Lisp - Offsetting and changing Linetype

Lisp - Offsetting and changing Linetype

Anonymous
Not applicable
2,107 Views
9 Replies
Message 1 of 10

Lisp - Offsetting and changing Linetype

Anonymous
Not applicable

Hello,

 

I've been tasked with creating a lisp that can offset a polyline 0.1075, twice, and editing the the central polyline to expand to the thickness of 0.215 and change it to the linetype ACAD_ISO03W100.

 

This is my first foray into writing lisp functions rather than just downloading them off the internet and have become a bit stuck.

 

I get as far as offsetting and thickening the central polyline however changing the linetype is to ACAD_ISO03W100 is still proving difficult.

 

It allows me to click on the central line and select LT and so on manually, though I do not know how to get the lisp to do this automatically.

 

Any Help or information would be greatly appreciated.

 

Kind Regards

 

Andrew

 

 

 

_$ 
_$ (defun C:WALLBUILDER()
        (setq cmde (getvar "cmdecho"))
        (setvar "cmdecho" 0)      
        (while (setq e (entsel "\nSelect polyline to convert to fence: "))
                (progn  (command "offset" "0.2150" e "-1,-1" "")
                        (command "offset" "0.1075" e "-1,-1" "")
                        (setq e (entlast))
                        (command "pedit" e "w" "0.2150" "")
			(command "chprop" "LT" "" "ACAD_ISO03W100" "")
		  )
	  )
     (setvar "cmdecho" cmde)
     (princ)
     )

 

0 Likes
Accepted solutions (2)
2,108 Views
9 Replies
Replies (9)
Message 2 of 10

DannyNL
Advisor
Advisor

You forgot to provide CHPROP with your entity parameter.

 

(defun C:WALLBUILDER()
        (setq cmde (getvar "cmdecho"))
        (setvar "cmdecho" 0)      
        (while (setq e (entsel "\nSelect polyline to convert to fence: "))
                (progn  (command "offset" "0.2150" e "-1,-1" "")
                        (command "offset" "0.1075" e "-1,-1" "")
                        (setq e (entlast))
                        (command "pedit" e "w" "0.2150" "")
			(command "chprop" e "" "LT" "ACAD_ISO03W100" "")
		  )
	  )
     (setvar "cmdecho" cmde)
     (princ)
     )

Your routine does need the linetype ACAD_ISO03W100 to be loaded in the drawing. If it is not present it will return an error.
My day at the office is over for now but if someone else didn't come up with a more clean code, I will look again tomorrow and give you another one with more error handling.

0 Likes
Message 3 of 10

DannyNL
Advisor
Advisor
Accepted solution

Updated version with some added checks and options.

 

Also linetype generation is turned on for the polyline that will get the new linetype, so the linetype will run smoothly along the polyline as a whole instead of segmented.

 

