Jump to content

LISP Request Offset&Extrude&Substract


zwonko

Recommended Posts

Hello,

could You help me with LISP that will do stuff like this:

1) I have a some polylines on drawing. All are closed. I start the lisp and could select one.

2) Selected (1st) polyline should be _extrude 12 units to create 1st 3DSolid

3) then this selected 1st polyline should be _offset 0.8 units to create 2nd poly

4) 2nd poly should be extruded 12 units to create 2nd 3DSolid

5) 2nd poly should be offset 0.4 units to create 3rd poly. (or alternatively it could be that 1st should be offset 1.2 units)

6) 3rd poly should be extrude 5 units to create 3rd 3DSolid

7) 3rd poly should be offset 4.8 units (or arternatively 1st should be offset 6 units) to create 4th poly

8 ) 4th poly should be extrude 2 units.

9) last thing substract selects 2nd 3rd and 4rd 3Dsolids, and cut off 1st 3DSolid

 

All offset must be outside. All extrude should be up (Z axis possitive)

 

I will be gratefull if the lisp run command with "_" (_extrude, _offset, _substract) becouse I use not english version of autocad. But i could change it myself.

 

Cool thing will be if I can select not only one poly but few polylines and they all do as i written above. But it could be hard.

 

I think that the worst thing in this is to automaticaly select created 3DSolids so I think that LISP may only start substract command and I will select 3Dsolids manually.

 

If it is possible to select few polylines and do Offset&Extrude, and after that substract must be done manually it will be awesome if substract command is started few times (for example 3 polylines select and the lisp starts substract three times)

 

I've attached the file that shows the start&result of my work. I have to do all alphabet letters like this "&"

 

Now I' doing it with two lisp (which I moddified from lisps founded in the internet)

 

(defun c:pof1 (/ plines ; selection set of polylines
      ext ; extrnal point
      poly ; a polyline from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly (ssname plines i))
   (setq plist (entget poly))
   (command "_offset" 0.8 poly ext "")
   (command "_offset" 1.2 poly ext "")
   (command "_offset" 6 poly ext "")
 )
)

(defun c:pof2 (/ plines ; selection set of polylines
      ext ; extrnal point
      poly ; a polyline from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly (ssname plines i))
   (setq plist (entget poly))
   (command "_extrude" poly "" 12 "")



/ plines ; selection set of polylines
      ext ; extrnal point
      poly ; a polyline from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly (ssname plines i))
   (setq plist (entget poly))
   (command "_extrude" poly "" 12 "")


/ plines ; selection set of polylines
      ext ; extrnal point
      poly ; a polyline from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly (ssname plines i))
   (setq plist (entget poly))
   (command "_extrude" poly "" 5 "")

/ plines ; selection set of polylines
      ext ; extrnal point
      poly ; a polyline from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly (ssname plines i))
   (setq plist (entget poly))
   (command "_extrude" poly "" 2 "")


   (command "_subtract" )



 )
)

lisp.dwg

Link to comment
Share on other sites

Without looking too deeply into the code you already have, I would recommend you explore SSGET "L" (last) to store each element (polyline & 3D solid) in a selection set, so you can recall them when coming to subtract from each other.

 

I'd be happy to take another look when I get to a computer, but chances are you'll be able to get some even better help from someone else on the forum before I can get back to it.

Link to comment
Share on other sites

@lamensterms that was everything that I need :)

I've modyfied code form lisp1 (pof1) to:

(defun c:pof3 (/ plines ; selection set of polylines
      ext ; extrnal point
      poly1 ; a polyline from plines
      poly2 ; a polyline from plines
      poly3 ; a polyline from plines
      poly4 ; a polyline from plines
      extr1 ; a extrude from plines
      extr2 ; a extrude from plines
      extr3 ; a extrude from plines
      extr4 ; a extrude from plines
      plist ; the list of poly
      del ; polyline to delete
      int ; internal point
      i)
 (command "undo" "begin")
 (princ "select polylines")
 (setq plines (ssget)
i      0
ext    (getvar "limmax")
 )
 (repeat (sslength plines)
   (setq poly1 (ssname plines i))
   (setq plist (entget poly1))
   (command "_offset" 0.8 poly1 ext "")
 (setq poly2 (ssget "_L"))
   (command "_extrude" poly1 "" 12 "")
 (setq extr1 (ssget "_L"))
   (command "_offset" 0.4 poly2 ext "")
 (setq poly3 (ssget "_L"))
   (command "_extrude" poly2 "" 12 "")
 (setq extr2 (ssget "_L"))
   (command "_offset" 4.8 poly3 ext "")
 (setq poly4 (ssget "_L"))
   (command "_extrude" poly3 "" 5 "")
 (setq extr3 (ssget "_L"))
   (command "_extrude" poly4 "" 2 "")
 (setq extr4 (ssget "_L"))
   (command "_subtract" extr2 extr3 extr4 "" extr1 "")
 )
)

everything works great :) Maybe code is not the simplest but its works :)

Link to comment
Share on other sites

Just a suggestion (Setq ent1 (entlast)) no need for ssget

 

You are setting a variable to a entity so no need to use a selection set

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