Lisp - Polyline Start, End & Lenght

Lisp - Polyline Start, End & Lenght

mikael.macial
Participant Participant
5,994 Views
30 Replies
Message 1 of 31

Lisp - Polyline Start, End & Lenght

mikael.macial
Participant
Participant

Hi y'all!

 

I have a little project that I'm working on, and I need a LISP that gives me these things in a .txt file:

 

Polylines: start X/Y, end X/Y, lenght

Cogo Point: easting, northing, raw description

 

The main objective is to extract these informations all at once, selecting all the polylines and cogo points manually, then getting a .txt file that gives me these infos separated by line, so I can read all that on a excel routine easily.

 

I think it's a easy lisp to do, but I'm not good with lisp, so can someone help me?

0 Likes
Accepted solutions (2)
5,995 Views
30 Replies
Replies (30)
Message 2 of 31

hak_vz
Advisor
Advisor

Can plain points be used instead COGO points?

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 31

hak_vz
Advisor
Advisor

I have written this test code. Test it in Civil 3d and fix what needed.

(defun c:foo ( / ss f file len start end s pntobj descr east north)
(vl-load-com)
(setq ss (ssget "X" '((0 . "LWPOLYLINE"))))
(setq f (getfiled "Open File to write layout names" (getvar "dwgprefix") "txt" 3)
    file (open f "w")
    s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
)

(vlax-for poly s
(setq
    len (rtos (vla-get-length poly) 2 2)
    start (vlax-curve-getstartpoint poly)
    end (vlax-curve-getendpoint poly)
    start (mapcar 'set '(xs ys zs) start)
    end (mapcar 'set '(xe ye ze) end)
    (write-line (strcar xs "," ys "," zs "," xe "," ye "," ze "," len) file)
    
))
(setq 
    s nil
    ss (ssget '((0 . "AECC_COGO_POINT")))
    s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
)

; modified code  from jeff_m  https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637
    (vlax-for pnt s
        (setq pntobj (vlax-ename->vla-object pnt))
        (setq descr	  (vlax-get pntobj 'fulldescription)
          east  (vlax-get pntobj 'easting)
          north (vlax-get pntobj 'northing)
        )
        (write-line (strcat east "," north "," descr) file)
    )
 (close file)
  (princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 31

mikael.macial
Participant
Participant

I tried to use the command "foo" but it didn't exist, maybe am I doing something wrong?

 

Yes, it could be a plain point, but a cogo point would be better cause I can add a description to it.

0 Likes
Message 5 of 31

hak_vz
Advisor
Advisor
(defun c:foo ( / ss f file len start end s pntobj descr east north xs ys zs xe ye ze)
(vl-load-com)
(setq ss (ssget "X" '((0 . "LWPOLYLINE"))))
(setq f (getfiled "Open File to write layout names" (getvar "dwgprefix") "txt" 3) file (open f "w") s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))

(vlax-for poly s
(setq
    len (vla-get-length poly)
    start (vlax-curve-getstartpoint poly)
    end (vlax-curve-getendpoint poly)
    len (rtos len 2 2)
   start (mapcar 'set '(xs ys zs) start)
    end (mapcar 'set '(xe ye ze) end)  
    xs (rtos xs 2 2)
    ys (rtos ys 2 2)
    zs (rtos zs 2 2)
    xe (rtos xe 2 2)
    ye (rtos ye 2 2)
    ze (rtos ze 2 2)
)
(write-line (strcat xs "," ys "," zs "," xe "," ye "," ze "," len) file)
)

(setq 
    s nil
    ss (ssget '((0 . "AECC_COGO_POINT")))
    s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
)

; modified code  from jeff_m  https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637
    (vlax-for pnt s
        (setq pntobj (vlax-ename->vla-object pnt))
        (setq descr	  (vlax-get pntobj 'fulldescription)
          east  (vlax-get pntobj 'easting)
          north (vlax-get pntobj 'northing)
        )
        (write-line (strcat east "," north "," descr) file)
    )
 (close file)
  (princ)
)

try now

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 31

hak_vz
Advisor
Advisor

If it works select "Accept Solution" in options aside (three dots in a blue square).

I can not test in Civil 3d. If you know some lisp edit write-line as you would like.

Follow up tomorrow, its time to go!

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 7 of 31

mikael.macial
Participant
Participant

Now I can run the function!

 

But right after I select a .txt file to save, it gives me the error "; error: no function definition: VLAX-CURVE-GETSTARTPOINT".

 

I've attached the image of the lisp opened in the lisp editor of AutoCad Civil 3D.

0 Likes
Message 8 of 31

dlanorh
Advisor
Advisor
This could be a lag issue

type (vl-load-com) on the command line and press enter.

draw a line

then type (vlax-curve-getstartpoint (car (entsel "\nSelect Line : "))) and press enter then select the line.

Does it still error?


I am not one of the robots you're looking for

Message 9 of 31

mikael.macial
Participant
Participant

Yes, it gives me the same error

0 Likes
Message 10 of 31

hak_vz
Advisor
Advisor

This works ok in acad 2014. I have to check why this doesnt work in Civil 3d.

For a test try to aply function on a drawing with just cogo points, to check if that part of code works ok.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 11 of 31

hak_vz
Advisor
Advisor

It works correctly, at least in Acad.

 

(defun c:foo ( / ss f file len start end s pntobj descr east north xs ys zs xe ye ze)
(vl-load-com)
(setq ss (ssget "X" '((0 . "*POLYLINE"))))
(setq f (getfiled "Open File to write points and polylines >" (getvar "dwgprefix") "txt" 3) file (open f "w") s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(if (and ss)
(vlax-for poly s
(setq
    len (vla-get-length poly)
    start (vlax-curve-getStartPoint poly)
    end (vlax-curve-getEndPoint poly)
    len (rtos len 2 2)
   start (mapcar 'set '(xs ys zs) start)
    end (mapcar 'set '(xe ye ze) end)  
    xs (rtos xs 2 2)
    ys (rtos ys 2 2)
    zs (rtos zs 2 2)
    xe (rtos xe 2 2)
    ye (rtos ye 2 2)
    ze (rtos ze 2 2)
)
(write-line (strcat xs "," ys "," zs "," xe "," ye "," ze "," len) file)
)
)

(setq 
    s nil ss nil
    ss (ssget '((0 . "AECC_COGO_POINT")))
    s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
)

; modified code  from jeff_m  https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637
(if (and ss)
    (vlax-for pnt s
        (setq pntobj (vlax-ename->vla-object pnt))
        (setq descr	  (vlax-get pntobj 'fulldescription)
          east  (vlax-get pntobj 'easting)
          north (vlax-get pntobj 'northing)
        )
        (write-line (strcat east "," north "," descr) file)
    )
)
 (close file)
  (princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 12 of 31

dlanorh
Advisor
Advisor
What operating system are you using?

I am not one of the robots you're looking for

Message 13 of 31

mikael.macial
Participant
Participant

I'm using Windows 10 x64, testing in AutoCad Civil 3D 2020.

 

When using the lisp with justo cogo points in the drawing, I select them and it gives me the error "; error: no function definition: VLAX-ENAME->VLA-OBJECT".

 

My main objective is to use a lisp to give me the informations like this:

 

- When Cogo Point: x , y , layer , raw description;

- When Polyline: start x , start y , end x , end y, layer , lenght;

- If the object doesn't have the information, keep it empty.

 

Example:

 

start x , start y , end x , end y , layer , raw description , lenght

 

100 , 100 , (empty) , (empty) , aerial , P1 , (empty)           - this is a point

100 , 100 , 230 , 250 , aerial , (empty) , 400                       - this is a polyline

 

My friend found a lisp that works fine here, but have a different purpose, it gives the coordinates of all the vertex of the polyline. I'm attaching it here.

0 Likes
Message 14 of 31

dlanorh
Advisor
Advisor

Your problem may be related to the fact that some registry keys are missing and/or Autocad cannot find the Visual Lisp arx file.

 

See Here 

 

I would discuss this with the person in charge of your CAD before applying any third party solution that involves altering your registry, and cross check with AutoCAD

I am not one of the robots you're looking for

Message 15 of 31

hak_vz
Advisor
Advisor

Lisp file that your friend provided is written without using visual lisp and that's why it works. But as @dlanorh  stated, you may have problem with registry keys. I could rewrite file to use only plain vanilla autolisp but that wont solve your problem.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 16 of 31

mikael.macial
Participant
Participant

Got it.

 

I'm contacting the support of autocad provider of my company, to see if they can help.

 

Thanks both of you for the help!!

 

After getting an answer I post it here.

0 Likes
Message 17 of 31

Sea-Haven
Mentor
Mentor

If you do Appload and look at loaded files VL.arx should be there. This is CIV3D 2020. If its not loaded then use appload and load it. Not sure if this is correct file as mine works.

 

screenshot138.png

Message 18 of 31

mikael.macial
Participant
Participant

I've checked that and it is loaded.

 

Could you please test the lisp above to see if it works fine?

 

I've contacted my company's autocad distributor, and they said that they can't help me, cause the LISP routine is not created by them. =/

0 Likes
Message 19 of 31

hak_vz
Advisor
Advisor

1) Copy following line into console and hit enter

(vl-load-com)

2) Copy following line into console and hit enter

(defun c:whatIsThis () (alert (strcat "This is " (substr (vlax-get (vlax-ename->vla-object (car(entsel "\nSelect something >"))) 'entityname) 5)))(princ))

As a result you'll get

C:WHATISTHIS

Type wharisthis in command line and select what ever drawing object.

 

What you get?

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 20 of 31

mikael.macial
Participant
Participant

It says to select something, then no matter what i select, it says "VLAX-ENAME->VLA-OBJECT".

I've tried with polylines, lines, cogo points, points, circles...

0 Likes