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(
OpenMode.ForWrite)
If myBlckRef.IsDynamicBlock Then
myBlckTable = myTrans.GetObject(myBlckRef.DynamicBlockTableRecord,
OpenMode.ForRead)
Else
myBlckTable = myTrans.GetObject(myBlckRef.BlockTableRecord,
OpenMode.ForRead)
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(
OpenMode.ForWrite)
IfString.Compare(myAttRef.Tag, AttTag, True) = 0 Then
myAttRef.TextString = AttVal.ToString
EndIfNextEndIf
myTrans.Commit()
EndUsingCatch ex AsExceptionEndTryEndSub
Hi,
>> 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.
Hi,
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 -
Hi,
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=18.1.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
Hi,
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.
Hi,
>> ACAD2010
...and the message from the message above:
>> from assembly 'acdbmgd, Version=18.1.0.0
That shows me that you have referenced the managed dll from AutoCAD 2011, not the one for AutoCAD 2010, don't mix versions! So that is the first problem.
>> BTW. You know that I am doing this from a standalone EXE.
No, should I? Have you told that anywhere in your previous posts?
So Norman (in >>>this post<<<) is absolutely correct with his opinion and when you seek through www to get samples orientate more on VB6 or VBA for AutoCAD (and not dotNET-based application development).
To get the most direct help then is to download the VBA-enabler (from >>>here<<<), if you start then VBAIDE you have the help that shows you how to use COM-based development with AutoCAD.
Good luck, - alfred -
Hi,
>> I'm using VisualBasic not VBA.
but the help is the best and the syntax is about the same.
I just wanted to point you to the most easy way to see a lot of sample-code as the VBA-for-AutoCAD shows for nearly every entity-type/every function/property/sub a sample. And as long as you have not installed the VBA-Enabler you won't have access to the help-file (acadauto.chm).
- alfred -
I downloaded the enabler. Have no idea where it installed to. Can't find it on my machine.
Hi,
>> I downloaded the enabler. Have no idea where it installed to
Just downloaded or also the exe started?
If you have started the exe so the VBA-Enabler got installed you can start AutoCAD, start command _VBAIDE and you are in the VBA-environment for AutoCAD.
Alternativly you may search for the file acadauto.chm ==> you can start it and use it for search and for samples for how to access blockreferences, attributereferences, open drawings and so on.
Good luck, - alfred -
Can't find what you're looking for? Ask the community or share your knowledge.