Jump to content

Help with insert block LISP


Demesne

Recommended Posts

Hi

 

I have an old lisp that inserts a 'tadpole' block between two picked points (top of slope and bottom of slope). I have edited the code to work only with horizontal distances and not slope distances to ensure that the scale factor is calculated correctly when working in 3D. My question is how do I have the block automatically inserted at a height of zero?

 

My knowledge of LISP is not great - I can sometimes see what it's doing and might me able to cut and paste code from one file to another, but as of yet, can't write the code myself.

 

(defun c:tadpole ()
;(while (= 1 1)
  (setq oldsnap (getvar "osmode"))
  (setvar "osmode" 512)
  (setvar "cmdecho" 0)
           (setq pt1 (getpoint "\nIndicate top of slope: ")
                 pt2 (getpoint "\nIndicate bottom of slope: " pt1)
     x1 (car pt1)   ;x-coord of point one
        x2 (car pt2)   ;x-coord of point two
        y1 (cadr pt1)  ;y-coord of point one
        y2 (cadr pt2)  ;y-coord of point two
        xdis (- x2 x1) ;distance in x direction between points
        ydis (- y2 y1) ;distance in y direction between points
        hzdis (sqrt(+ (expt xdis 2.0)(expt ydis 2.0))) ;A sq + B sq = C sq   
     sf (* hzdis 0.9)
  )
   (tadpole pt1 pt2)
(setvar "osmode" oldsnap)
(setvar "cmdecho" 1)
(princ)

)
(defun tadpole (pt1 pt2)
 (setq la (getvar "CLAYER"))
 (command "LAYER" "M" "ES_Tadpoles" ""
          "INSERT" "TADPOLE" pt1 sf sf pt2
          "LAYER" "S" la ""
 )
)

TADPOLE.DWG

Link to comment
Share on other sites

From a first glance (too early):

 

For this portion of the code...

"INSERT" "TADPOLE" pt1 sf sf pt2

 

 

replace pt1 with

(list (car pt1) (cadr pt1) 0.)

Link to comment
Share on other sites

alanjt - Thanks for the quiqk reply but I couldn't seem to get that to work. Block still comes in at pt1 z value.

Link to comment
Share on other sites

(defun c:tadpole ()
;(while (= 1 1)
  (setq oldsnap (getvar "osmode"))
  (setvar "osmode" 512)
  (setvar "cmdecho" 0)
           (setq pt1 (getpoint "\nIndicate top of slope: ")
                 pt2 (getpoint "\nIndicate bottom of slope: " pt1)
     x1 (car pt1)   ;x-coord of point one
        x2 (car pt2)   ;x-coord of point two
        y1 (cadr pt1)  ;y-coord of point one
        y2 (cadr pt2)  ;y-coord of point two
        xdis (- x2 x1) ;distance in x direction between points
        ydis (- y2 y1) ;distance in y direction between points
        hzdis (sqrt(+ (expt xdis 2.0)(expt ydis 2.0))) ;A sq + B sq = C sq   
     sf (* hzdis 0.9)
  )
   (tadpole pt1 pt2)
(setvar "osmode" oldsnap)
(setvar "cmdecho" 1)
(princ)

)
(defun tadpole (pt1 pt2)
 (setq la (getvar "CLAYER"))
 (command "LAYER" "M" "ES_Tadpoles" ""
          [color=Red]"INSERT" "TADPOLE" "_non" (list (car pt1) (cadr pt1) 0.) sf sf pt2[/color]
          "LAYER" "S" la ""
 )
)

Link to comment
Share on other sites

Thanks. That works great.

 

I understand that that (car pt1) is the easting and (cadr pt1) is the northing - the first and second list items, but what relevance has "_non"?

Link to comment
Share on other sites

Thanks. That works great.

 

I understand that that (car pt1) is the easting and (cadr pt1) is the northing - the first and second list items, but what relevance has "_non"?

It ignores any running OSnaps.

Link to comment
Share on other sites

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...