All Polylines on layer to featureline

All Polylines on layer to featureline

emma_duymelinck3LZQW
Explorer Explorer
1,444 Views
9 Replies
Message 1 of 10

All Polylines on layer to featureline

emma_duymelinck3LZQW
Explorer
Explorer

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


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

pendean
Community Legend
Community Legend
Can you share your DWG here (and identify the layer with the Plines or share a DWG with only that layer with them)?
0 Likes
Message 3 of 10

Kent1Cooper
Consultant
Consultant

Feature lines are not a part of "vanilla" AutoCAD.  Might you do better in the Civil 3D Forum?  That one even has its own dedicated Civil 3D Customization Forum.

Kent Cooper, AIA
0 Likes
Message 4 of 10

komondormrex
Mentor
Mentor

try to change

 (setq ss (ssget "X" (list (cons 8 layername) (cons 0 "LWPOLYLINE") (cons 0 "POLYLINE"))))

to

 (setq ss (ssget "X" (list (cons 8 layername) (cons 0 "LWPOLYLINE, POLYLINE"))))

Message 5 of 10

Kent1Cooper
Consultant
Consultant

@komondormrex wrote:

....

 (setq ss (ssget "X" (list (cons 8 layername) (cons 0 "LWPOLYLINE, POLYLINE"))))


... but without the space after the comma:

(setq ss (ssget "X" (list (cons 8 layername) (cons 0 "LWPOLYLINE,POLYLINE"))))

Or, simply:

(setq ss (ssget "X" (list (cons 8 layername) (cons 0 "*POLYLINE"))))

Kent Cooper, AIA
Message 6 of 10

CodeDing
Mentor
Mentor
Accepted solution

@emma_duymelinck3LZQW ,

 

The problem with creating Feature Lines from scratch is that there are so many options that the user usually has to be involved with, that it's not worth the hassle to cover all of the necessary items involved with the setup of feature lines (such as site, naming, layering, delete entities, etc...)

 

So, if your primary concern is making it easier to select all of the entites on a certain layer, then I propose this code:

 

(defun c:P2F ( / errMsg e isEnt lyr ss)
  (initget "Name")
  (setq errMsg
    (cond
      ((not (setq e (entsel "\nSelect Polyline on Layer to convert Feature Lines or [Name]: ")))
        "\nNo entity was selected. Try again."
      )
      ((and (setq isEnt (not (eq 'STR (type e)))) (not (wcmatch (cdr (assoc 0 (entget (setq e (car e))))) "*POLYLINE")))
        "\nMust select a Polyline entity. Try again"
      )
      ((and (not isEnt) (eq "" (setq lyr (getstring "\nLayer Name: " t))))
        "\nNo layer name was entered."
      )
      ((and (not isEnt) (not (tblsearch "LAYER" lyr)))
        (strcat "\nThe layer, " lyr ", does not exist.")
      )
      ((and isEnt (not (setq lyr (cdr (assoc 8 (entget e)))))) nil) ;; ignore
      ((not (setq ss (ssget "_X" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 8 lyr) (cons 410 "Model")))))
        (strcat "\nNo Polyline entities found on layer, " lyr)
      )
    );cond
  );setq
  (if errMsg (progn (alert (princ errMsg)) (exit)))
  (command-s "_AeccCreateFeatureLines" ss "")
  (prompt "\nP2F Complete.")
  (princ)
);defun

 

... This will still give the user the most control of what should happen to the entities during conversion:

 

image.png

 

Best,

~DD

Message 7 of 10

hosneyalaa
Advisor
Advisor

@emma_duymelinck3LZQW 

Make sure you have  style  “Standard” , so that it works

 

hosneyalaa_0-1731325742453.png

 

 

7.gif

 

 

 

0 Likes
Message 8 of 10

emma_duymelinck3LZQW
Explorer
Explorer

Yes, I do have this style. Doesn't seem to be the problem but thank you 🙂

0 Likes
Message 9 of 10

emma_duymelinck3LZQW
Explorer
Explorer

This solution worked to get the routine to find the polyline on the layer,  but the application still failed to load unfortunately, will continue to look!

0 Likes
Message 10 of 10

emma_duymelinck3LZQW
Explorer
Explorer
Hi DD,
This is exactly what I was looking for, thank you for your help!!

All the best,
Emma
0 Likes