Hii everyone,
I have a polyline with mtexts intersecting it
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
Does anyone have lisp for that ?
Solved! Go to Solution.
Solved by Moshe-A. Go to Solution.
@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
@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
Can't find what you're looking for? Ask the community or share your knowledge.