vla-put-textstring changes alignment/insertion point of attritte text... help!

vla-put-textstring changes alignment/insertion point of attritte text... help!

Anonymous
Not applicable
7,839 Views
20 Replies
Message 1 of 21

vla-put-textstring changes alignment/insertion point of attritte text... help!

Anonymous
Not applicable

I am using the (vla-put-textstring obj val).

I am noticing that this is have unintended affects besides just updating the text.

Actually it is NOT changing the insertion point automatically based on the text it is given as input.

 

Before command:

before_change.PNG

 

 

After running vla-put-textstring on this object:

after_change.PNG

 

The entity data is a little weird:

Initial value of attribute:
((-1 . <Entity name: 7ffffb22cb0>)
  (0 . "ATTRIB")
  (330 . <Entity name: 7ffffb22ca0>)
  (5 . "4843")
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "DESC")
  (100 . "AcDbText")
  (10 2.25534 19.875 0.0)
  (40 . 0.125)
  (1 . "WRONG TEXT")
  (50 . 0.0)
  (41 . 0.7)
  (51 . 0.0)
  (7 . "WD")
  (71 . 0)
  (72 . 2)
  (11 3.0 19.875 0.0)
  (210 0.0 0.0 1.0)
  (100 . "AcDbAttribute")
  (280 . 0)
  (2 . "DESC1")
  (70 . 0)
  (73 . 0)
  (74 . 0)
  (280 . 0)
)

After running command:
((-1 . <Entity name: 7ffffb22cb0>)
  (0 . "ATTRIB")
  (330 . <Entity name: 7ffffb22ca0>)
  (5 . "4843")
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "DESC")
  (100 . "AcDbText")
  (10 2.25534 19.875 0.0)
  (40 . 0.125)
  (1 . "TEST 1")
  (50 . 0.0)
  (41 . 0.7)
  (51 . 0.0)
  (7 . "WD")
  (71 . 0)
  (72 . 2)
  (11 3.0 19.875 0.0)
  (210 0.0 0.0 1.0)
  (100 . "AcDbAttribute")
  (280 . 0)
  (2 . "DESC1")
  (70 . 0)
  (73 . 0)
  (74 . 0)
  (280 . 0)
)

 

This is an autocad electrical dwg, "edit component" is a built in command. My point being that the dxf 10 code never changes when I use the entmod method of changing this attribute text, but of course, I need to use active-x to do this change.

After edit component:
((-1 . <Entity name: 7ffffb22cb0>)
  (0 . "ATTRIB")
  (330 . <Entity name: 7ffffb22ca0>)
  (5 . "4843")
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "DESC")
  (100 . "AcDbText")
  (10 2.62156 19.875 0.0)
  (40 . 0.125)
  (1 . "TEST 1")
  (50 . 0.0)
  (41 . 0.7)
  (51 . 0.0)
  (7 . "WD")
  (71 . 0)
  (72 . 2)
  (11 3.0 19.875 0.0)
  (210 0.0 0.0 1.0)
  (100 . "AcDbAttribute")
  (280 . 0)
  (2 . "DESC1")
  (70 . 0)
  (73 . 0)
  (74 . 0)
  (280 . 0)
)

 

 

I am having a hard time figure out exactly what is happening here.

0 Likes
7,840 Views
20 Replies
Replies (20)
Message 2 of 21

devitg
Advisor
Advisor

Acording with the aligment property , you have to handle insertionpoint , and textaligmentpoint property

 

 

(SETQ ALIG (VLA-GET-ALIGNMENT TEXT-OBJ))
    (SETQ INS-PT (VLA-GET-INSERTIONPOINT TEXT-OBJ))
    (SETQ ALIG-PT (VLA-GET-TEXTALIGNMENTPOINT TEXT-OBJ))


your stuff


