.NET

.NET

Reply
Contributor
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 1 of 15

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

302 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*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 2 of 15

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
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 3 of 15

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*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 4 of 15

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
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 5 of 15

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*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 6 of 15

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
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 7 of 15

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
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 8 of 15

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*
9,836 Posts
1,219 Kudos
Registered: ‎06-29-2007
Post 9 of 15

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
22 Posts
0 Kudos
Registered: ‎08-25-2012
Post 10 of 15

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!