Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to Export Polyline handle and intersecting texts to excel

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
hythamthelove
349 Views, 5 Replies

Lisp to Export Polyline handle and intersecting texts to excel

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 ?

 

5 REPLIES 5
Message 2 of 6
Moshe-A
in reply to: hythamthelove

@hythamthelove  hi,

 

Can you tell us what these lines and texts represent?

 

Moshe

 

 

 

Message 3 of 6
hythamthelove
in reply to: Moshe-A

it is just cables with different types and stretching

Message 4 of 6
Moshe-A
in reply to: hythamthelove

@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

 

 

Message 5 of 6
Moshe-A
in reply to: hythamthelove

@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

 

 

 

 

Message 6 of 6
hythamthelove
in reply to: Moshe-A

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta