11
AutoLISP (Vanilla / Visual) / Width of block multiline attribute
« Last post by Spainenins on April 17, 2024, 11:22:44 AM »Hello!
I have made a lisp routine that does the following:
1)adds a block reference to the model space;
2)changes the value (text string) of an attribute;
3)gets the real width (through bounding box) of the attribute;
4)changes a dynamic block property so that the width of the block reference fits the new text.
It works beautifully, when the attribute is a single-line one. But sadly my colleagues requested I make it a multi-line attribute, so they could use subscripts and superscripts in it.
The problem seems to be that Bounding box of a multi-line attribute is always as if it had it's default text string.
Maybe there is another way to get the width of a multi-line attribute?
Code below:
The block is a really simple one with one attribute called "NR", and one custom property called "Width".
EDIT (John): Fixed code tag.
I have made a lisp routine that does the following:
1)adds a block reference to the model space;
2)changes the value (text string) of an attribute;
3)gets the real width (through bounding box) of the attribute;
4)changes a dynamic block property so that the width of the block reference fits the new text.
It works beautifully, when the attribute is a single-line one. But sadly my colleagues requested I make it a multi-line attribute, so they could use subscripts and superscripts in it.
The problem seems to be that Bounding box of a multi-line attribute is always as if it had it's default text string.
Maybe there is another way to get the width of a multi-line attribute?
Code below:
Code - Auto/Visual Lisp: [Select]
- (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) ;get modelspace of active document
- (setq propname "Width") ;block property name that is supposed to change depending on width of the attribute
- ;;get the relevant attribute as vla-object
- (setq attrobj
- (car
- );vl-member-if
- );car
- );setq
- ;;get the relevant property as vla-object
- (setq propobj
- (car
- );vl-member-if
- );car
- );setq
- (vla-put-value propobj (+ 2.0 attrwidth)) ;change it's value
- );defun
The block is a really simple one with one attribute called "NR", and one custom property called "Width".
EDIT (John): Fixed code tag.