Lisp to Export Polyline handle and intersecting texts to excel

Lisp to Export Polyline handle and intersecting texts to excel

hythamthelove
Advocate Advocate
589 Views
5 Replies
Message 1 of 6

Lisp to Export Polyline handle and intersecting texts to excel

hythamthelove
Advocate
Advocate

Hii everyone,

I have a polyline with mtexts intersecting it

hythamthelove_1-1721201546231.png

 

i want to export polyline length and handle. Also i want to export mtexts is green (1 text only will be good), also i want to export the blue texts, the blue text may be 1 per polyline or may be two within the polyline. so the final outcome would be like that

hythamthelove_0-1721201528063.png

Does anyone have lisp for that ?

 

0 Likes
Accepted solutions (1)
590 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@hythamthelove  hi,

 

Can you tell us what these lines and texts represent?

 

Moshe

 

 

 

0 Likes
Message 3 of 6

hythamthelove
Advocate
Advocate

it is just cables with different types and stretching

0 Likes
Message 4 of 6

Moshe-A
Mentor
Mentor

@hythamthelove  hi,

 

check this...to fetch the texts i used the following expresstion on line #27

(setq ss1 (ssget "_c" t0 t3 '((0 . "text,mtext"))))

 

where t0, t3 calculated bounding box around the pline offset 150. this value is set with (setq SELOSET 150.0) on line #8, you can change this value if needed according to drawing scale.

 

the excel file created is csv format 😀

 

enjoy

Moshe

 

 

 

 

 

(defun c:nb (/ _greenFields _blueFields  ; local functions
	       SELOSET curfname excelfname f ss0 ss1 ename0 ename1 elist1 p0 p1 t0 t3 green^ blue^ bluStr)

 ; anonym,ous functions 
 (setq _greenFields (lambda (lst) (car (mapcar (function (lambda (ent) (cdr (assoc '1 (entget ent))))) lst))))
 (setq _blueFields  (lambda (lst) (substr (apply 'strcat (mapcar (function (lambda (str) (strcat "," str))) (mapcar (function (lambda (ent) (cdr (assoc '1 (entget ent))))) lst))) 2))) 
			    
 (setq SELOSET 150.0)
  
 (if (setq ss0 (ssget '((0 . "line,lwpolyline"))))
  (progn 
   (setq curfname (strcat (getvar "dwgprefix") (getvar "dwgname")))
   (setq excelfname (strcat (vl-filename-directory curfname) "\\" (vl-filename-base curfname) ".csv"))
   (setq f (open excelfname "w"))

   (write-line "Handle,Length,Green Text,Blue Text1,Blue Text2" f) ; header line
  
   (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
    (setq p0 (vlax-curve-getStartPoint ename0))
    (setq p1 (vlax-curve-getEndPoint ename0))
     
    (setq t0 (polar p0 (- (angle p0 p1) (/ pi 2)) SELOSET)) 
    (setq t3 (polar p1 (+ (angle p0 p1) (/ pi 2)) SELOSET)) 
    
    (setq green^ nil blue^ nil)
     
    (if (setq ss1 (ssget "_c" t0 t3 '((0 . "text,mtext"))))
     (progn
      (foreach ename1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
       (setq elist1 (entget ename1))
       (cond
        ((= (cdr (assoc '62 elist1)) 3)
         (setq green^ (cons ename1 green^))
        )
        ((= (cdr (assoc '62 elist1)) 5)
         (setq blue^ (cons ename1 blue^))
        )
       ); cond
      ); foreach
     ); progn
    ); if

    (if (= (vl-list-length blue^) 1)
     (setq bluStr (strcat (_blueFields blue^) ",0"))
     (setq bluStr (_blueFields blue^))
    )
       
     
    ; write out to csv file 
    (write-line (strcat (cdr (assoc '5 (entget ename0))) "," (rtos (distance p0 p1) 2 0) "," (_greenFields green^) "," bluStr) f)

   ); foreach

   (setq f (close f)) ; close file
  ); progn
 ); if

 (princ "\nDone.")  
 (princ)
); c:nb

 

 

0 Likes
Message 5 of 6

Moshe-A
Mentor
Mentor
Accepted solution

@hythamthelove  hi,

 

Attached is an update after fine tunning

 

i would like to hear your feedback? 

 

if it answer your request then do mark it as your solution?

 

Moshe

 

 

 

 

0 Likes
Message 6 of 6

hythamthelove
Advocate
Advocate

it works like magic, thank you for that you are brilliant 💪 

0 Likes