PDA

View Full Version : Edit Mtext Attribute in Block using LISP



Adam Junior
2021-04-20, 07:34 PM
Is there an AutoLISP function that works similar to ATTIPEDIT, or like pressing Ctrl and double clicking a Mtext Attribute in a Block? I’m wanting to pass it two arguments like EntityName and TagName. It would work similar to press the [...] button in the Enhanced Attribute Editor, but it would be used for custom AutoLISP programs. For starters I use: (setq EntityName (car (entsel))), and there are also several other ways to get it. The first part of the function might look like this.
(defun MtextFunction (EntityName "TAGNAME") :roll: The real one of course.
Thanks,
Adam

BIG-AL
2021-04-21, 12:34 AM
Have you looked into NENTSEL that allows direct access to a attribute. You can entmod or put-textstring dont need tagname.

(entget (car (nentsel "\pick a attribute ")))

Adam Junior
2021-04-21, 02:14 PM
I’m looking for an AutoLISP function that is run after a Dialog closes when the user picks a button like [...] to edit the Mtext Attribute in the block, which may have more than one Attribute. For example the Dialog may have prompts for Part Number, Quantity and Installation Notes. Right now I’m telling the users to press Ctrl and double click on the "INSTALLATION_NOTES" Mtext in the block. This works, but I would like a better way of doing it similar to the [...] button function in the Enhanced Attribute Editor so the user doesn't have to pick anything in the block.
Thanks.

BIG-AL
2021-04-22, 12:11 AM
In simplest terms 2 ways use a attribute tag name or use the attribute order. An example using tagname.



(foreach att (vlax-invoke (vlax-ename->vla-object blockobj) 'getattributes)
(if (= tagname (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr)
) ; end if

Adam Junior
2021-04-22, 06:52 PM
Hi Big-AL. Thanks for the code, but I couldn't get it to load. Something to do with malformed list on input, and AutoLISP file doesn't have matching parentheses.

BIG-AL
2021-04-23, 07:01 AM
It is an example of the bit of the code you would use in your code to change a attribute string value. There is more code wrapped around it. Like select a entity Blockobj and tagname the latter would be "INSTALLATION_NOTES"




(setq newstr (getstring "\nEnter new string "))
(setq blockobj (vlax-ename->vla-object (car (entsel "Pick block"))))
(foreach att (vlax-invoke (vlax-ename->vla-object blockobj) 'getattributes)
(if (= "INSTALLATION_NOTES" (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr)
)
)

It should also do a error check does Block have attributes.

Adam Junior
2021-04-23, 02:10 PM
Is there a way using AutoLISP to open the "MTEXT Editor" to edit a Mtext Attribute in a Block?
I’m thinking you would only need the blocks EntityName and "TAGNAME" in an AutoLISP function.

Tom Beauford
2021-04-23, 03:42 PM
This attached lisp may help:
A replacement function for -attedit that uses dialog boxes instead of the command line for changing attribute or text Value, Position, Height, Width, Rotation, Style, Layer ,Color or Case. There are also options to draw a box around the text as well as one to Undo each modification one at a time. Modify Attribute Definitions, Mtext, Text or Dimension Objects as well.
(load "Atted") Atted

Adam Junior
2021-04-23, 04:56 PM
Tom, I’m looking into your code for Atted.lsp and it is impressive to say the least. It will take me some time to study it all and figure out what I need here. I appreciate it. Thanks.