Lisp - Polyline Start, End & Lenght

Lisp - Polyline Start, End & Lenght

mikael.macial
Participant Participant
6,033 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)
6,034 Views
30 Replies
Replies (30)
Message 21 of 31

hak_vz
Advisor
Advisor

Here is a post about similar problem with acad 2018. Problem is probably with registry keys. There is even proposed solution, but as mentioned before you should fix it through your supplier. You just have to tell them my program doesn't work correctly, it has to be fixed or reinstalled. None of them would check if lisp function works correctly.

 

Problem sometime may emerge as a result if registry cleaner had been used. 

 

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 22 of 31

ronjonp
Mentor
Mentor

Excuse me if I missed something in this thread but have you tried a simple repair of C3D?

image.png

Message 23 of 31

mikael.macial
Participant
Participant

Ok, I've got some progress, I think...

 

I've reinstaled the AutoCad 2020.

 

Now, when i run the lisp, it asks to select something, then the only thing that it accepts is a cogo point.

 

After selecting it, it gives me the error:

 

; error: bad argument type: lentityp #<VLA-OBJECT IAeccPoint 0000022f54b74060>

0 Likes
Message 24 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 lay)
(vl-load-com)
(setq ss (ssget "X" '((0 . "*POLYLINE"))))
(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))))
(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)
    lay (vlax-get poly 'layer)
)
(mapcar 'set '(xs ys zs) start)
(mapcar 'set '(xe ye ze) end)
(setq  
    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 "," lay) 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  (rtos(vlax-get pntobj 'easting) 2 2)
          north (rtos(vlax-get pntobj 'northing) 2 2)
          elev (rtos(vlax-get pntobj 'elevation) 2 2)
          lay (vlax-get pntobj 'layer)
        )
        (write-line (strcat east "," north "," elev "," descr "," lay) file)
    )
)
 (close file)
  (princ)
)

Another test

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 25 of 31

ronjonp
Mentor
Mentor

Quick glance and the issue is here:

    (vlax-for pnt s
        (setq pntobj (vlax-ename->vla-object pnt))

'pnt' is already a vla-object

 

That vlax-for segment could be condensed to something like this:

(vlax-for pnt s
  (write-line
    (apply 'strcat
	   (mapcar '(lambda (x) (strcat (vl-princ-to-string (vlax-get pnt x)) ","))
		   '(easting northing elevation fulldescription layer)
	   )
    )
    file
  )
)
Message 26 of 31

mikael.macial
Participant
Participant

Same as before, can't select anything but cogo points, and same error:

 

; error: bad argument type: lentityp #<VLA-OBJECT IAeccPoint 00000222b03227f0>

0 Likes
Message 27 of 31

hak_vz
Advisor
Advisor

could you try to fix this code for @mikael.macial 

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 28 of 31

ronjonp
Mentor
Mentor
Accepted solution

@mikael.macial 

Try this version:

(defun c:foo (/ _csv _2l f file p s x)
  ;; RJP » 2020-01-13
  (defun _csv (l)
    (vl-string-right-trim
      ","
      (apply 'strcat
	     (mapcar '(lambda (x)
			(strcat	(if (= 'real (type x))
				  (rtos x 2 2)
				  (vl-princ-to-string x)
				)
				","
			)
		      )
		     l
	     )
      )
    )
  )
  (defun _2l (s)
    (if	s
      (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
    )
  )
  (if (setq f (getfiled "Open File to write layout names" (getvar 'dwgprefix) "csv" 3))
    (progn (setq file (open f "W"))
	   (foreach p (_2l (ssget "_X" '((0 . "*POLYLINE"))))
	     (write-line
	       (_csv (append (vlax-curve-getstartpoint p)
			     (vlax-curve-getendpoint p)
			     (list (vla-get-length p) (vla-get-layer p))
		     )
	       )
	       file
	     )
	   )
	   (foreach p (_2l (ssget '((0 . "AECC_COGO_POINT"))))
	     (write-line
	       (_csv (mapcar '(lambda (x) (vlax-get p x))
			     '(easting northing elevation fulldescription layer)
		     )
	       )
	       file
	     )
	   )
	   (close file)
	   (print f)
    )
  )
  (princ)
)
(vl-load-com)
Message 29 of 31

mikael.macial
Participant
Participant

Works greatly!

 

@ronjonp@hak_vz@Sea-Haven@dlanorh, thanks a lot for your help!!!

 

I'll have drawings with ~ 50 polylines and ~ 30 cogo points, and this lisp will save me a lot of time.

 

Thank you all again!

0 Likes
Message 30 of 31

ronjonp
Mentor
Mentor
Accepted solution

Glad you can use the code! 🍻

 

If you want the COGO points to be auto selected like the polylines, change this:

(_2l (ssget '((0 . "AECC_COGO_POINT"))))

to this

(_2l (ssget "_X" '((0 . "AECC_COGO_POINT"))))
Message 31 of 31

hak_vz
Advisor
Advisor

Thank you @ronjonp . @mikael.macial So, finally you have working code. 🙂

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.