I'm trying to use this code I founf here in the forum. What I can't figure out is where does it open the drawing and how do I pass it the ObjectID.
PublicSub SetAttribute(ByVal BlockID As Autodesk.AutoCAD.DatabaseServices.ObjectId, ByVal blckname AsString, ByVal AttTag AsString, ByVal AttVal AsString)
Dim MyDb AsDatabase = Application.DocumentManager.MdiActiveDocument.Database
If BlockID.IsNull ThenExit SubTryUsing myTrans AsTransaction= MyDb.TransactionManager.StartTransaction
Dim myBlckRef AsBlockReferenceDim myAttColl AsAttributeCollectionDim myBlckTable AsBlockTableRecord
myBlckRef = BlockID.GetObject(
If myBlckRef.IsDynamicBlock Then
myBlckTable = myTrans.GetObject(myBlckRef.DynamicBlockTableRecor
myBlckTable = myTrans.GetObject(myBlckRef.BlockTableRecord,
EndIfIfString.Compare(myBlckTable.Name, blckname, True) = 0 Then
myAttColl = myBlckRef.AttributeCollection
Dim myEnt As Autodesk.AutoCAD.DatabaseServices.ObjectIdDim myAttRef As Autodesk.AutoCAD.DatabaseServices.AttributeReferenceForEach myEnt InmyAttColl
myAttRef = myEnt.GetObject(
IfString.Compare(myAttRef.Tag, AttTag, True) = 0 Then
myAttRef.TextString = AttVal.ToString
EndUsingCatch ex AsExceptionEndTryEndSub
>> What I can't figure out is where does it open the drawing
It does not open the drawing, it uses the active document (currently loaded and activated DWG).
>> how do I pass it the ObjectID
Sorry not to understand that. The answer "you call this sub and transfer the objectid by adding it as the first parameter to the calling line-code" will not be what you are looking for, I guess.
- alfred -
PS: to make your code readable within the threads here you should use the icon in the answering-dialog. Otherwise you see your code gets really unstructured and so useless (spaces and cr missing after pasting your lines).
I want to create a routine that looks like this.
Sub EditAttribute(DWGNAME, BLOCKNAME, ATTRIBUTENAME, ATTRIBUTEVALUE)
The routine will open the specified drawing, find the block and attribute and write a new value in.
and when the block (blockreference) is inserted multiple times in one drawing (e.g. 1 in each layout and 3 in the modelspace)? Which one should then be modified?
- alfred -
find attached the code (and a sample drawing), it's not really tested, so be careful
- alfred -
I'm getting this error.....
Method 'GetEnumerator' in type 'Autodesk.AutoCAD.DatabaseServices.BlockTable' from assembly 'acdbmgd, Version=22.214.171.124, Culture=neutral, PublicKeyToken=null' does not have an implementation.
upload your test-drawing and your call-parameters.
But I think it's anything like wrong version of the *mgd*.dll you are referencing ==> what os and what AutoCAD-version (and vertical product) do you work with?
- alfred -
fillBlock("C:\Users\PAUL\Desktop\B-03-J-H135.dwg", "RO", "CAB", "UUUU")
ACAD2010. I downloaded the ObjectARX2011. The dll's are there.
BTW. You know that I am doing this from a standalone EXE.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.