Hi,
I have a simple block with 2 attribute and 1 line inside it.
something like this:
Attribute1
──────
Attribute2
I want to modify length of line due to width of thoes attributs. length of line is equal to
maximum(width attribute1 and width attribute2).
dxf code for start point of a line is 10 and end point for a line entity is 11.
The question is: how can I modify the length of line automatically via maximum width of these attributes?
for getting width of a text:
(defun GetWidth ( en ) ((lambda ( lst ) (- (caadr lst) (caar lst))) (textbox en)))
sample:
A1
──────
Attribute2
Attribute1
──────
A2
please see the attached for a sample dwg.
Thanks for any help/guide.
Abbas
Solved! Go to Solution.
Solved by alanjt_. Go to Solution.
It can be done by modifying the the line entity within the block definition, but this I am sure is not what you want, because EVERY single insert of this block will then then change to the one linewidth. There are 2 ways you can do it, you can write a routine that will basically take the block and create a new unique block with the line length you want, thus every insert would be its own block. Or you can use a dynamic block. with the dynamic block, the block will be the same name and every insert entitiy of the block you can manullly stretch the line to the legnth desired OR you can entmod the insert entitiy of the dynamic block and to do it via a lisp routine. I have succesfully done this in many routines. The only issue you will have is cycling through the enitites of the block insert definition, I have a question pending in this forum that has no replies yet about that. If you only have one line in the block, it is easy, one you hit a "line" entity while cycling through the definition, you stop, entmod the line entity, done.
Cheers
The issue here is, if you change the length of the line in the block definition, it will change all instance of that block.
I forgot to add that when you modify the dynamic block insert entity, you do not modify the line entity within the block, you modify the lookup pararmeter that stretches the line. In order to do this you MUST download a small function some genius Russian wrote that you add to your code that will retrieve AND modify the parameter you specified. Its called DynamicProps.
When there is a will there is a way.
I was told you cannot get rid of the dialogue box when you do building/section elevate, many many posts over the years, you cant do it, some guy tried to use visual basic to control the dialogue box, I did it with simple lisp.
Oh ok, you already have a stretch parameter set for the line within a dynamic block with attributes. I didn't open the block to check. Yes, what you want is very possible.
I'll open the block i the morning and see what I can do.
Whose thread is this aqdam1978 or royboy666?
Its certainly doable with a stretch parameter . But All i can see on the attached file is the attribute block. no DB's
This is aqdam1978's thread. He wants to adjust the width of a line within a block automatically using code. We stated it can't be done with a regular block which he attached, I suggested using a dynamic block and do it manully for each insert OR I stated it is possible to do it using lisp, by updating the stretch parameter within the anonymous block to stretch the line where you want it.
Give this a whirl. I updated your block to be a dynamic block with a stretch parameter on the middle line.
(defun c:Test (/ *error* _textWidth ss i o v) (vl-load-com) (defun *error* (msg) (and *AcadDoc* (vla-endundomark *AcadDoc*)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (progn (vl-bt) (princ (strcat "\nError: " msg))) ) ) (defun _textWidth (en) ((lambda (lst) (- (caadr lst) (caar lst))) (textbox en)) ) (vla-startundomark (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) (if (setq ss (ssget "_:L" '((0 . "INSERT") (2 . "`*U*,LABELTAG")))) (repeat (setq i (sslength ss)) (if (eq (if (vlax-property-available-p (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i))))) 'EffectiveName ) (vla-get-effectivename o) (vla-get-name o) ) "LabelTag" ) (progn (setq v (+ (apply 'max (mapcar (function (lambda (a) (_textWidth (entget (vlax-vla-object->ename a))))) (vlax-invoke o 'GetAttributes) ) ) (* (if (vlax-property-available-p o 'XEffectiveScaleFactor) (vla-get-XEffectiveScaleFactor o) (vla-get-XScaleFactor o) ) 0.35 ) ) ) (vl-some (function (lambda (obj) (if (eq (vla-get-propertyname obj) "Distance1") (progn (vla-put-value obj l) T) ) ) ) (vlax-invoke o 'GetDynamicBlockProperties) ) ) ) ) ) (*error* nil) (princ) )
Arg, stupid typo. I can't believe you are unable to edit a post. That's just stupid.
Thanks for catching it, pbejse.
(defun c:Test (/ *error* _textWidth ss i o v) (vl-load-com) (defun *error* (msg) (and *AcadDoc* (vla-endundomark *AcadDoc*)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (progn (vl-bt) (princ (strcat "\nError: " msg))) ) ) (defun _textWidth (en) ((lambda (lst) (- (caadr lst) (caar lst))) (textbox en)) ) (vla-startundomark (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) ) ) (if (setq ss (ssget "_:L" '((0 . "INSERT") (2 . "`*U*,LABELTAG")))) (repeat (setq i (sslength ss)) (if (eq (if (vlax-property-available-p (setq o (vlax-ename->vla-object (ssname ss (setq i (1- i))))) 'EffectiveName ) (vla-get-effectivename o) (vla-get-name o) ) "LabelTag" ) (progn (setq v (+ (apply 'max (mapcar (function (lambda (a) (_textWidth (entget (vlax-vla-object->ename a))))) (vlax-invoke o 'GetAttributes) ) ) (* (if (vlax-property-available-p o 'XEffectiveScaleFactor) (vla-get-XEffectiveScaleFactor o) (vla-get-XScaleFactor o) ) 0.35 ) ) ) (vl-some (function (lambda (obj) (if (eq (vla-get-propertyname obj) "Distance1") (progn (vla-put-value obj v) T) ) ) ) (vlax-invoke o 'GetDynamicBlockProperties) ) ) ) ) ) (*error* nil) (princ) )
Hi alanjt_,
Thank you for your help.
I downloaded your attached drawing (LabelTag.dwg 81 KB) and I found out you exploded my LabelTag BLOCK.
so, how can I apply your lisp to this exploded block?!
and I have a favour: May you explain me about Dynamic Blocks? I don't know anything about DBs!
How I can make a DB?
Thank you so much for your time and consideration.
Abbas
I didn't explode the block, I WBlocked it out of the drawing for easy posting. Just insert it into a drawing, rather than just opening it.
Dynamic blocks are very useful and afford the user many abilities to stetch, array, flip, use multiple visibilities, etc. Look through your tool palettes and you should find a few (will have an additiona lightening bolt icon on them).
Hi alanjt_,
Thanks for your help.
you define a dynamic block with three parameter:
one linear parameter: Distance1
two stretch action: Stretch2 and Stretch3
as you know I dont know anything about dynamic blocks.
Can you explain me about this three item? what they do exactly?
Thanks,
Abbas