ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Nested BlockReference with Attributes

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
christineweiss86
716 Views, 3 Replies

Nested BlockReference with Attributes

Hello,

 

i have the following issue. I created a block. Every instance of this block has a set of data, that is to big for using XData so i decided to make a custom Entity. First I tried extending AcDbBlockReference but since my block has an attribute I had to learn that I can't append attributes to a class deriving from AcDbBlockReference. So my next try was to nest a AcDbBlockReference in a Class deriving from AcDbEntity (I am calling the worldDraw of my nested BlockReference inside of my subworlddraw to draw it). That worked fine until I tried to change the appearance of the attribute.

 

What I need to do is depending of the angle (rotation) that I am inserting the block with, I need to rotate the attribute. I managed to do that by setting the alignmentPoint to the PositionPoint, chaning the alignment to topright instead of bottomleft and setting the rotation of the TextAttribute to 180 degrees more than the rotation of the inserted block.

 

That works fine when I am adding just the BlockReference I created to the ModelSpace. But when I try to add my custom object to the ModelSpace, that has the BlockReference nested inside of it, it does'nt work anymore. The rotation of the attribute is updated but not the alignment and changes to the alignementPoint. 

 

I think I may be missing a method override of BlockReference for my custom class, but I can't figure out what it could be. Maybe one of you have already had a simular problem and can help me?

 

I also tried to extend AcDbBlockReference instead of AcDbEntity and still nest my BlockReference Object inside of this class to support the attributes. And when I am setting the nested BlockReference pointer I tried to set the important values to the deriving class like so:

 

void setBlockRef(AcDbBlockReference * pBlockRef) {
  m_pBlockRef = pBlockRef;
  setRotation(m_pBlockRef->rotation());
  setBlockTableRecord(m_pBlockRef->blockTableRecord());
  setBlockTransform(m_pBlockRef->blockTransform());
  setNormal(m_pBlockRef->normal());
  setPosition(m_pBlockRef->position());
}

 

But it still doesn't work.

 

I'm using Visual Studio 2012, AutoCAD 2016, ObjectARX 2016, Windows 7 64bit.

3 REPLIES 3
Message 2 of 4

Try to call transformBy() to your block reference, this will also transform the attribute.
Message 3 of 4

Thank you for your reply bernd.

Unfortunately this doesn't work for me because I just want the attribute text to be changed while the blockreference stays as it is.

Also the rotation of the attribute is working fine but so isn't the alignment and the changes to the alignmentPoint.

 

I attached a picture to make this clear.

1 is what I got

2 is what I want (and get using the AcDbBlockReference)

3 is what I get when using my custom entity

Message 4 of 4

Hello again.

 

I tried googleing for the 100th time and this time I managed to find the solution to my problem on the site below:

 

http://adndevblog.typepad.com/autocad/2012/06/updating-text-alignment-.html

 

You need to call the following method on your AcDbAttribute object (or your TextObject if you have the problem with this one) before inserting it to the database.

 

adjustAlignment(acdbHostApplicationServices()->workingDatabase());

Or with any other database that you want to add your text to.

That worked for me and finally the Alignment change is shown corretly in my dwg.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost