Block Name to Multileader User Block Attribute

Block Name to Multileader User Block Attribute

krkeene
Enthusiast Enthusiast
519 Views
8 Replies
Message 1 of 9

Block Name to Multileader User Block Attribute

krkeene
Enthusiast
Enthusiast

I've recently found a LSP (BNameLable.lsp) on the forums that will grab the name of a block, the start the Multileader command and place the block name in the Multileader MText.  I've modified it a bit so that I switch into a view port, select the block, then switch back to Paper Space to place the Multileader.  This works great, but I'd like to figure out if the block name value can be inserted into an attribute of a Multileader User Defined Block.  I have a Block-Type Multileader defined, but with that style active when I use this LSP file, it opens the Attribute Dialog box, and breaks the rest of the lisp routine.  I'm new to LISP programming and haven't been able to figure out how to pass the block name into the Multileader Block attribute.  The Block Name is "Part_Number" and the attribute tag is also "Part_Number".   I'd really appreciate any suggestions, you might have.  

0 Likes
Accepted solutions (1)
520 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

maybe try setting ATTDIA to 0 and then run your command?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

krkeene
Enthusiast
Enthusiast

Thanks Paul.  I should have mentioned that I tried that, but get this error message:  " error: Automation Error. Description was not provided.".   It places the block, without the dialog, but it places an empty block and gives the error message above.  So the block name value isn't getting passed to the block attribute.  

0 Likes
Message 4 of 9

paullimapa
Mentor
Mentor

Since the Attribute is inside the Block, you'll have to dive deeper before you can use the vla-put-textring

so I would try replacing this section:

(vla-put-textstring
(vlax-ename->vla-object entl)
(vlax-get-property
(setq obj (vlax-ename->vla-object ent))
(if (vlax-property-available-p obj 'EffectiveName)
'EffectiveName
'Name
)
)
)

with this:

   (foreach attribute (vlax-invoke (vlax-ename->vla-object entl) 'getAttributes)
    (vla-put-textstring
     attribute
     (vlax-get-property
       (setq obj (vlax-ename->vla-object ent))
       (if (vlax-property-available-p obj 'EffectiveName)
        'EffectiveName
        'Name
       ) ; if
     ) ; get block name text
    ) ; put block name text
   ) ; foreach

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 9

krkeene
Enthusiast
Enthusiast
Do I need to put the attribute tag name or anything in the code? This is what I get: error: ActiveX Server returned the error: unknown name: "GETATTRIBUTES". It still places an empty block.

I wonder if it has to do with this being a Multi-leader not a "normal" block.
0 Likes
Message 6 of 9

paullimapa
Mentor
Mentor

That could be the problem since the block is embedded into the mleader. Perhaps share your block here so we can check what the block is made of 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 9

paullimapa
Mentor
Mentor
Accepted solution

ok, the following revisions to your original code just simplifies everything:

; BlockLabel inserts mleader in pspace using selected block name as attribute value
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-name-to-multileader-user-block-attribute/m-p/12072574#M450763
(defun c:BlockLabel (/ attdia cmdecho ent entl nam obj)
(vl-load-com)
; save current settings
(setq attdia (getvar"attdia") cmdecho (getvar"cmdecho"))
; change settings
(setvar "cmdecho" 0)
(setvar "attdia" 0)
(command "_.Mspace")
(cond 
  ((not (setq ent (car (entsel "\nSelect block: ")))))
  ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid object!"))
  (progn 
   (setq obj (vlax-ename->vla-object ent)) ; convert entity to object
   (setq nam 
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    ) 
   )
   (command "_.Pspace") 
   (setq pt (getpoint "\nSpecify first point: "))
   (vl-cmdf "_.mleader" "_non" pt pause nam)
  )
 ) ; cond
; restore settings
(setvar "attdia" attdia)  
(setvar "cmdecho" cmdecho)
(princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 9

krkeene
Enthusiast
Enthusiast
Perfect. Thanks for you effort on this Paul.
0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

sure, glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes