Jump to content

Recommended Posts

Posted (edited)

Hello, I need help. I use the lisp Batter to draw slope tick lines and the lisp works great if my drawings are in coordinates that have 3 or 4 digits. Example (100.00,200.00) or (5100.00, 5100.00) but the coordinate system that uses UTM zone 34 has 9 and 7 digits (34455000.00, 4951000.00) simply the lisp does all the operations but does not draw the slope lines. If I move the entire drawing to coordinates with 3 or 4 digits the lisp works great, I noticed that if the drawing is in coordinates with 5 or more digits the lisp does not draw tick line. My knowledge of auto lisp is very little so if someone can help me and correct the codes in lisp I would be very grateful. sorry for my bad English 🙂

Capture1.JPG.877f36a980c286489bce85510e68f1b1.JPG

 

 

Capture3.thumb.JPG.1605cce763aa7930bee3321806874924.JPGCapture4.JPG.794659571cd286d2f646a7f2e4f739b4.JPG

 

 

Capture 2.JPG

 

 

(defun c:batter ()
(setq oldlay (getvar "clayer"))
(setvar "osmode" 0)
(command "-view" "s" "cur")
(command "ucs" "w")
(if
 (not (tblsearch "layer" "BATTER"))
   (command "_.layer" "_make" "BATTER" "_color" "8" "" "")
  ) 
 (setvar "clayer" "BATTER")
 (setvar "cmdecho" 0)
   
   (setvar "aunits" 0)
   (setvar "angbase" (/ pi 2))
   (setvar "angdir" 1)
   (if (not lint) (setq lint 10.0))
   (setq int (getdist (strcat "\nInterval <" (rtos lint 2 3) ">: ")))
   (if int (setq lint int) (setq int lint))
   (command "line" (list 0.0 0.0) (list 0.0 0.0001) "")
   (if (tblsearch "block" "tadtick")
         (command "block" "tadtick" "y" (list 0.0 0.0) (entlast) "")
         (command "block" "tadtick" (list 0.0 0.0) (entlast) "")
   )
   (while (setq refent (entsel "\nSelect reference line: "))
      (command "undo" "group")
      (redraw (car refent) 3)
      (initget 1 "Cut Fill")
      (setq reply (getkword "\n[C]ut or [F]ill batter: "))
      (setq s (ssget))
      (command "measure" refent "b" "tadtick" "y" int)
      (setq p (ssget "p") cn 0)
      (if s
         (progn
            (while (< cn (sslength p))
               (setq en (entget (ssname p cn)) p0 (cdr (assoc 10 en)) pt1 p0 pt2 nil b (cdr (assoc 50 en)))
               (entdel (ssname p cn))
               (setq p1 (polar p0 (+ (/ pi 2) b) 0.0001))
               (command "line" p0 p1 "")
               (command "extend" s "" (list (entlast) p1) "")
               (setq xent (entget (entlast)))
               (setq xdist (distance (cdr (assoc 10 xent)) (cdr (assoc 11 xent))))
               (if (not (equal xdist 0.0001 0.0001))
                  (setq pt2 (cdr (assoc 11 xent)))
                  (progn
                     (command "extend" s "" (list (entlast) p0) "")
                     (setq xent (entget (entlast)))
                     (setq xdist (distance (cdr (assoc 10 xent)) (cdr (assoc 11 xent))))
                     (if (not (equal xdist 0.0001 0.0001))
                        (setq pt2 (cdr (assoc 10 xent)))
                     )
                  )
               )
               (entdel (entlast))
               (if pt2
                  (if (= reply "Fill")
                     (if (= (rem cn 2) 0) (command "line" pt1 pt2 "")
                        (command "line" pt1 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)) "")
                     )
                     (if (= (rem cn 2) 0) (command "line" pt2 pt1 "")
                        (command "line" pt2 (polar pt2 (angle pt2 pt1) (/ (distance pt2 pt1) 2)) "")
                     )
                  )
               )
               (setq cn (1+ cn))
            )
         )
      )
      (command "undo" "en")
   )
(setvar "clayer" oldlay)
(command "-view" "r" "cur")
(command "-view" "d" "cur")
   (princ)
)
(prompt "\nDraw cut/fill batter slope lines.")

 

batter.lsp

Edited by SLW210
Added Code Tags!
  • DraganK changed the title to Batter lisp problem
Posted

Hi,

 

My suggestion as an alternative.
Entities selections can be polylines lines arcs circles ellipses and splines in 2D or 3D.
The wrapping lines will be in 2D or 3D depending on the source.
Try it if it suits you!...

slope3D.lsp

Posted

Tsuky - Thanks for the alternative  , but it's not what I need for the job, I hope someone else will join in and try to fix the error in the code.

Posted

In the future please use code tags for your code. (<> in the editor toolbar)

Posted

BIGAL thanks for the lisp, but it doesn't draw what I need, I have to shorten every other line, it's easier to move my drawing and draw the slopes line and then return to the old coordinate system.

  • 2 months later...
