TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Daniel J. Ellis on November 03, 2008, 08:53:30 AM
-
Hi,
-
(OK, that was weird)
I'm trying to select an object and turn it into polyline, and then select that object (now a polyline) automatically for use in a JOIN command.
I'v tried using (command "PEDIT" ent "YES" "" ""))
along with a suitable test for being a polyline, but this causes trouble with selecting the object to move on.
using a variable only works if it's already a polyline, "LAST" only works if it was the last object created, and JOIN doesn't support PREVIOUS.
Any ideas?
DJE
-
Use Region and Subtract
(defun C:OTK ( / blk pt Lpt pline otv L H *error* nab)
(defun *error* (msg)(princ msg)
(if (and blk (entget blk)) (entdel blk))(princ))
(vl-load-com)
(setvar "cmdecho" 0)(setvar "expert" 5)
(setq pline (car (entsel "\nSelect polyline: ")))
(setq Lpt t pt (getvar "LASTPOINT"))
(while (and pline Lpt)
(initget 7 )(setq L (getdist "\nLength of an aperture: "))
(initget 7 )(setq H (getdist "\nHeight of an aperture: "))
(VL-CMDF "_.Rectang" "0,0" (list L H))
(VL-CMDF "_.-block" "TMPBLK" "0,0" "_L" "")
(VL-CMDF "_-INSERT" "TMPBLK" "0,0" "" "" "")
(setq blk (entlast))
(princ "\n Insert an aperture (ENTER-exit): ")
(setq pt (getvar "LASTPOINT"))
(vl-cmdf "_.CHANGE" blk "" "" pause "")
(setq Lpt (getvar "LASTPOINT"))
(if (equal Lpt pt 0.000001)
(progn (entdel blk)(setq Lpt nil))
(progn
(vl-cmdf "_.Explode" blk)
(setq otv (entlast))
(if (not(vl-catch-all-error-p
(vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value
(vla-intersectwith (vlax-ename->vla-object otv) (vlax-ename->vla-object pline) acextendnone))))))
(progn ;_ пересекаются
(vl-cmdf "_.Region" pline "")(setq pline (entlast))
(vl-cmdf "_.Region" otv "")(setq otv (entlast))
(vl-cmdf "_subtract" pline "" otv "")
(setq otv (entlast) nab (ssadd))
(foreach item (vlax-invoke (vlax-ename->vla-object otv) 'Explode)
(ssadd (vlax-vla-object->ename item) nab))
(if (and (getvar "PEDITACCEPT") (= (getvar "PEDITACCEPT") 1))
(vl-cmdf "_pedit" "_Multiple" nab "" "_Join" 0 "")
(vl-cmdf "_pedit" "_Multiple" nab "" "_Y" "_Join" 0 ""))
(setq pline (entlast) nab nil)
(entdel otv)
)
) ;_ if
(setq pt (getvar "LASTPOINT"))
)
)
)
(princ)
)
-
Cool, but how did you do that gif?
-
"PEDIT" "Multiple" does support "Previous".
-
Set this as a button.
^C^C_peditaccept;1;_select;p;;_Pedit;m;p;;_j;0;;
1. Select objects
2. Click button that contains this macro
3. You get joined polylines
I select the lines I wish to convert and this will then join all the ones I have had selected.
This was one of my first button macros :)
I hope it helps.
Daniel
**Edit below**
If you wish to join a complete layer use this code.
;;Join polyline by layer
;;by cadmoogle - 2008
(Defun C:LJ (/ ss) ;Select layer, join all objects as a polyline.
(defun *error* (msg)
(setvar "QAFLAGS" 0)
(princ)
)
(command "undo" "begin")
(command "QAFLAGS" "1")
(setq a (entget (car (entsel "Select object: "))))
(setq ss (ssget "x" (list (cons 8 (cdr (assoc 8 a))))))
(command "peditaccept" "1")
(command "_select" "p" "")
(command "_pedit" "m" "p" "" "_j" "0" "")
(command "QAFLAGS" "0")
(command "undo" "end")
(princ "\nThe layer has been joined as a polyline.")
(princ))
(OK, that was weird)
I'm trying to select an object and turn it into polyline, and then select that object (now a polyline) automatically for use in a JOIN command.
I'v tried using (command "PEDIT" ent "YES" "" ""))
along with a suitable test for being a polyline, but this causes trouble with selecting the object to move on.
using a variable only works if it's already a polyline, "LAST" only works if it was the last object created, and JOIN doesn't support PREVIOUS.
Any ideas?
DJE
-
Cool, but how did you do that gif?
Camtasia Studio 4.
For a free program like camtasia, look for camstudio in sourceforge.
-
Cool thanks for the information. I love SF!