Jump to content

Set Position of AttributeReference


Boortsneggor

Recommended Posts

Hi there,

I´m developing a little interface for AUTCOCAD at the moment. I use Visual Studio 2010 and ObjectARX 2012 with C#. The interface should be able to edit specific blockReferences and their attributes. I´ve got two special kinds of blocks which I want to edit. Now I´ve implemented a command to move the position of one kind of the block references`attributes. For one of my two blocks this command works very well. For the other ones I cannot set a new position of the attribute references. And I don´t know why! I´ve compared several properties of the attributes but they are the same for both kind of blocks. The "lockposition" for example is "false" for both. Which property of the attribute references, block references or block should I set to change the position of the attribute references. Curiously to change the height or width of the text attributes makes no problems for both kind of blocks. So what could it be?? Or is there a simple way to set all properties of one block also to another one??

 

Thanks for help!!!

 

greets robert

Link to comment
Share on other sites

Hello fixo,

 

first of all, happy new year! Thanks for your answer. Unfortunately after setting the properties you mentioned the positions still remain the same. Do you have another ideas which can be the reason for this??

 

greets robert

Link to comment
Share on other sites

Thanks Robert,

Happy New Year too :)

Unfortunatelly I can't 2010 release on my machine

Just an idea, sorry, perhaps in the block table record this attribute properties:

Lock position was set to true?

 

Best wishes,

 

Oleg

Link to comment
Share on other sites

Hallo Oleg,

 

I came through with small steps. I've find out, that it works, when I sync the BlockReferences with the origin block.

Now I`ve the problem, that the visible Attributes also get all the Textproperties like Textheight, width and so on... of the origin Block. But the Textproperties of the visible Attributes of every BlockReference need to remain the same independent from the origin Block.

Do you have an idea to realize that??

 

greets robert

Link to comment
Share on other sites

Hi Robert, I could not generate the same issue on my machine

I've used this simple code written years ago:

 
      public void ApplyAttributes(Database db, Transaction tr, BlockReference bref)
       {
           BlockTableRecord btrec = tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
           if (btrec.HasAttributeDefinitions)
           {
               Autodesk.AutoCAD.DatabaseServices.AttributeCollection atcoll = bref.AttributeCollection;
               foreach (ObjectId subid in btrec)
               {
                   Entity ent = (Entity)subid.GetObject(OpenMode.ForRead);
                   AttributeDefinition attDef = ent as AttributeDefinition;
                   if (attDef != null)
                   {
                       AttributeReference attRef = new AttributeReference();
                       attRef.SetDatabaseDefaults();// optional or wrong maybe
                       attRef.SetAttributeFromBlock(attDef, bref.BlockTransform);
                       attRef.Position = attDef.Position.TransformBy(bref.BlockTransform);
                       attRef.Tag = attDef.Tag;
                      // you may want to swap other properties
                      // between AttributeDefinition and AttributeReference here
                       attRef.AdjustAlignment(db);
                       atcoll.AppendAttribute(attRef);
                       tr.AddNewlyCreatedDBObject(attRef, true);
                   }
               }
           }
       }

 

Try it too, perhaps it will be working for you, who knows?

Or stay arriving of the heavy artillery :)

Link to comment
Share on other sites

Hi Oleg,

 

could you please explain your code a little bit. When I integrate the method I `ve got the little problem, that all blockReferences has their Attributes twice times. So I have to delete the old ones but store the values to set them to the new ones.

 

But as I say on parts I don´t know exactly what your method did.

 

Thanks for help!

 

greets robert

Link to comment
Share on other sites

Hi Oleg,

 

it´s me again and I´ve solved the problem. The difference between the blocks were the alignment of the text attributes. If they have the default-LEFT-alingment you can simply use the "Position" property to move them. If they have other alignment in my case right, you have to set the "AlingmentPoint" property of the attribute references.

So now my method works fine for all blocks and I´m very happy!8)

 

Again thanks for your help and have a good time!

 

greets robert

Link to comment
Share on other sites

Hi Oleg,

 

it´s me again and I´ve solved the problem. The difference between the blocks were the alignment of the text attributes. If they have the default-LEFT-alingment you can simply use the "Position" property to move them. If they have other alignment in my case right, you have to set the "AlingmentPoint" property of the attribute references.

So now my method works fine for all blocks and I´m very happy!8)

 

Again thanks for your help and have a good time!

 

greets robert

Hi Robert,

Glad you've solved it by yorself

Sorry for the belating,

and yes, it's right way to set all properties

for attribute references by its parent attribute definition

one by one

I was lazy to write them all separately :)

Cheers, mate :)

 

Oleg

Edited by fixo
spell check
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...