(VLA-PUT-ALIGNMENT TEXT-OBJ ALIG)
    (VLA-PUT-INSERTIONPOINT TEXT-OBJ INS-PT)
    (if (not (= alig 0))(VLA-PUT-TEXTALIGNMENTPOINT TEXT-OBJ ALIG-PT))
    )

See vlide help for further info 
0 Likes
Message 3 of 21

devitg
Advisor
Advisor

From the VLIDE help 

 

 

 

Text aligned to acAlignmentLeft uses the InsertionPoint property to position the text.

Text aligned to acAlignmentAligned, or acAlignmentFit uses both the InsertionPoint and TextAlignmentPoint properties to position the text.

Text aligned to any other position uses the TextAlignmentPoint property to position the text.

0 Likes
Message 4 of 21

dbroad
Mentor
Mentor

You are misinterpreting the results of your experiment.  Vla-put-textstring has no effect on alignment.  What you have failed to understand is that the alignment coding for attributes is not the same as for text.  Text uses 72 code.  Attributes use 71 code.  Your attribute alignment is coded left aligned, which is what the results demonstrate.  Nothing more.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 21

Anonymous
Not applicable

Maybe I should restate the actual issue.

 

for right aligned text:

When the text is "wrong text" that yeilds a given inserrtion point.

When the text is "test 1" that yeilds yet another insertion point.

The text alignment point is the same for both.

 

 

When I change the text with a (subst (cons X1 . X1) (cons X1 . X2)) (and of course entmod) the insertion point for the text is automatically generated such that the text remains right aligned correctly.

 

When I put the text string with active-x, and change nothing else, the old insertion point is now not correct for the new text.

 

So I guess I am asking if anyone knows of a way to make the active-x mode of doing this automatically set this value for  me.

 

 

0 Likes
Message 6 of 21

Anonymous
Not applicable

that's the problem... the new text if shorter, or longer, now needs a different insertion piont... the old one no longer is valid for the new text.

0 Likes
Message 7 of 21

dbroad
Mentor
Mentor

Read my post again carefully.  There is no problem with vla-put-textstring.  Your attribute is defined left aligned.  Redefine the block and use battman or attsync to update the insertions.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 21

Anonymous
Not applicable

Dbroad,
I did read it and checked the dxf codes... 71 is text generation flags (or attachment point), 72 is horizontal justification, (or drawing direction). The attribute IS aligned right, I have been checking it. It's the insertion point.


From DXF codes:
If group 72 and/or 74 values are nonzero then the text insertion point values are ignored, and new values are calculated by AutoCAD based on the text alignment point and the length of the text string itself (after applying the text style). If the 72 and 74 values are zero or missing, then the text alignment point is ignored and recalculated based on the text insertion point and the length of the text string itself (after applying the text style).

this has something to do with it...

 

My issue is that when I put the new text string on it, it keeps the original insertion point, and textalignmentpoint, the orignal insertion point is no longer valid for the shorter length text.

 

When I change the acalignment from acalignmentright (numerical value of 2 in vlax-dump-object) to acalignmentleft (value 0), via the console window it is resetting the insertion point to 0,0,0. I can then put it back to acalignmentright, reput the old textalignmentpoint and it automatically resets the insertion point based on the new text length... but only when I do it from the console window.... not in my program.

 

I'll try vla-update and the attribute and the block and see if that resets it.

0 Likes
Message 9 of 21

dbroad
Mentor
Mentor

You are listing DXF codes for text, NOT FOR ATTRIBUTES.  Read the DXF codes for attributes or just edit the block in bedit and fix the attribute alignment without needing to know the dxf codes.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 10 of 21

Anonymous
Not applicable

Dbroad,

Maybe this will help....

 

Before I run my code:

before2.PNG

 

Aligned right....

 

After my function runs using vla-put-textstring, notice the insertion point is the same for this new text which is shorter than old text:

after2.PNG

 

 

It should be:

after2a.PNG

 

My problem is getting active-x methods to do this automatically.

