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

Unexpected behavior when editing/adding attributes to blocks.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
sweekly
1324 Views, 6 Replies

Unexpected behavior when editing/adding attributes to blocks.

Hello all.  I am seeing some unexpected behavior with a program I am creating.  I suspect that it's just my inexperience with AutoCAD's .NET API (and AutoCAD in general) but I want to verify and see if there is a solution.

 

What I am trying to do is provide a form/app to allow our users to add new titleblocks to a drawing and then update/increment the revisions in the titleblock.  We have a DWT (template) with our blocks and such that I copy into a new layout when the user creates a new titleblock with the app.  But, when trying to add new revisions - when a user adds a rev the attributes they add are copied to EVERY blockreference of the Revision Block.  I suspect that I am just confused at to how this works but when I use ArxDBG to snoop the database and look I can see that I have several blockreferences in the DB and when I debug I am getting all of my BlockReferences. 

 

Note that all of the blocks are dynamic - I have a single Titleblock block, a single RevisionBlock block, and then copies of the RevisionBlock based on the size of the drawing.  The titleblock has several ViewStates and the RevisionBlock has a couple of ViewStates as well.  I have attached a screenshot and some code.  Any help here would be greatly appreciated.

6 REPLIES 6
Message 2 of 7
sweekly
in reply to: sweekly

More information:  what I belive I have is a case of having several anonymous blocks in the drawing that are pointing at the original block.  So - when inserting my new layout what I get is one hard reference to the RevisionBlock block and then 'N' anonymous blocks based on the size of my template.  I need to be able to edit the attributes on each RevisionBlock block (anonymous or not) independently of one another. 

 

So, how do I get the anonymous blocks and edit their attributes?  I have attached another screenshot to show what I am talking about (hopefully).  In the screenshot, note that there is a "RevisionBlock" block in the blocktable as well as a *U6, *U5, and *U3.  These are my revisionblocks (note in the drawing there are four of them next to the titleblock).

Message 3 of 7
Anonymous
in reply to: sweekly

Yoiu don't manipulate the anonymous blocks for a dynamic block, because they

are subject to being regenerated from the dynamic block definition when any of

the parameters of an insertion changes.

 

You manipulate the dynamic block definition, and then call UpdateAnonymousBlocks().

Message 4 of 7
sweekly
in reply to: Anonymous

I think I am not coming across clearly - let me try to further explain what I am trying to accomplish.  I am trying to change individual anonymous blocks in my drawing, not every reference to the dynamicblock (if that makes sense).  The sequence of events that I am trying (programatically) are as follows:

  • go to the layout dictionary and get the currently active layout.  I am only interested in updating the Revision Block attributes in the current layout. 
  • get the block table record (BTR) for the layout
  • loop through the BTR and get all of the BlockReferences in the BTR.  Each revision block SHOULD be a BlockReference in the BTR - at least when I snoop the database thats what I see (nine block references, one for each rev block and one for the titleblock).  Each one of these block references are Anonymous blocks.
  • FOREACH found blockreference, loop through the blocks attribute-references and get the text - save the text in a dictionary.
  • using values passed into the method - update the revblock attributes closest to the titleblock with the new values and then update all of the rest of the blocks with the values pulled from the drawing already <- basically I am trying to shift the revisions to the left and put the newest revision closest to the titleblock

The issue is that even though I have 8 different block references in my collection - when I update the first revision with the new values EVERY revision gets those values.  See the second screenshot for an example.  I am not understanding the relationships between blocks and attributes at all - my assumption has been that I could change the attributes on each "revision block" simply by getting said blocks objectid, gettings its attributes and changing them.  I can do this in AutoCAD via the attributes editor, I just can't do it via code.  I am quite sure there is something that I am just not understanding here - any help at all would be highly appreciated.

 

Message 5 of 7
Anonymous
in reply to: sweekly

The problem is somewhere in your code.  Modifying block attributes

is fairly straightfoward, and what you say is happening shouldn't

happen if the code is doing what it should be doing, correctly.

 

Unfortunately, the code is a bit difficult to follow and I'm not going to

test it even if I could. For example, you have a method that returns a

StringDictinoary, and also uses an 'out' parameter to return more data.

That kind of design tends to obsfucate the cause of bugs, and makes

it difficult to follow the code logic. Another odd thing, is your calling

ObjectId.ToString().  I'm nnt sure why you're doing that, but there's

no reason for it. ObjectIds can be compared to each other just as

strings can.

 

Message 6 of 7
Anonymous
in reply to: sweekly

If your revision block is dynamic and used dynamiclly then you can fill a objectIdcollection with GetAnonymousBlockIds  

Also you could use the blockTablerecord property IsDynamic to get the Dynamic Block Definition 

Message 7 of 7
sweekly
in reply to: Anonymous

Figured it out.  Had nothing to do with where I thought the error was - there was a bug in my code.  In an earlier method call to another method I was passing in some variables and I was incorrectly applying those variables to the 'refblock' blocks as well.  So - I was doing something stupid and I just didn't see it.  I have simplified what I was doing and I fixed the issue. 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost