Jump to content

Leader with text


lucky9

Recommended Posts

On 7/21/2021 at 9:13 AM, lucky9 said:

 

Hi, confutatis I ran your code it is giving me this error.

 

 

 

 

 

 

EDIT:  

 

 

 

Your Code working fine, It was my fault, I selected only 2 text objects which was causing error. could you please modify the code to be little more flexible like it would ask for first insertion point, so that the leader be placed at desired location. The text size is too small how to fix it.

 

 

 

Regards,

lucky9

Edited by lucky9
Link to comment
Share on other sites

We'll sort it out now, I didn't have your dwg to hand so I had to guess by looking at the image. With the text boundingbox I wanted to save you a click... 😉

 

 

Edited by confutatis
Link to comment
Share on other sites

(defun C:MLEA (/ *error* ss listsmallnumber data1 data2 data3 data4 data5 P1 P2 points oML index)
 (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
 (defun *error* (msg)
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
   (progn (princ (strcat "\nError: " msg))
    (command-s "_UNDO" "")
   )
  )
 )
 (setq ss (ssget '((0 . "TEXT"))))
 (if (and (/= (sslength ss) 3)(/= (sslength ss) 5))
  (vl-exit-with-error (alert "Selection not 3 or 5 text!"))
 ) 
 (setq listsmallnumber (mapcar '(lambda (elem) (list elem (vla-get-Textstring elem)))
			(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
		       )
 )
 (cond
  ((= (sslength ss) 3)
   (foreach elem listsmallnumber
    (cond
     ((vl-string-search "P-" (cadr elem))
      (setq data1 (cadr elem))
     )
     ((vl-string-search " mm" (cadr elem))
      (setq data2 (cadr elem))
     )   
     ((vl-string-search " m" (cadr elem))
      (setq data3 (cadr elem))
     )
    )
   )
  )
  ((= (sslength ss) 5)
   (foreach elem listsmallnumber
    (cond
     ((vl-string-search "P-" (cadr elem))
      (setq data1 (cadr elem))
     )
     ((or (vl-string-search "ROAD" (cadr elem)) (vl-string-search "BO" (cadr elem)))
      (setq data2 (cadr elem))
     )
     ((vl-string-search "Ø" (cadr elem))
      (setq data3 (cadr elem))
     )   
     ((vl-string-search "m" (cadr elem))
      (setq data4 (cadr elem))
     )
     ((vl-string-search "L/s" (cadr elem))
      (setq data5 (cadr elem))
     )
    )
   )
  )
 )
 (cond
  ((= (sslength ss) 3)
   (if (not (and data1 data2 data3))
    (vl-exit-with-error (alert "Data missing!"))
   )
  ) 
  ((= (sslength ss) 5)
   (if (not (and data1 data2 data3 data4 data5))
    (vl-exit-with-error (alert "Data missing!"))
   )
  ) 
 )
 (setq P1 (getpoint "\nSelection first point MLeader: ")
       P2 (getpoint "\nSelection second point MLeader: " P1)
       points (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 5)) (apply 'append (list P1 P2))))
       oML (vla-AddMLeader (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) points 0)
 )
 (cond
  ((= (sslength ss) 3)
   (vla-put-TextString oML (strcat data1 "\\P" data2 "," data3))
  ) 
  ((= (sslength ss) 5)
   (vla-put-TextString oML (strcat data1 "," data2 "\\P" data3 "," data4 "\\P" data5))
  ) 
 ) 
 (if (< (car P2)(car P1))
  (vla-setdoglegdirection oML (vla-getleaderindex oML 0) (vlax-3d-point (list -1.0 0.0 0.0)))
  (vla-setdoglegdirection oML (vla-getleaderindex oML 0) (vlax-3d-point (list 1.0 0.0 0.0)))
 )	
 (vla-put-TextLineSpacingStyle oML 2)
 (vla-put-TextLineSpacingFactor oML 0.8)
 (vla-put-TextleftAttachmentType oML 7)
 (vla-put-TextRightAttachmentType oML 7)
 (vla-put-ArrowheadSize oML 10)
 (vla-put-TextHeight oML 7)
 (vla-put-TextJustify oML 2)
 (vla-put-TextStyleName oML "Standard")
 (vla-put-DogLegLength oML 3.00)
 (if (= (sslength ss) 3)
  (progn
   (if (not (tblsearch "LAYER" (strcat "PIPE" (substr data2 1 (- (strlen data2) 3)))))
    (vla-add (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (strcat "PIPE" (substr data2 1 (- (strlen data2) 3))))
   )
   (vla-put-layer oML (strcat "PIPE" (substr data2 1 (- (strlen data2) 3))))
  )
 ) 
 (repeat (setq index (sslength ss)) (entdel (ssname ss (setq index (1- index)))))
 (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
 (princ)
)

 

There, that should do it. The mleader is placed on the "PIPExxx" layer, where xxx is the diameter of the pipe. If the layer does not exist, it is created, taking the diameter data.

Edited by confutatis
  • Agree 1
Link to comment
Share on other sites

(defun C:MTEXTALI (/ *error* ss listsmallnumber a b data1 data2 data3 data4 data5 P1 P2 pol P1 oTX index loop selez codice data)
 (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
 (defun *error* (msg)
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
   (progn (princ (strcat "\nError: " msg))
    (command-s "_UNDO" "")
   )
  )
 )
 (setq ss (ssget '((0 . "TEXT"))))
 (if (and (/= (sslength ss) 3)(/= (sslength ss) 5))
  (vl-exit-with-error (alert "Selection not 3 or 5 text!"))
 ) 
 (setq listsmallnumber (mapcar '(lambda (elem) (list elem (vla-get-Textstring elem)))
			(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
		       )
 )
 (cond
  ((= (sslength ss) 3)
   (foreach elem listsmallnumber
    (cond
     ((vl-string-search "P-" (cadr elem))
      (setq data1 (cadr elem))
     )
     ((vl-string-search " mm" (cadr elem))
      (setq data2 (cadr elem))
     )   
     ((vl-string-search " m" (cadr elem))
      (setq data3 (cadr elem))
     )
    )
   )
  )
  ((= (sslength ss) 5)
   (foreach elem listsmallnumber
    (cond
     ((vl-string-search "P-" (cadr elem))
      (setq data1 (cadr elem))
     )
     ((or (vl-string-search "ROAD" (cadr elem)) (vl-string-search "BO" (cadr elem)))
      (setq data2 (cadr elem))
     )
     ((vl-string-search "Ø" (cadr elem))
      (setq data3 (cadr elem))
     )   
     ((vl-string-search "m" (cadr elem))
      (setq data4 (cadr elem))
     )
     ((vl-string-search "L/s" (cadr elem))
      (setq data5 (cadr elem))
     )
    )
   )
  )
 )
 (cond
  ((= (sslength ss) 3)
   (if (not (and data1 data2 data3))
    (vl-exit-with-error (alert "Data missing!"))
   )
  ) 
  ((= (sslength ss) 5)
   (if (not (and data1 data2 data3 data4 data5))
    (vl-exit-with-error (alert "Data missing!"))
   )
  ) 
 )
 (setq pol (vlax-ename->vla-object (car (entsel "\nSelect pipe polyline: ")))
       P1 (getpoint "\nSelection position mtext: ")
       oTX (vla-AddMText (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-3d-point P1) 90 (strcat data1 "\\P" data2 "," data3))
 )
 (cond
  ((= (sslength ss) 3)
   (vla-put-TextString oTX (strcat data1 "\\P" data2 "," data3))
  ) 
  ((= (sslength ss) 5)
   (vla-put-TextString oTX (strcat data1 "," data2 "\\P" data3 "," data4 "\\P" data5))
  ) 
 )
 (vla-put-LineSpacingStyle oTX 2)
 (vla-put-LineSpacingFactor oTX 0.8)
 (vla-put-AttachmentPoint oTX 2)
 (vla-put-Height oTX 7)
 (vla-put-StyleName oTX "Standard")
 (vla-put-Rotation oTX (vla-get-Rotation (vlax-ename->vla-object (ssname ss 0))))
 (if (= (sslength ss) 3)
  (progn
   (if (not (tblsearch "LAYER" (strcat "PIPE" (substr data2 1 (- (strlen data2) 3)))))
    (vla-add (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (strcat "PIPE" (substr data2 1 (- (strlen data2) 3))))
   )
   (vla-put-layer oTX (strcat "PIPE" (substr data2 1 (- (strlen data2) 3))))
  )
 )
 (repeat (setq index (sslength ss)) (entdel (ssname ss (setq index (1- index)))))
 (setq loop "loop")
 (while loop
  (progn
   (setq selez	(grread T 15 0)
	 codice	(car selez)
	 data	(cadr selez)
   )
   (cond
    ((= 5 codice)
     (vla-put-InsertionPoint oTX (vlax-3d-point data))
     (if (and (> (vla-get-Rotation oTX) (/ pi 2)) (< (vla-get-Rotation oTX) (* (/ pi 2) 3)))
      (vla-put-Rotation oTX (- (angle data (vlax-curve-getClosestPointTo pol data)) (/ pi 2)))
      (vla-put-Rotation oTX (+ (angle data (vlax-curve-getClosestPointTo pol data)) (/ pi 2)))
     ) 
    ) 
    ((= 3 codice)
     (vla-put-InsertionPoint oTX (vlax-3d-point data))
     (setq loop nil)
    )
    (T
     (setq loop nil)
    )
   )
  )
 )
 (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
 (princ)
)

 

I have noticed that there is not always a mleader, sometimes it is just the text above the polyline. I had fun creating the program that inserts the texts and not the mleaders. Once the small texts are selected, the polyline is selected and the text is inserted dynamically, following the curves of the polyline.

Edited by confutatis
  • Agree 1
Link to comment
Share on other sites

@confutatis Whoa !  woohoo ! , Your code works like charm 💓😻 So, happy with the result. I was like doing all this manually and frustrated so much, It was so tedious work, and you just made my day.  Can't thank you enough! 😘😘😘😘

 

Today, Got this file to process which I'm attaching. There were more data on the line, when I use your code its not working. I wonder why it's not working?

 

 

Edited by lucky9
  • Like 1
Link to comment
Share on other sites

I'm glad I could solve a problem for you! As for the extra data, I'll have to check it out. There will be new conditions that I didn't anticipate, maybe different strings. I'll take a look as soon as I have a moment.

  • Like 1
Link to comment
Share on other sites

 

Quote

Today, Got this file to process which I'm attaching. There were more data on the line, when I use your code its not working. I wonder why it's not working?

 

 

 

As I imagined, the strings are completely different.

The commands in the two posts have been changed to suit the new requirements of having 3 or 5 texts. If only one of the texts does not meet the conditions of the string, the program exits. For the time being, the program only fixes the layer for the 3-text choice. Tell me how to operate the layer name. Then, if your needs change with other texts, we will see about making further modifications, so as to cover as many cases as possible.

 

Edited by confutatis
Link to comment
Share on other sites

  • 3 months later...

I'm Getting this Error while running the  lisp

 

Quote

C:MTEXTALI

 

 

Error: no function definition: VLA-GET-RO_UNDO Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back] <1>: GROUP

 

 

please help me fix it. It was working fine earlier but now its not.. :(

Edited by lucky9
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...