PDA

View Full Version : add new attribute to existing block


rklee
2008-06-19, 10:43 PM
I would like to add a fourth attribute to an existing block with 3 attributes. I have been trying to do this without redefining the block. As the display of the attribute matters I have moved the original last one down one space and created an attribute in mspace in it's original location. Now I need to add that attribute to the block definition and place the value. This is the section of code I have been working on and it is a work in progress. Any suggestions would be greatly appreciated. I have searched this forum and also a Google search for something that does this.

irneb
2008-06-20, 08:16 AM
Why don't you want to redefine? Just after redefining run ATTSYNC or BATTMAN to have the new Attribute placed in each insertion of the block. It will also reposition the ATTRIBs as per your Block Def.

rklee
2008-06-20, 04:56 PM
I am trying to learn the vlisp/vba functions and I have not been able to figure out the method equal of the old entmod and entupd. Any suggestions or point me in the right direction?

irneb
2008-06-23, 09:09 AM
After obtaining an ename of one of the blocks - you need to obtain the block definition's data 1st. (Whether using AutoLisp / VLisp). This you can do using the tblobjname function, e.g.:(setq en (entsel "Select block you wish to add Attribute to:")) ;Get ename of INSERT
(setq ed (entget (car en))) ;Get data of INSERT
(setq bn (tblobjname "BLOCK" (cdr (assoc 2 ed)))) ;Get ename of BLOCK definition
From here, I'd go with the vlax methods instead, since it makes creating new Attributes easier, as with the old entmake method you had to recreate the block. The vlax allows for simply adding an attribute, that is after changing the necessary data to VLA Variant types:(setq bo (vlax-ename->vla-object bn)) ;Get a reference to the BLOCK def's ActiveX object
(setq Height 0.18) ;Text height
(setq pt (vlax-3d-point '(3.0 3.0 0.0))) ;Fill array with ATTDEF's insertion point
....
(vla-AddAttribute bo Height .....)Though even after this you'd still need to update the existing INSERT entities to the new definition. Again that ATTSYNC / BATTMAN commands come into play.

The vla-AddAttribute function comes from the ActiveX AddAttribute method of a BLOCK object. This has the following parameters:
Object - the object reference it appliesto
Height - text height
Mode - Invisible / Constant / Verify ... etc.
Prompt - the prompt shown in the EATTEdit dialog
etc. etc. etc.I'd suggest following this procedure to figure out what to do when using VLAX: In the Developer Help (AutoCAD Menu --> Help --> Additional Resources --> Developer Help; or in the VLISP editor just press F1), browse to AutoLISP Developer's Guide / Using the Visual LISP Environment / Working with ActiveX. It shows all the general ideas behind using ActiveX, however it doesn't show all the required methods. For that you need to look at the ActiveX and VBA Reference section as well, you basically learn how the AutoCAD portion of VBA works. Then for any object's Methods you prefix vla- and add the object as the 1st parameter, for properties it's vla-get- (to retrieve the value) and vla-put- (to set the value).

In most instances data-types are handled automatically, but stuff like booleans and arrays need to be converted manually. For these (and some other usefull functions) I'd suggest also looking at AutoLISP Reference / AutoLISP Functions / V Functions - all the vlax functions (especially vlax-get-acad-object and those to do with safearray and variant). E.g. the BlockRef.GetAttributes returns a Variant Array of Attribute Reference objects.

You may also need to figure out how to handle collection objects, such as the object returned by BlockRef.GetDynamicBlockProperties method. Some examples are given in AutoLISP Developer's Guide / Using the Visual LISP Environment / Working with ActiveX / Working with Collection Objects.

rklee
2008-06-23, 02:13 PM
Thank you, I will be working on it this week, if work allows and let you know how I come out. The hardest part I have is translating the VBA into vlax or vla and having the correct order of procedure and parameters.

Thank you again.

peter
2008-06-24, 01:52 PM
I played with adding attributes to existing blocks before. This attsync2 function will replace the block, keep the old attributes exactly the way they were, and add any NEW linework and attributes to the block instance.

Hope it fills your needs,

Peter

rklee
2008-06-24, 04:46 PM
Thank you for the post. I have printed your routine and I want to look at it so that I can learn some more about object programming.

Thank you for your help, I have gotten the attributes added, just for some reason the insertion point has changed by a few hundred feet. Love the debugging.