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

synchronize block with attributes

13 REPLIES 13
Reply
Message 1 of 14
wang890
1877 Views, 13 Replies

synchronize block with attributes

the attributes' location in my block has updated, is there a way to synchronize it from code? just like the synchronize button from the Modify II tool bar.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
13 REPLIES 13
Message 2 of 14
chiefbraincloud
in reply to: wang890

yes... The hard way. You have to open the BlockTableRecord of the Block in question, then BTR.GetBlockReferenceIds, and open each of the references, and almost recreate the code for adding the AttributeReference to the BlockReference when inserted, except that for existing attributes that have been modified, you don't create them as new ones, you just call SetAttributeFromBlock. Also, for existing attributes that have been modified, like you moved them, or changed the font, or visibility, etc... If the attribute has a textstring in it that is not the default, you will have to store that textstring, call SetAttributeFromBlock, then reset the textstring.

I'm a little reluctant to post my version, but here it is... attached. It takes the BlockTableRecord's ObjectID, and a regular expression for what attribute tags to Sync. The regular expression is optional and is defaulted to Sync all Tags found. To sync a single att, just pass the Tagstring. If you use it, you'll find there is a reference to the DocumentManager at the top that you will have to declare or change.

Edited by: chiefbraincloud on May 13, 2009 1:11 PM

Changed the attachments extension so it doesn't try to 'Run' when you click it.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 14
chiefbraincloud
in reply to: wang890

I just noticed that you are the same poster from the other day with the Attribute not showing up (solved) but your last comment indicates you are working with a database on the side instead of the current drawing. The code I posted works with the current document, but I'm not at all sure what the result would be if you tried the same approach on a side database. At first thought it seems like it should work just by changing the DB reference to the side database but I never tried to do that level of manipulation on a side database before.
Dave O.                                                                  Sig-Logos32.png
Message 4 of 14
wang890
in reply to: wang890

i put your sub in my code but current no license for autocad, i only have civil 3d installed. so sucks. we are tight on the licenses. yeah, thanks man, hopefully yoru code works out.

"side database" that's a good term. i am looking for this term. as opposed to the current document. too bad the "editor" can't be obtained with side database, which i can't do a window selection and such. would be nice if i can do that.

i don't know why if i use the current document then the block are fine when inserted, but when using a side document it somehow use some "default" justify property. but that's the advantage of using .net. don't need to open the drawing like the com objects. totally worth the time, took me like 40 hours already, but consider we are going to run this on 2000 drawings with all kinda stuff inside, then it's worth the time spent. but shouldn't volunteer to program stuff like this. use too much brain.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 5 of 14
wang890
in reply to: wang890

didn't work man. here's all my code.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 6 of 14
chiefbraincloud
in reply to: wang890

Did it suffer some sort of access failure, or just not overcome the justification problem?
Dave O.                                                                  Sig-Logos32.png
Message 7 of 14
wang890
in reply to: wang890

i've attached the whole project in vb.net.

didn't suffer anything. just if i have the document current then it's ok, when it's side, not ok- need user synchronization.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 8 of 14
wang890
in reply to: wang890

here's the drawing for testing. just put it anywhere and then change the testpath variable in the code to where you put it.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 9 of 14
wang890
in reply to: wang890

make sure you copy the drawing before hand. because the program saves the drawing and change the database without confirmation.
Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
Message 10 of 14
chiefbraincloud
in reply to: wang890

Based on the apparent purpose of this function (to update title block attributes), I can see a use for it in our house as well. So, I would be happy to take a look and see if I can help find a solution. I won't really be able to get into it until tomorrow, though.
Dave O.                                                                  Sig-Logos32.png
Message 11 of 14
Anonymous
in reply to: wang890

Here's what I have. A note on the attribute default placement-- setting the database to the working database and then calling the adjustalignment on the attribute should do what you wanted. The TitleblockAttributes class is just a collection of attribute values.

I'm not all that proficient at programming--so feel free to point out errors or incorrect disposings if they're in the code. I run this out about 2000 drawings myself and find it seems to work well. The file is output if I can't write to it so that I can pass is back in an error message.

BTW, all of this code is from through the interface (with the exception of the layer checking perhaps) compiled from the various posts Kean's done on blocks and attributes. His blog has been a great asset to me.

You'd think with the number of people wanting to have a method for updating thousands of titleblocks automatically, it might be something AutoCAD would just take care of...show of hands for everyone working on intelligent titleblocks?! Edited by: dwolfe01 on May 14, 2009 8:45 AM
Message 12 of 14
chiefbraincloud
in reply to: wang890


I've always had some sort of Lisp routine for updating title block atts, but I've never taken the time to do a .Net version, much less a .net version that works on the side instead of opening each drawing.

setting the database to the working database and then calling the adjustalignment on the attribute should do what you wanted.

There are a couple of things missing (besides TitleBlockAttributes) so I can't build it without fixing it, but it makes sense, I think that may be the bit we were reaching for. I'm personally curious now, I wonder if setting the side DB to the working database will eliminate the problem with the alignment and then calling AdjustAlignment would be unneccessary?

And, I also frequently extoll the virtues of Through the Interface. Kean's posts have saved me from many hours of frustration (and once or twice, saved me from ending it all After many hours of frustration;-)

Dave O.                                                                  Sig-Logos32.png
Message 13 of 14
Anonymous
in reply to: wang890

{quote}

chiefbrainfart copied and pasted:

"setting the database to the working database and then calling the
adjustalignment on the attribute should do what you wanted."

{quote}

Isn't that what dewolfe01 just said, EXACTLY ?

I'm not sure what it is you're here to prove, but this sort of 'copy & paste
plaugirism' is definitely not having the intended effect.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm
Message 14 of 14
chiefbraincloud
in reply to: wang890

Yes...That's why it is Italicized and separated... I was referring to it in the comment that followed. That in no way qualifies as PLAGIARISM.

And, If your post was intended to disrupt a perfectly civil discussion about .NET programming then it definitely IS having the intended effect.
Dave O.                                                                  Sig-Logos32.png

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