I have tried changing the alignment from right to left (this should reset the insertion point to 0,0,0), , then back to right and then reput the old text alignmentpoint back on it (it should refigure the insertion point), but it then leaves the insertion point at 0,0,0 it doesn't update it based on the length of the new text.

 

I have tried vla-update attribute object, and vla-update blockobject. This has no affect.

 

Here's my code:

(defun vla_set_attribute_value	(blk tag val)
  (setq tag (strcase tag))
  (vl-some (function (lambda (att)
	      (if (= tag (strcase (vla-get-tagstring att)))
		(progn
		  (setq txta_pt (vlax-variant-value (vla-get-textalignmentPoint att)))
		  (vla-put-textstring att val)
		  (vla-put-alignment att acalignmentleft);| maybe try a regen after this?|;
		  (vla-update att)
		  (vla-update blk)
;;;		  (vla-put-InsertionPoint att (vlax-3d-point 0 0 0));it is not changing the insertion point so I will set it to zero so it can refigure it, without this  is remembers the insertion point from before.
		  (vla-put-alignment att acalignmentright);| maybe try a regen after this?|;
		  (vla-put-textalignmentpoint att txta_pt);| maybe try a regen after this?|;
		  val);end progn
		);end if
	      ));end function lambda
	   (vlax-invoke blk 'getattributes)
;;;	   (vlax-variant-value (vla-getattributes blk));<--this doesn't seem to work vla-getattributes cuases ; error: bad argument type: listp #<variant 8201 ...>, the vlax-variant-value causes: ; error: bad argument type: listp #<safearray...>
	   );end vl-some
  );end defun

 

This code based on code from Lee Mac (not sure its a copywrite thing... there are very few ways to do this).

Sorry for the comments, I have been trying like heck to try different things...

 

 

 

 

0 Likes
Message 11 of 21

Anonymous
Not applicable

Dbroad,

not sure I can do bedit in a drawing that is not the drawing the LISP started in... I tried the old school (subst (cons x . x) (cons x.x)) (entmod ent) but that did very strange things....in the current drawing, not the target drawing.... because I am accessing another open drawing than the one I am executing code in I have to use active-x methods, or so I seem to be reading in all the forums.

0 Likes
Message 12 of 21

Anonymous
Not applicable

Dbroad:

in reply to:

You are listing DXF codes for text, NOT FOR ATTRIBUTES.  Read the DXF codes for attributes or just edit the block in bedit and fix the attribute alignment without needing to know the dxf codes.

 

The dxf codes I am posting are from an (entget (car (nentselp))) on the actual attribute entity.

Active-x apparently treats an attribute, in model space, like a peice of text.

 

0 Likes
Message 13 of 21

Anonymous
Not applicable

Battman has no command line functionality, window only. Since my vlisp code isn't running that window, I can't access it.

ATTSYNC has the affect of resetting all attribute layers to 0, an undesired affect. It does, however, set the insertion point of the text correctly again.

 

 

So I don't think either of those are going to help me much.

 

0 Likes
Message 14 of 21

Anonymous
Not applicable

probably been given just enough rope...

 

This is my first dive into active-x via vlisp so I don't know all the limitations yet.

 

I am using active-x to access an open drawing that is not the drawing my lisp code is running in.

 

Apparently, in this situation, the vla-put-textstring function will not automatically reset the insertion point of the text based on the change in the text length as it would if issued from the active drawing.

 

Unless there is some guru mojo that can be applied?

 

 

0 Likes
Message 15 of 21

dbroad
Mentor
Mentor

I dont' know what is going on with your program.  It should work correctly. It works fine here although you have extra stuff like changing the insertion point and refreshing the item that shouldn't be necessary.  I am attaching a small drawing with a test block with 2 attributes.  Load and use the test command defined below, pick an attribute and watch the results.

 

(defun c:test ( / nt)
  (setq nt (getstring "\nEnter new text: "))
  (prompt "\nPick attribute: ") ;pick the attribute at the block reference
  (vla-put-textstring
    (vlax-ename->vla-object
      (car
	(nentsel)))
    nt)
  (princ)
  )

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 16 of 21

Anonymous
Not applicable

Dbroad,

I am using vla-put-textstring on *another* open document than the one my vlisp code is running in.

I am aware that vlisp has limitaoins with the MDE (multidocument environment), it's just hard to know exactly what the limitations are for a given command. Vla-put-text string will put the text, it doesn't seem to autoset the insertion point in an open but nonactive drawing.. It does autoset it if you issue the command from the active drawing.

 

I'm gonna have to force the user to (save then) close all the open project drawings now and then try ObjectDBX, if that also fails to autoset the insertionpoint then I'll have to just implement scripting. That or learn VBA.

I was hoping to not have to close any open drawings as I have users that like to have multiple unsaved documents open, not a huge thing but I just wanted my tool to be a bit more in the background.

 

Basically what I am trying to do is have the user pick some blocks (signal arrows) that they have recently changed the DESC1 attribute value on, then go find the matching blocks in the other project drawings and make their DESC1 attributes match the ones that were picked.

Autocad Electrical doesn't have a very easy way to make source/destination arrow descriptions match, especially if you have changed one of them after they have both been inserted. I am trying to make a tool that will do this.

 

 

 


@Anonymous wrote:

I dont' know what is going on with your program.  It should work correctly. It works fine here although you have extra stuff like changing the insertion point and refreshing the item that shouldn't be necessary.  I am attaching a small drawing with a test block with 2 attributes.  Load and use the test command defined below, pick an attribute and watch the results.

 

(defun c:test ( / nt)
  (setq nt (getstring "\nEnter new text: "))
  (prompt "\nPick attribute: ") ;pick the attribute at the block reference
  (vla-put-textstring
    (vlax-ename->vla-object
      (car
	(nentsel)))
    nt)
  (princ)
  )

 


 

0 Likes
Message 17 of 21

vladop
Collaborator
Collaborator

No solution yet?

I am using AutoCAD Electrical too.

The best solution I know is to use Project-Wide Utility in AutoCAD Electrical to execute following script in all the drawings I want to update:

_______________________________

move
all

0,0,0
0,0,0

 

_______________________________

 

I tried to "move all" in closed drawing but nothing happened. Drawings have to be opened.

 

Regards,

Vladimir

0 Likes
Message 18 of 21

dbroad
Mentor
Mentor

First, I apologize to @Anonymous and @devitg for making this thread more difficult than it needed to be. They were exactly right and were very patient with me despite my certainty. I was completely wrong.  The insertion point of the attribute should change when the textstring length changes but they don't. The horizontal DXF for attribs (72) are the same as for text. The vertical justification DXF for attributes are different than text (74 vs 73). DXF 71 is only related to ATTDEF's as a justification.

Second, I don't have access to AutoCAD Electrical so I can't test exactly what is happening.

Third, AutoLISP ActiveX is usually fine for the active document but absolutely horrible for other documents.  VBA generally works OK for any document open in the document collection. If there is a lot of need for this, downloading and testing a VBA version would be worthwhile.

It is possible that using ObjectDBX or AutoCAD core console might work but I don't have time to test.  It would probably require a vla-update on the affected attrib.  Using a script in the core console that used legacy methods might work with (entupd...). Just don't know. I do know that ObjectDBX will destroy the thumbnails, if that is important.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 19 of 21

john.uhden
Mentor
Mentor

Changing the textstring property of an attribute will not change its insertion point or alignment point.

It appears to me that the string got replaced with a bundle of spaces.

John F. Uhden

0 Likes
Message 20 of 21

dbroad
Mentor
Mentor

If the text alignment is not set to left (default), then changing the text string typically changes the insertion point (by internal processes) in my testing.  The alignment point stays constant.  If the text alignment is set to the default, then the alignment point is ignored and the insertion point stays constant.

Architect, Registered NC, VA, SC, & GA.
0 Likes