Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi. i just started learning LISP and am trying to write an autoLISP application to select all polylines on a layer to create a feature line.
This is the code I have written. Unfortunately, when I use the command no polylines are found on the layer but I know that there are certainly polylines on the layer (Works fine with a basic QSelect command but the ssget doesn't seem to select anything). Any idea what is going wrong?
;;by Emma
(defun c:ConvertPolylinesToFeatureLines ( / layername ss c3d civdoc sites site flines fline entity )
;; Prompt user for layer name
(setq layername (getstring "\nEnter the layer name to select polylines: "))
;; Check if the layer exists in the drawing
(if (tblsearch "LAYER" layername)
(progn
;; Use ssget to select all polylines on the specified layer
(setq ss (ssget "X" (list (cons 8 layername) (cons 0 "LWPOLYLINE") (cons 0 "POLYLINE"))))
;; Check if the selection set is valid (not empty)
(if ss
(progn
;; Notify user of the number of polylines selected
(princ (strcat "\n" (itoa (sslength ss)) " polylines found on layer: " layername))
;; Load Civil 3D application COM interface
(vl-load-com)
(setq *acad* (vlax-get-acad-object))
(setq c3d (vla-getinterfaceobject *acad* "AeccXUiLand.AeccApplication.2025"))
;; Check if Civil 3D is loaded successfully
(if c3d
(progn
;; Get the active Civil 3D document
(setq civdoc (vlax-get c3d 'activedocument))
;; Get the Sites collection
(setq sites (vlax-get civdoc 'sites))
;; Add a "Site 1" site if it doesn't exist
(setq site (vlax-invoke sites 'add "Site 1"))
(setq flines (vlax-get site 'featurelines))
;; Loop through each selected polyline and convert to feature line
(vlax-for entity ss
(setq fline (vlax-invoke flines 'addfrompolylineex (vlax-ename->vla-object entity) "Standard"))
;; Optionally: Set the layer for the feature line to match the selected entity layer
(vla-put-layer fline (vla-get-layer (vlax-ename->vla-object entity)))
)
;; Optionally zoom to the extents of the selected feature lines
(command "_.zoom" "A")
(princ "\nPolylines have been converted to feature lines.")
)
(princ "\nError: Unable to load Civil 3D application interface.")
)
)
(princ "\nNo polylines found on the specified layer.")
)
)
(princ "\nInvalid layer name entered.")
)
(princ)
)
Solved! Go to Solution.