Command: SELECTCROSSINTGPOLYLINE
Selects objects inside or crossing polyline. Operates in Topview with LWpolyline.Code:
;;; ================================================
;;; SELECTCROSSINGPOLYLINE_v1_02.LSP
;;;
;;; Written by Andrzej Kalinowski, www.autolisps.blogspot.com
;;; v1.00 - 27.01.2019
;;; v1.01 - 08.07.2022 - fixed bug with highlightning objects on locked layers.
;;; v1.02 - 30.03.2025 - program adjusted to work with rotated UCS.
;;;
;;; Command: SELECTCROSSINGPOLYLINE -
;;; Selects objects inside or crossing polyline. Operates in Topview with LWpolyline.
;;; ================================================
(defun c:SELECTCROSSINGPOLYLINE ( / sset2 obj1 lst1 i1 coords1 i2 curobj1)
;-----------------------------------------
;object selection
;-----------------------------------------
(setq obj1 nil)
(prompt "\nSelect Polyline (LW): ")
(while (= obj1 nil)
(setq obj1 (ssget "_:S+."))
(if (= obj1 nil)
(princ "\nWrong object");then
(if (> (sslength obj1) 1);else
(progn
(princ "\nSelect only one object")(princ)
(setq obj1 nil)
);progn
(if (not (member (vlax-get (vlax-ename->vla-object (ssname obj1 0) ) 'ObjectName) (list "AcDbPolyline" ) ) );not
(progn
(princ "\nSelect only one object")(princ)
(setq obj1 nil)
);progn
);if
);if
);end if
);end while
(setq obj1 (ssname obj1 0))
;-----------------------------------------
(setq lst1 (list) )
(setq coords1 (vlax-get (vlax-ename->vla-object obj1 ) 'Coordinates) )
(setq i1 0 )
(repeat (/ (length coords1) 2)
(setq lst1 (cons (list (nth i1 coords1) ( nth (1+ i1) coords1) ) lst1 ) )
(setq i1 (+ 2 i1) )
)repeat
(vl-cmdf "_UCS" "_W")
(setq sset2 (ssget "_CP" lst1) )
(vl-cmdf "_UCS" "_P")
(ssdel obj1 sset2)
(vl-cmdf "_move" ) (command) ; regenerates highlited selection
(SCP_HIGHLIGHSEL sset2)
(princ (strcat "\nTotal selected objects: " (itoa (sslength sset2) ) ) )
(princ)
);defun
;;; ================================================
; SBT_HIGHLIGHSEL
;;; ================================================
;highlights selectionset
(defun SCP_HIGHLIGHSEL ( get_sset / i9 MyLayers2)
(setq i9 0)
(setq MyLayers1 (vla-get-layers (vla-get-activedocument (vlax-get-acad-object) ) ))
(repeat (sslength get_sset)
(if (=(vla-get-lock (vla-item MyLayers1(vla-get-layer (vlax-ename->vla-object (ssname get_sset i9))))):vlax-true )
(if (getcname "-DWGUNITS");checks if Autocad or Gstarcad. In Gstarcad dwgunits is unavailable. This condition prevents error in Gstarcad: ActiveX server returned an error: Exception occurred. We have to redraw the selection instead of invoking highlight methode.
(vlax-invoke-method (vlax-ename->vla-object (ssname get_sset i9)) 'Highlight :vlax-true);autocad
(redraw (ssname get_sset i9) 3);gstarcad
);if
(vlax-invoke-method (vlax-ename->vla-object (ssname get_sset i9)) 'Highlight :vlax-true)
);if
(setq i9 (1+ i9))
)
(sssetfirst nil)
(sssetfirst nil get_sset)
);defun
Example:
1.00 - 27.01.2019 - first release
1.01 - 08.07.2022 - fixed bug with highlightning objects on locked layers.
1.02 - 30.03.2025 - program adjusted to work with rotated UCS.
File format:
.FAS
Compatibility:
-All Autocad versions
Remarks:
-The application comes with the long command names listed above. To create your own short aliases for these commands, go to ACAD.PGP file or Menu Manage->Customization->Edit aliases->Edit Aliases
Download file:
SELECTCROSSINGPOLYLINE_v1_02.FAS

No comments:
Post a Comment