.NET

Reply
Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 1 of 15 (276 Views)

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

276 Views, 14 Replies
08-25-2012 05:01 PM

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 2 of 15 (258 Views)

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

08-26-2012 01:07 AM 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
-------------------------------------------------------------------------
Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 3 of 15 (245 Views)

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

08-26-2012 05:14 AM 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.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 4 of 15 (240 Views)

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

08-26-2012 05:25 AM 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
-------------------------------------------------------------------------
Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 5 of 15 (239 Views)

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

08-26-2012 05:27 AM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 6 of 15 (230 Views)

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

08-26-2012 07:12 AM in reply to: phives

Hi,

 

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

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 7 of 15 (226 Views)

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

08-26-2012 07:15 AM in reply to: Alfred.NESWADBA

Tx. will try it.....

Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 8 of 15 (210 Views)

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

08-26-2012 10:06 AM 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.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,982
Registered: ‎06-29-2007
Message 9 of 15 (207 Views)

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

08-26-2012 10:20 AM 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
-------------------------------------------------------------------------
Contributor
phives
Posts: 22
Registered: ‎08-25-2012
Message 10 of 15 (206 Views)

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

08-26-2012 10:25 AM 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.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.