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

Put all dynamic block parameter values in multileader

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
JCprog
593 Views, 5 Replies

Put all dynamic block parameter values in multileader

Hello everyone Smiley Happy

 

I have a this lisp that tags conduits with a multileader. Is there a way to make it work the same way with dynamic blocks which can include layer, blockname, all attributes and parameter values in a multileader? output text inside multileader would be like:

 

Layer: block1

Name: myblock

Visibility: 

Length: 5'-0"

Attribute: note

 

 

Please help. Thanks in advance Smiley Happy

 

(defun c:cndtag	(/ CNDEnt CNDObj PickPoint TagPoint CNDSize CNDSystem CNDTag)
  (vl-load-com)
  (if
    (and (setq CNDEnt (entsel "\nSelect the conduit to tag... "))
	 (setq CNDObj (vlax-ename->vla-object (car CNDEnt)))
	 (setq PickPoint (osnap (cadr CNDEnt) "nea"))
	 (setq TagPoint (getpoint PickPoint "\nPosition of conduit tag... "))
	 (vlax-property-available-p CNDObj "SizeName")
	 (setq CNDSize (substr (vlax-get-property CNDObj "SizeName") 1 4))
	 (vlax-property-available-p CNDObj "Description")
	 (setq CNDSystem (vlax-get-property CNDObj "Description"))
    )
     (progn
       (cond
	 ((= (substr CNDSize 2 3) ".00") (setq CNDSize (substr CNDSize 1 1)))
	 ((= (substr CNDSize 2 3) ".25")
	  (setq CNDSize (strcat (substr CNDSize 1 1) " 1/4"))
	 )
	 ((= (substr CNDSize 2 3) ".50")
	  (setq CNDSize (strcat (substr CNDSize 1 1) " 1/2"))
	 )
	 ((= (substr CNDSize 2 3) ".75")
	  (setq CNDSize (strcat (substr CNDSize 1 1) " 3/4"))
	 )
       )
       (if (= (substr CNDSize 1 2) "0 ")
	 (setq CNDSize (vl-string-left-trim "0 " CNDSize))
       )
       (setq CNDTag (strcat CNDSize "\" C, " CNDSystem))
       (command "_MLEADER" PickPoint TagPoint CNDTag)
     )
  )
  (princ)
)

 

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: JCprog


@JCprog wrote:

 

I have a this lisp that tags conduits with a multileader. Is there a way to make it work the same way with dynamic blocks which can include layer, blockname, all attributes and parameter values in a multileader? output text inside multileader would be like:

 

Layer: block1

Name: myblock

Visibility: 

Length: 5'-0"

Attribute: note

 


Hi JCprog,

 

as a 'demo':

 

(vl-load-com)
(defun c:demo (/ a atts b lst obj osm pt pt1 ss str)
  (if (and (setq osm (getvar 'OSMODE))
           (setvar 'OSMODE 512)
           (setq pt (getpoint "\nSelect a Dynamic Block to tag: "))
           (setvar 'OSMODE osm)
           (setq ss (ssget pt '((0 . "INSERT"))))
           (setq obj (vlax-ename->vla-object (ssname ss 0)))
           (vlax-property-available-p obj 'IsDynamicBlock)
           (eq (vla-get-IsDynamicBlock obj) :vlax-true)
           (setq pt1 (getpoint pt "\nPosition of Dynamic Block tag:"))
      )
    (progn
      (setq lst (cons (list "Layer: " (vla-get-Layer obj)) lst)
            lst (cons (list "Name: " (vla-get-EffectiveName obj)) lst)
      )
      (foreach p (vlax-safearray->list
                   (vlax-variant-value (vla-getdynamicblockproperties obj))
                 )
        (if (and (/= (setq a (vlax-get p 'PropertyName)) "Origin")
                 (setq b (vlax-get p 'Value))
            )
          (setq lst (cons (list (strcat a ": ") (vl-princ-to-string b)) lst))
        )
      )
      (if (and (vlax-property-available-p obj 'Hasattributes)
               (eq :vlax-true (vla-get-hasattributes obj))
          )
        (progn
          (setq atts (vlax-invoke obj 'Getattributes))
          (foreach att atts
            (setq lst
                   (cons (list (strcat (vla-get-tagstring att) ": ")
                               (vla-get-textstring att)
                         )
                         lst
                   )
            )
          )
        )
      )
      (setq str (vl-string-right-trim
                  "\\P"
                  (apply 'strcat
                         (mapcar (function (lambda (x) (strcat (car x) (cadr x) "\\P")))
                                 (reverse lst)
                         )
                  )
                )
      )
      (command "_.mleader" "_NONE" pt "_NONE" pt1 str)
    )
    (prompt "\nNot a Dynamic Block!")
  )
  (princ)
)

 

Hope that helps

Henrique

EESignature

Message 3 of 6
JCprog
in reply to: hmsilva

Hello Henrique,

 

This works awesome! but for some reason it seems like its cutting short when it comes to the attributes.

Its printing fine for the first 7 lines (I'm getting 2 Properties and 5 parameters and after that it cuts off) whereas the block has 5 more attributes

 

Layer: layer1
Name: blk01
Visibility: wide
LEADER DISTANCE: 7.08473
LEADER ANGLE: 0.0
Flip state1: 0
Flip state2: 0
de

 

*the de at the last line suppose to description

Message 4 of 6
hmsilva
in reply to: JCprog

Hi JCprog,

 

AutoLISP as a restriction on a string  length, 132 characters...

 

I dont have AutoCAD in this laptop, but should work as expected, change

 

(command "_.mleader" "_NONE" pt "_NONE" pt1 str)

 

to

 

(command "_.mleader" "_NONE" pt "_NONE" pt1 "")
(setq obj (vlax-ename->vla-object (entlast)))
(vla-put-textstring obj str)

 

HTH

Henrique

EESignature

Message 5 of 6
JCprog
in reply to: hmsilva

Yup! that definitely did the trick!

 

That is just brilliant! Thanks for your help Henrique Smiley Very Happy

Message 6 of 6
hmsilva
in reply to: JCprog

You're welcome, JCprog.
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost