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

Need help with code. I'm new to all this

14 REPLIES 14
Reply
Message 1 of 15
phives
715 Views, 14 Replies

Need help with code. I'm new to all this

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

14 REPLIES 14
Message 2 of 15
Alfred.NESWADBA
in reply to: phives

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).

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 15
phives
in reply to: Alfred.NESWADBA

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.

Message 4 of 15
Alfred.NESWADBA
in reply to: phives

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 -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 15
phives
in reply to: Alfred.NESWADBA

Each of our blocknames are unique. That's why we do it that way.

Message 6 of 15
Alfred.NESWADBA
in reply to: phives

Hi,

 

find attached the code (and a sample drawing), it's not really tested, so be careful 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 7 of 15
phives
in reply to: Alfred.NESWADBA

Tx. will try it.....

Message 8 of 15
phives
in reply to: phives

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.

Message 9 of 15
Alfred.NESWADBA
in reply to: phives

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 -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 10 of 15
phives
in reply to: Alfred.NESWADBA

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.

Message 11 of 15
Alfred.NESWADBA
in reply to: phives

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 12 of 15
phives
in reply to: Alfred.NESWADBA

I'm using VisualBasic not VBA.

Message 13 of 15
Alfred.NESWADBA
in reply to: phives

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 -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 14 of 15
phives
in reply to: Alfred.NESWADBA

I downloaded the enabler. Have no idea where it installed to. Can't find it on my  machine.

Message 15 of 15
Alfred.NESWADBA
in reply to: phives

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

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