Posted (edited)

Heelp 🤐

 
Edited by DraganK
Posted

Hi
Attach a drawing with which your code works

  • Thanks 1
Posted

Does your drawing contain blocks?

Posted
6 minutes ago, GLAVCVS said:

Does your drawing contain blocks?

The drawing has no blocks, the drawings I posted only have 4 lines between which I draw slopes. In the drawing where the coordinates have 4 digits the lisp works but in the other drawing with 9 and 7 digits it does not work.
Sorry for my bad English

Posted

I have made the necessary modifications to make the command calls compatible with other languages and the code works fine for me in your 2 drawings.
Are you using an English version of AutoCAD or another language?

Posted
1 minute ago, GLAVCVS said:

I have made the necessary modifications to make the command calls compatible with other languages and the code works fine for me in your 2 drawings.
Are you using an English version of AutoCAD or another language?

Using English version Civil 3d 2023. 

Posted

This is the code I tried
And it works

 

(defun c:batter	(/ oldlay int refent reply s p cn en p0 pt1 pt2 b p1 xdist xent)
  (setq oldlay (getvar "clayer"))
  (setvar "osmode" 0)
  (command "_.view" "_s" "_.cur")
  (command "_.ucs" "_w")
  (if (not (tblsearch "layer" "BATTER"))
     (command "_.layer" "_make" "BATTER" "_color" "8" "" "")
  )
  (setvar "clayer" "BATTER")
  (setvar "cmdecho" 0)

  (setvar "aunits" 0)
  (setvar "angbase" (/ pi 2))
  (setvar "angdir" 1)
  (if (not lint)
    (setq lint 10.0)
  )
  (setq int (getdist (strcat "\nInterval <" (rtos lint 2 3) ">: ")))
  (if int
    (setq lint int)
    (setq int lint)
  )
  (command "_.line" (list 0.0 0.0) (list 0.0 0.0001) "")
  (if (tblsearch "block" "tadtick")
    (command "_.block" "tadtick" "_y" (list 0.0 0.0) (entlast) "")
    (command "_.block" "tadtick" (list 0.0 0.0) (entlast) "")
  )
  (while (setq refent (entsel "\nSelect reference line: "))
    (command "_.undo" "_group")
    (redraw (car refent) 3)
    (initget 1 "Cut Fill")
    (setq reply (getkword "\n[C]ut or [F]ill batter: "))
    (setq s (ssget))
    (command "_.measure" refent "_b" "tadtick" "_y" int)
    (setq p  (ssget "p")
	  cn 0
    )
    (if	s
      (progn
	(while (< cn (sslength p))
	  (setq	en  (entget (ssname p cn))
		p0  (cdr (assoc 10 en))
		pt1 p0
		pt2 nil
		b   (cdr (assoc 50 en))
	  )
	  (entdel (ssname p cn))
	  (setq p1 (polar p0 (+ (/ pi 2) b) 0.0001))
	  (command "_.line" p0 p1 "")
	  (command "_.extend" s "" (list (entlast) p1) "")
	  (setq xent (entget (entlast)))
	  (setq	xdist
		 (distance (cdr (assoc 10 xent)) (cdr (assoc 11 xent)))
	  )
	  (if (not (equal xdist 0.0001 0.0001))
	    (setq pt2 (cdr (assoc 11 xent)))
	    (progn
	      (command "_.extend" s "" (list (entlast) p0) "")
	      (setq xent (entget (entlast)))
	      (setq xdist (distance (cdr (assoc 10 xent))
				    (cdr (assoc 11 xent))
			  )
	      )
	      (if (not (equal xdist 0.0001 0.0001))
		(setq pt2 (cdr (assoc 10 xent)))
	      )
	    )
	  )
	  (entdel (entlast))
	  (if pt2
	    (if	(= reply "Fill")
	      (if (= (rem cn 2) 0)
		(command "_.line" pt1 pt2 "")
		(command
		  "_.line"
		  pt1
		  (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2))
		  ""
		)
	      )
	      (if (= (rem cn 2) 0)
		(command "_.line" pt2 pt1 "")
		(command
		  "_.line"
		  pt2
		  (polar pt2 (angle pt2 pt1) (/ (distance pt2 pt1) 2))
		  ""
		)
	      )
	    )
	  )
	  (setq cn (1+ cn))
	)
      )
    )
    (command "_.undo" "_en")
  )
  (setvar "clayer" oldlay)
  (command "_.view" "_r" "_cur")
  (command "_.view" "_d" "_cur")
  (princ)
)

 

Posted

Lisp worked in Autocad 2013 and now in Civil 2023 it doesn't work, probably it's a problem with the plugins I have. Thank you very much for your help.

Posted

My test was on Civil 3D 2021, in case it helps you to know.

Posted

Worked for me Bricscad V25.

 

Just a comment got an error message about view may be my Bricscad. But batter worked

 

Cannot find view: _CUR
Cannot find view: _.VIEW
Cannot find view: _D
Cannot find view: _CUR
View to restore: 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...