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.
Solved! Go to Solution.
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).
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().
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:
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.
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.
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
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.