lucky9 Posted February 5, 2021 Share Posted February 5, 2021 (edited) Hi, I have given a task to show line detailing on leader in the following manner Line No, Diameter & Length, although the above data are already placed in the drawing I receive, but in very small font size. I need to show them in leader in a visible size. I'm attaching a sample file of it. Its taking me a lot of time manually placing the leader and adding details. I'm looking for a lisp that would help to get the job done in short time. I need a lisp which ask for data by selection or manually taking all three input form a user. Options 1) Select all three properties (Line No, Diameter and Length one by one then create leader to place in desired location. 2) Ask to insert (Input Data) manually. Edit: The line data (source) must be eraised after it was placed on leader. Best Regards Lucky9 Edited July 28, 2021 by lucky9 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted February 5, 2021 Share Posted February 5, 2021 You really should be using an mleader for this. Quote Link to comment Share on other sites More sharing options...
Steven P Posted February 5, 2021 Share Posted February 5, 2021 Lee Mac has quite a nice little tool, copy and swap text, on his website, If I am looking at this right, the text you need is there in the drawing? So make up the leader / Mleader and then use this LISP to copy the text into it. This will work best if the text you are copying is mtext and can copy all in one go Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 5, 2021 Share Posted February 5, 2021 Just my opinion, I would use a layout and a blow up viewport of that area then do the mleaders as the person who checked a dwg would get my staff to have another go to confusing. We got gas plans like this and often would have a blowup of areas or even another sheet. Quote Link to comment Share on other sites More sharing options...
lucky9 Posted February 6, 2021 Author Share Posted February 6, 2021 20 hours ago, Steven P said: Lee Mac has quite a nice little tool, copy and swap text, on his website, If I am looking at this right, the text you need is there in the drawing? So make up the leader / Mleader and then use this LISP to copy the text into it. This will work best if the text you are copying is mtext and can copy all in one go The worst part is I don't know how to code, I'm good at VBA excel only but not in lisp not even a beginner level. Quote Link to comment Share on other sites More sharing options...
Steven P Posted February 6, 2021 Share Posted February 6, 2021 1 hour ago, lucky9 said: The worst part is I don't know how to code, I'm good at VBA excel only but not in lisp not even a beginner level. Going back to Lee Mac, he has been very good and careful to have a section on his website on how to get a LISP working (If I remember correctly, if not it is the type of thing he does). If you search out the copy text LISP, save it somewhere and then load it into AutoCAD using Appload (sorry if I am teaching you what you know), it is there to use - no coding needed his routines are good to go - then just type in the command (CTX in this LISP I think - it is defined in a LISP after the statement (defun c:xxxxx (.... with the command being the xxxxx - same as VBA really) However BigALs viewport solution will work well Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 6, 2021 Share Posted February 6, 2021 (edited) Code in VBA if you know that you can mix and match lisp with VBA both can call a program to run. I am sure if you google will find a VBA leader example. You just need to know the equivalents to some common methods of selecting entsel, ssget, Getpoint etc stufflike XYZ of a point are car cadr caddr , point(0) point(1) point(2) I am no expert in VBA just enough knowledge to be dangerous. If you get stuck ask. Edited February 6, 2021 by BIGAL Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 18, 2021 Author Share Posted July 18, 2021 Sorry, for bumping the thread. Can anyone help me with any solution. Its too much work for me to copy and paste leader putting details for each line. please help me with lisp solution. My eyes worn-out doing this manually, I'm very depressed. Quote Link to comment Share on other sites More sharing options...
confutatis Posted July 18, 2021 Share Posted July 18, 2021 (edited) Is it possible to get a sample drawing piece? Are the texts to be imported individual texts or is it an MTEXT entity? The lisp program is already sketched out, but I would need the actual small text data from the drawing. Edited July 18, 2021 by confutatis Quote Link to comment Share on other sites More sharing options...
confutatis Posted July 18, 2021 Share Posted July 18, 2021 (defun C:MLEA (/ ss listsmallnumber listacoo data1 data2 data3 xmax xmin ymax ymin PT p1 points oML index) (setq ss (ssget '((0 . "TEXT"))) listsmallnumber (mapcar '(lambda (elem) (list elem (vla-get-Textstring elem))) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))) listacoo '() ) (foreach elem listsmallnumber (cond ((vl-string-search "P-" (cadr elem)) (setq data1 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ((vl-string-search " mm" (cadr elem)) (setq data2 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ((vl-string-search " m" (cadr elem)) (setq data3 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ) ) (setq listacoo (apply 'append listacoo) xmax (apply 'max (mapcar 'car listacoo)) xmin (apply 'min (mapcar 'car listacoo)) ymax (apply 'max (mapcar 'cadr listacoo)) ymin (apply 'min (mapcar 'cadr listacoo)) PT (reverse (cons 0.0 (reverse (polar (list xmin ymin) (angle (list xmin ymin) (list xmax ymax)) (/ (distance (list xmin ymin) (list xmax ymax)) 2.00))))) p1 (getpoint "\nSelection point text MLeader: ") points (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 5)) (apply 'append (list PT p1)) ) ) oML (vla-AddMLeader (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)) ) points 0 ) ) (vla-put-TextString oML (strcat data1 "\\P" data2 "," data3)) (vla-put-TextLineSpacingStyle oML 2) (vla-put-TextLineSpacingFactor oML 1.0) (vla-put-TextleftAttachmentType oML 7) (vla-put-TextRightAttachmentType oML 7) (repeat (setq index (sslength ss)) (entdel (ssname ss (setq index (1- index))))) ) This is how it should go, the program selects the small texts (TEXT entities) and asks for the insertion point of the multileader text. The insertion point of the arrow is calculated by doing a getboundingbox of the texts and calculating the centre point. At the end the small texts are deleted. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 18, 2021 Share Posted July 18, 2021 (edited) Without a dwg bit hard to comment, confutatis needs a while for multi leaders. use the pt as per your code but only once, the pt Y value should auto increase so get a nice vertical pattern also need a do leader to left or right. Edited July 18, 2021 by BIGAL Quote Link to comment Share on other sites More sharing options...
confutatis Posted July 19, 2021 Share Posted July 19, 2021 Let's just say I went a bit by intuition, seeing the image. Then, just move the mleader grip and you can put it where you want. In any case it should speed up the work of lucky9 and if there is something to change I will already have a good base. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 20, 2021 Share Posted July 20, 2021 confutatis you are right need Lucky9 to respond. 1 Quote Link to comment Share on other sites More sharing options...
confutatis Posted July 20, 2021 Share Posted July 20, 2021 Thanks, Bigal! Also because lucky9 had seemed pretty desperate to me, to post 5 months down the road... Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 20, 2021 Author Share Posted July 20, 2021 16 hours ago, BIGAL said: confutatis you are right need Lucky9 to respond. Sorry guys, I was down with fever so couldn't respond. On 7/18/2021 at 5:08 PM, confutatis said: Is it possible to get a sample drawing piece? Are the texts to be imported individual texts or is it an MTEXT entity? The lisp program is already sketched out, but I would need the actual small text data from the drawing. I'm attaching two files 1. Out file in DXF format file which I receive to process 2. Network file - after processing out file. I do it all manually. Regards, Lucky 1. Network.dwg Out_D1-12-07-21.dxf Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 20, 2021 Share Posted July 20, 2021 I use this regularly. (defun c:MC (/ *error* AT:GetSel AT:TextString _getPoint ss cmd e slst elst ent p1 elast prop wid o d l) ;; Multileader Copy ;; Alan J. Thompson, 04.07.09 / 11.23.10 / 04.28.11 / 2014.06.02 / 2014.09.24 / 2016.03.29 / 2016.12.09 ;; Global variables: *MLeaderCopy:Layer* *MLeaderCopy:Return* (defun *error* (msg) (foreach e elst (redraw e 4)) (and ss (sssetfirst nil nil)) (and cmd (setvar 'CMDECHO cmd)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (progn (vl-bt) (princ (strcat "\nError: " msg))) ) ) (defun AT:GetSel (meth msg fnc / ent) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (while (progn (setvar 'ERRNO 0) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again.")) ((eq (type (car ent)) 'ENAME) (if (and fnc (not (fnc ent))) (princ "\nInvalid object!") ) ) ) ) ) ent ) (defun AT:TextString (Obj) ;; Extract textstring (with symbols) from text object ;; Works on: Attrib, Attdef, MText, Multileader, Text ;; Obj - Object to extract textstring from ;; Alan J. Thompson, 11.24.09 / 04.13.10 (if Obj ((lambda (e) (cond ((eq (cdr (assoc 0 e)) "MULTILEADER") (cdr (assoc 304 e))) ((vl-position (cdr (assoc 0 e)) '("ATTDEF" "ATTRIB" "TEXT")) (cdr (assoc 1 e))) ((eq (cdr (assoc 0 e)) "MTEXT") (apply 'strcat (mapcar (function (lambda (x) (if (vl-position (car x) '(1 3)) (cdr x) "" ) ) ) e ) ) ) ) ) (entget (cond ((vl-consp Obj) (car Obj)) ((eq (type Obj) 'ENAME) Obj) ((eq (type Obj) 'VLA-ObjECT) (vlax-vla-object->ename Obj)) ) ) ) ) ) (defun _getPoint (/ p) (initget 0 "Current Object Hard Soft") (cond ((not (setq p (getpoint (strcat "\nUse [Hard/Soft] return? <" (cond (*MLeaderCopy:Return*) ((setq *MLeaderCopy:Return* "Hard")) ) ">\nUse [Current/Object] layer? <" (cond (*MLeaderCopy:Layer*) ((setq *MLeaderCopy:Layer* "Current")) ) ">\nSpecify first mleader point: " ) ) ) ) nil ) ((eq (type p) 'STR) (set (cdr (assoc p '(("Current" . *MLeaderCopy:Layer*) ("Object" . *MLeaderCopy:Layer*) ("Hard" . *MLeaderCopy:Return*) ("Soft" . *MLeaderCopy:Return*) ) ) ) p ) (_getpoint) ) ((vl-consp p) p) ) ) (if (and (or (and (setq ss (ssget "_I" '((0 . "ATTDEF,ATTRIB,MTEXT,MULTILEADER,TEXT")))) (eq (sslength ss) 1) (setq e (ssname ss 0) elst (list e) slst (list (list "" (AT:TextString e))) ) (progn (redraw e 3) T) ) (while (setq e (car (AT:GetSel nentsel (strcat "\nSelect source text object for copying" (if acet-sys-shift-down " (Hold down <Shift> to combine w/space: " ": " ) ) (lambda (x) (wcmatch (cdr (assoc 0 (entget (car x)))) "ATTDEF,ATTRIB,MTEXT,MULTILEADER,TEXT") ) ) ) ) (progn (redraw e 3) (setq slst (cons (list (if (and acet-sys-shift-down (acet-sys-shift-down)) " " (if (eq *MLeaderCopy:Return* "Hard") "\\P" "\n" ) ) (AT:TextString (car (setq elst (cons e elst)))) ) slst ) ) ) ) ) (setq p1 (_getPoint)) (setq elast (entlast)) (progn (setq cmd (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (princ "\nSpecify next point: ")) (vl-cmdf "_.mleader" "_non" p1 PAUSE) (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (vl-cmdf "")) (not (equal elast (setq elast (entlast)))) ) (progn (vla-put-textstring (setq o (vlax-ename->vla-object elast)) (apply 'strcat (cdr (apply 'append (reverse slst)))) ) (if (and (eq (length elst) 1) (setq prop (cdr (assoc (cdr (assoc 0 (entget (car elst)))) '(("MTEXT" . Width) ("MULTILEADER" . TextWidth)) ) ) ) (not (zerop (setq wid (vlax-get (vlax-ename->vla-object (car elst)) prop)))) ) (vla-put-textwidth o wid) ) (if (eq *MLeaderCopy:Layer* "Object") (vla-put-layer o (cdr (assoc 8 (entget (last elst))))) ) (initget 0 "Yes No") (if (eq (getkword "\nDelete original? [Yes/No] <No>: ") "Yes") (foreach e elst (if (and (eq (cdr (assoc 0 (setq d (entget e)))) "MTEXT") (setq l (cdr (assoc 330 d))) (entget l) ) (entdel l) ; qlattached leader, if e is MTEXT ) (entdel e) ; select text object ) ) ) ) (*error* nil) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 20, 2021 Share Posted July 20, 2021 3 hours ago, lucky9 said: Sorry guys, I was down with fever so couldn't respond. I'm attaching two files 1. Out file in DXF format file which I receive to process 2. Network file - after processing out file. I do it all manually. Regards, Lucky 1. Network.dwg 245.31 kB · 0 downloads Out_D1-12-07-21.dxf 373.7 kB · 0 downloads Looks like a WaterCAD model. Question .. why don't you make your sheets at a smaller scale so all this cleanup is not necessary? You're a very patient person doing this by hand ... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 20, 2021 Share Posted July 20, 2021 Like ronjonp make layouts at a smaller scale I have make layouts whilst this follows a pline it will still work for rectangs any where on your dwg. So make 1 then copy. it will make the layouts to suit. It does though need some details about the layout and mview size. I am having problems posting a video. Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 21, 2021 Author Share Posted July 21, 2021 (edited) On 7/19/2021 at 3:07 AM, confutatis said: (defun C:MLEA (/ ss listsmallnumber listacoo data1 data2 data3 xmax xmin ymax ymin PT p1 points oML index) (setq ss (ssget '((0 . "TEXT"))) listsmallnumber (mapcar '(lambda (elem) (list elem (vla-get-Textstring elem))) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))) listacoo '() ) (foreach elem listsmallnumber (cond ((vl-string-search "P-" (cadr elem)) (setq data1 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ((vl-string-search " mm" (cadr elem)) (setq data2 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ((vl-string-search " m" (cadr elem)) (setq data3 (cadr elem)) (vla-getboundingbox (car elem) 'a 'b)(setq a (safearray-value a))(setq b (safearray-value b)) (setq listacoo (cons (list a b) listacoo)) ) ) ) (setq listacoo (apply 'append listacoo) xmax (apply 'max (mapcar 'car listacoo)) xmin (apply 'min (mapcar 'car listacoo)) ymax (apply 'max (mapcar 'cadr listacoo)) ymin (apply 'min (mapcar 'cadr listacoo)) PT (reverse (cons 0.0 (reverse (polar (list xmin ymin) (angle (list xmin ymin) (list xmax ymax)) (/ (distance (list xmin ymin) (list xmax ymax)) 2.00))))) p1 (getpoint "\nSelection point text MLeader: ") points (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 5)) (apply 'append (list PT p1)) ) ) oML (vla-AddMLeader (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)) ) points 0 ) ) (vla-put-TextString oML (strcat data1 "\\P" data2 "," data3)) (vla-put-TextLineSpacingStyle oML 2) (vla-put-TextLineSpacingFactor oML 1.0) (vla-put-TextleftAttachmentType oML 7) (vla-put-TextRightAttachmentType oML 7) (repeat (setq index (sslength ss)) (entdel (ssname ss (setq index (1- index))))) ) This is how it should go, the program selects the small texts (TEXT entities) and asks for the insertion point of the multileader text. The insertion point of the arrow is calculated by doing a getboundingbox of the texts and calculating the centre point. At the end the small texts are deleted. Hi, confutatis I ran your code it is giving me this error. Edited August 15, 2021 by lucky9 Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 21, 2021 Author Share Posted July 21, 2021 (edited) On 7/21/2021 at 2:49 AM, alanjt said: I use this regularly. (defun c:MC (/ *error* AT:GetSel AT:TextString _getPoint ss cmd e slst elst ent p1 elast prop wid o d l) ;; Multileader Copy ;; Alan J. Thompson, 04.07.09 / 11.23.10 / 04.28.11 / 2014.06.02 / 2014.09.24 / 2016.03.29 / 2016.12.09 ;; Global variables: *MLeaderCopy:Layer* *MLeaderCopy:Return* (defun *error* (msg) (foreach e elst (redraw e 4)) (and ss (sssetfirst nil nil)) (and cmd (setvar 'CMDECHO cmd)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (progn (vl-bt) (princ (strcat "\nError: " msg))) ) ) (defun AT:GetSel (meth msg fnc / ent) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (while (progn (setvar 'ERRNO 0) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again.")) ((eq (type (car ent)) 'ENAME) (if (and fnc (not (fnc ent))) (princ "\nInvalid object!") ) ) ) ) ) ent ) (defun AT:TextString (Obj) ;; Extract textstring (with symbols) from text object ;; Works on: Attrib, Attdef, MText, Multileader, Text ;; Obj - Object to extract textstring from ;; Alan J. Thompson, 11.24.09 / 04.13.10 (if Obj ((lambda (e) (cond ((eq (cdr (assoc 0 e)) "MULTILEADER") (cdr (assoc 304 e))) ((vl-position (cdr (assoc 0 e)) '("ATTDEF" "ATTRIB" "TEXT")) (cdr (assoc 1 e))) ((eq (cdr (assoc 0 e)) "MTEXT") (apply 'strcat (mapcar (function (lambda (x) (if (vl-position (car x) '(1 3)) (cdr x) "" ) ) ) e ) ) ) ) ) (entget (cond ((vl-consp Obj) (car Obj)) ((eq (type Obj) 'ENAME) Obj) ((eq (type Obj) 'VLA-ObjECT) (vlax-vla-object->ename Obj)) ) ) ) ) ) (defun _getPoint (/ p) (initget 0 "Current Object Hard Soft") (cond ((not (setq p (getpoint (strcat "\nUse [Hard/Soft] return? <" (cond (*MLeaderCopy:Return*) ((setq *MLeaderCopy:Return* "Hard")) ) ">\nUse [Current/Object] layer? <" (cond (*MLeaderCopy:Layer*) ((setq *MLeaderCopy:Layer* "Current")) ) ">\nSpecify first mleader point: " ) ) ) ) nil ) ((eq (type p) 'STR) (set (cdr (assoc p '(("Current" . *MLeaderCopy:Layer*) ("Object" . *MLeaderCopy:Layer*) ("Hard" . *MLeaderCopy:Return*) ("Soft" . *MLeaderCopy:Return*) ) ) ) p ) (_getpoint) ) ((vl-consp p) p) ) ) (if (and (or (and (setq ss (ssget "_I" '((0 . "ATTDEF,ATTRIB,MTEXT,MULTILEADER,TEXT")))) (eq (sslength ss) 1) (setq e (ssname ss 0) elst (list e) slst (list (list "" (AT:TextString e))) ) (progn (redraw e 3) T) ) (while (setq e (car (AT:GetSel nentsel (strcat "\nSelect source text object for copying" (if acet-sys-shift-down " (Hold down <Shift> to combine w/space: " ": " ) ) (lambda (x) (wcmatch (cdr (assoc 0 (entget (car x)))) "ATTDEF,ATTRIB,MTEXT,MULTILEADER,TEXT") ) ) ) ) (progn (redraw e 3) (setq slst (cons (list (if (and acet-sys-shift-down (acet-sys-shift-down)) " " (if (eq *MLeaderCopy:Return* "Hard") "\\P" "\n" ) ) (AT:TextString (car (setq elst (cons e elst)))) ) slst ) ) ) ) ) (setq p1 (_getPoint)) (setq elast (entlast)) (progn (setq cmd (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (princ "\nSpecify next point: ")) (vl-cmdf "_.mleader" "_non" p1 PAUSE) (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (vl-cmdf "")) (not (equal elast (setq elast (entlast)))) ) (progn (vla-put-textstring (setq o (vlax-ename->vla-object elast)) (apply 'strcat (cdr (apply 'append (reverse slst)))) ) (if (and (eq (length elst) 1) (setq prop (cdr (assoc (cdr (assoc 0 (entget (car elst)))) '(("MTEXT" . Width) ("MULTILEADER" . TextWidth)) ) ) ) (not (zerop (setq wid (vlax-get (vlax-ename->vla-object (car elst)) prop)))) ) (vla-put-textwidth o wid) ) (if (eq *MLeaderCopy:Layer* "Object") (vla-put-layer o (cdr (assoc 8 (entget (last elst))))) ) (initget 0 "Yes No") (if (eq (getkword "\nDelete original? [Yes/No] <No>: ") "Yes") (foreach e elst (if (and (eq (cdr (assoc 0 (setq d (entget e)))) "MTEXT") (setq l (cdr (assoc 330 d))) (entget l) ) (entdel l) ; qlattached leader, if e is MTEXT ) (entdel e) ; select text object ) ) ) ) (*error* nil) (princ) ) (vl-load-com) (princ) Hi alanjit, I ran your code It worked pretty well, its a lifesaver for me. Can the code be modified to match the text formatting in OP ? The text size I'm getting is too small how to fix it. Sorry, if I'm asking too much. ~lucky9 Edited July 28, 2021 by lucky9 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.