(defun C:WALLBUILDER (/ W_ActiveDoc W_OldVars W_Entity)
   (vla-StartUndoMark (setq W_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq W_OldVars (mapcar 'getvar '("cmdecho" "osmode")))              
   (setvar "cmdecho" 0)
   (setvar "osmode"  0)
   (while
      (setq W_Entity (entsel "\nSelect polyline to convert to fence: "))
      (progn         
         (command "offset" "0.2150" W_Entity "-1,-1" "")
         (command "offset" "0.1075" W_Entity "-1,-1" "")
         (setq W_Entity (entlast))
         (vla-put-LinetypeGeneration (vlax-ename->vla-object W_Entity) :vlax-true)
         (command "pedit" W_Entity "w" "0.2150" "")
         (if
            (not (tblsearch "LTYPE" "ACAD_ISO03W100"))
            (command "-LINETYPE" "L" "ACAD_ISO03W100" "" "")
         )
         (command "chprop" W_Entity "" "LT" "ACAD_ISO03W100" "")
      )
   )
   (mapcar 'setvar '("cmdecho" "osmode") W_OldVars)
   (vla-EndUndoMark     W_ActiveDoc)
   (vlax-release-object W_ActiveDoc)
   (princ)
)
Message 4 of 10

Anonymous
Not applicable

Thanks you so much!

0 Likes
Message 5 of 10

DannyNL
Advisor
Advisor
Accepted solution

You're welcome, glad I could help.

 

Made one more small modification to the code. Checking for the linetype should only be done once and not every time a new polyline is selected. So I've moved this check to the beginning before the WHILE loop.

 

(defun C:WALLBUILDER (/ W_ActiveDoc W_OldVars W_Entity)
   (vla-StartUndoMark (setq W_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq W_OldVars (mapcar 'getvar '("cmdecho" "osmode")))              
   (setvar "cmdecho" 0)
   (setvar "osmode"  0)
   (if
      (not (tblsearch "LTYPE" "ACAD_ISO03W100"))
      (command "-LINETYPE" "L" "ACAD_ISO03W100" "" "")
   )
   (while
      (setq W_Entity (entsel "\nSelect polyline to convert to fence: "))
      (progn         
         (command "offset" "0.2150" W_Entity "-1,-1" "")
         (command "offset" "0.1075" W_Entity "-1,-1" "")
         (setq W_Entity (entlast))
         (vla-put-LinetypeGeneration (vlax-ename->vla-object W_Entity) :vlax-true)
         (command "pedit" W_Entity "w" "0.2150" "")
         (command "chprop" W_Entity "" "LT" "ACAD_ISO03W100" "")
      )
   )
   (mapcar 'setvar '("cmdecho" "osmode") W_OldVars)
   (vla-EndUndoMark     W_ActiveDoc)
   (vlax-release-object W_ActiveDoc)
   (princ)
)
Message 6 of 10

Anonymous
Not applicable

Using your latest Lisp function I have adapted the offset to pause for user input. I am trying to make a new version of the original but to allow the user to determine which way it offsets. The lisp below does it with two clicks. Is there a way to tell the pause for user input to be the same as the first pause for input?

 

Thanks for all your help by the way!

 

(defun C:WB2 (/ W_ActiveDoc W_OldVars W_Entity)
   (vla-StartUndoMark (setq W_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq W_OldVars (mapcar 'getvar '("cmdecho" "osmode")))              
   (setvar "cmdecho" 0)
   (setvar "osmode"  0)
   (if
      (not (tblsearch "LTYPE" "Dashed"))
      (command "-LINETYPE" "L" "Dashed" "" "")
   )
   (while
      (setq W_Entity (entsel "\nSelect polyline to convert to fence: "))
      (progn         
         (command "offset" "0.2150" W_Entity pause "")
         (command "offset" "0.1075" W_Entity pause "")
         (setq W_Entity (entlast))
         (vla-put-LinetypeGeneration (vlax-ename->vla-object W_Entity) :vlax-true)
         (command "pedit" W_Entity "w" "0.2150" "")
         (command "chprop" W_Entity "" "LT" "Dashed" "")
      )
   )
   (mapcar 'setvar '("cmdecho" "osmode") W_OldVars)
   (vla-EndUndoMark     W_ActiveDoc)
   (vlax-release-object W_ActiveDoc)
   (princ)
)
0 Likes
Message 7 of 10

Anonymous
Not applicable

Using your latest Lisp function I have adapted the offset to pause for user input. I am trying to make a new version of the original but to allow the user to determine which way it offsets. The lisp below does it with two clicks. Is there a way to tell the pause for user input to be the same as the first pause for input?

 

Thanks for all your help by the way!

 

(defun C:WB2 (/ W_ActiveDoc W_OldVars W_Entity)
   (vla-StartUndoMark (setq W_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq W_OldVars (mapcar 'getvar '("cmdecho" "osmode")))              
   (setvar "cmdecho" 0)
   (setvar "osmode"  0)
   (if
      (not (tblsearch "LTYPE" "Dashed"))
      (command "-LINETYPE" "L" "Dashed" "" "")
   )
   (while
      (setq W_Entity (entsel "\nSelect polyline to convert to fence: "))
      (progn         
         (command "offset" "0.2150" W_Entity pause "")
         (command "offset" "0.1075" W_Entity pause "")
         (setq W_Entity (entlast))
         (vla-put-LinetypeGeneration (vlax-ename->vla-object W_Entity) :vlax-true)
         (command "pedit" W_Entity "w" "0.2150" "")
         (command "chprop" W_Entity "" "LT" "Dashed" "")
      )
   )
   (mapcar 'setvar '("cmdecho" "osmode") W_OldVars)
   (vla-EndUndoMark     W_ActiveDoc)
   (vlax-release-object W_ActiveDoc)
   (princ)
)

 

0 Likes
Message 8 of 10

DannyNL
Advisor
Advisor

In that case a variable needs to be set that stores the point you select with the first offset. This variable can then be passed as an argument to the second offset on the position of the PAUSE, so you use the same value as with the first offset.

 

The initget line in the code prevents the user from simply pressing enter on the getpoint command and causing an error.

 

(defun C:WB2 (/ W_ActiveDoc W_OldVars W_Entity W_OffsetPoint)
   (vla-StartUndoMark (setq W_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
   (setq W_OldVars (mapcar 'getvar '("cmdecho" "osmode")))              
   (setvar "cmdecho" 0)
   (setvar "osmode"  0)
   (if
      (not (tblsearch "LTYPE" "Dashed"))
      (command "-LINETYPE" "L" "Dashed" "" "")
   )
   (while
      (setq W_Entity (entsel "\nSelect polyline to convert to fence: "))
      (progn
         (initget 1)
         (command "offset" "0.2150" W_Entity (setq W_OffsetPoint (getpoint "\nSpecify point on side to offset: ")) "")
         (command "offset" "0.1075" W_Entity W_OffsetPoint "")
         (setq W_Entity (entlast))
         (vla-put-LinetypeGeneration (vlax-ename->vla-object W_Entity) :vlax-true)
         (command "pedit" W_Entity "w" "0.2150" "")
         (command "chprop" W_Entity "" "LT" "Dashed" "")
      )
   )
   (mapcar 'setvar '("cmdecho" "osmode") W_OldVars)
   (vla-EndUndoMark     W_ActiveDoc)
   (vlax-release-object W_ActiveDoc)
   (princ)
)

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

Oh Thanks This is great. I think I really need to develop my Lisp writing skills.

0 Likes
Message 10 of 10

DannyNL
Advisor
Advisor

Once you go LISP..... Smiley Wink