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

C# method to read the value out of attributes

6 REPLIES 6
Reply
Message 1 of 7
MartinSi
1039 Views, 6 Replies

C# method to read the value out of attributes

I haven‘t work long with the AutoCAD .Net API and need help on the following topic.

What is the C# method to read the value out of attributes and write it into an array?
It would be very helpful if you could provide me with code samples.

Thank you for your time.
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: MartinSi

There are a number of steps involved in this process. On which step are you
having problems?

--
Bobby C. Jones
http://bobbycjones.spaces.live.com


"MartinSi" wrote in message news:6340211@discussion.autodesk.com...
> I haven‘t work long with the AutoCAD .Net API and need help on the
> following topic.
>
> What is the C# method to read the value out of attributes and write it
> into an array?
> It would be very helpful if you could provide me with code samples.
>
> Thank you for your time.
Message 3 of 7
MartinSi
in reply to: MartinSi

I heard of a C# method which can get Attributes out of blocks and puts them in an array.
Did you hear about this method or can you tell me where I can find more information?
Message 4 of 7
Anonymous
in reply to: MartinSi

"MartinSi" wrote in message news:6340267@discussion.autodesk.com...
> I heard of a C# method which can get Attributes out of blocks and puts
> them in an array.
> Did you hear about this method or can you tell me where I can find more
> information?

The COM API has such a method, but I don't know of a managed counterpart.

--
Bobby C. Jones
http://bobbycjones.spaces.live.com
Message 5 of 7
krugerm
in reply to: MartinSi

Here's the way I would do it, but I'm sure there must be a better way - particularly when it comes to finding an attref's corresponding attdef. If anyone knows a better solution please post a reply! (Calling TT on the batphone...)



BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord blkRecord = (BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead, false);


// get all the attribute definitions
List attDefs = new List();

// iterate through & index (by tag) all the block attribute definitions
foreach (ObjectId adId in blkRecord)
{
DBObject adObj = trans.GetObject(adId, OpenMode.ForRead);

// For each attribute definition we find...
AttributeDefinition ad = adObj as AttributeDefinition;
if (ad != null)
{
attDefs.Add(ad);
}
}


// get all the attribute references for this block
List attRefs = new List();

// iterate through the references to this block
foreach (ObjectId objId in blkRecord.GetBlockReferenceIds(true, true))
{
DBObject obj = (DBObject)trans.GetObject(objId, OpenMode.ForWrite, false);

BlockReference blockRef = obj as BlockReference;
if (blockRef == null)
continue;

foreach (ObjectId attrId in blockRef.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)trans.GetObject(attrId, OpenMode.ForRead, false);
attRefs.Add(attRef);

// To find the corresponding attDef, search through attDefs to find one with a Tag matching this attRef.
// I'd love to know if there's a better way.
// Can TT help?
}
}


// do some nifty stuff with the attributes
//...
Message 6 of 7
Anonymous
in reply to: MartinSi

The code in your post was reformatted by the forum software.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6340892@discussion.autodesk.com...
Here's the way I would do it, but I'm sure there must be a better way -
particularly when it comes to finding an attref's corresponding attdef. If
anyone knows a better solution please post a reply! (Calling TT on the
batphone...) BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
OpenMode.ForRead, false); BlockTableRecord blkRecord =
(BlockTableRecord)trans.GetObject(bt[blockName], OpenMode.ForRead, false); //
get all the attribute definitions List attDefs = new List(); // iterate through
& index (by tag) all the block attribute definitions foreach (ObjectId adId in
blkRecord) { DBObject adObj = trans.GetObject(adId, OpenMode.ForRead); // For
each attribute definition we find... AttributeDefinition ad = adObj as
AttributeDefinition; if (ad != null) { attDefs.Add(ad); } } // get all the
attribute references for this block List attRefs = new List(); // iterate
through the references to this block foreach (ObjectId objId in
blkRecord.GetBlockReferenceIds(true, true)) { DBObject obj =
(DBObject)trans.GetObject(objId, OpenMode.ForWrite, false); BlockReference
blockRef = obj as BlockReference; if (blockRef == null) continue; foreach
(ObjectId attrId in blockRef.AttributeCollection) { AttributeReference attRef =
(AttributeReference)trans.GetObject(attrId, OpenMode.ForRead, false);
attRefs.Add(attRef); // To find the corresponding attDef, search through attDefs
to find one with a Tag matching this attRef. // I'd love to know if there's a
better way. // Can TT help? } } // do some nifty stuff with the attributes //...
Message 7 of 7
MartinSi
in reply to: MartinSi

thanks for your help

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