Reg. Extract attributes without opening Drawing file

Reg. Extract attributes without opening Drawing file

Anonymous
Not applicable
3,222 Views
7 Replies
Message 1 of 8

Reg. Extract attributes without opening Drawing file

Anonymous
Not applicable

Hi everyone,

 

I want to extract the attributes from the drawing file without opening drawing file.

 

Is there any way to do it ?

 

If it is possible then which API will be work Automation(ActiveX API) or Customization(.NET API) ?

0 Likes
3,223 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Are you asking how to extract block attributes without opening drawing file? Or drawing properties? Need clarification.
0 Likes
Message 3 of 8

owenwengerd
Advisor
Advisor

Your question sounds like "Can I read a book without opening it?" You should be more precise about what you mean by "attributes" and "opening". You must open a file in the operating system sense to read data from it, so perhaps you meant "without opening the drawing file in the AutoCAD editor".

--
Owen Wengerd
ManuSoft
Message 4 of 8

SENL1362
Advisor
Advisor
Or did he meant without showing in the AutoCAD editor.
Because of the ActiveX hint he probably meant extracting out of process without AutoCAD visible.
0 Likes
Message 5 of 8

Dale.Bartlett
Collaborator
Collaborator

I think the request is to batch process a collection of drawings and extract block attributes.

Refer here for code to open drawings:

http://forums.autodesk.com/t5/net/readdwgfile-side-database-correct-useage/td-p/5444657

And this may help for returning attributes and other block information:

<code>

 

// return csv string to write out to file

 

// specifically block name, attribute value and insert point (x,y,z)

public static string GetBlockInfo(Database pDb, Entity pEnt, string pstrAttTag)

{

string lstrReturnValue = string.Empty;

using (Transaction tr = pDb.TransactionManager.StartTransaction())

{

if (pEnt.GetType() == typeof(BlockReference))

{

// cast entity to a block reference

BlockReference br = pEnt as BlockReference;

// if successful, continue

if (br != null)

{

BlockTableRecord btr = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead, false) as BlockTableRecord;

// get block name

string lstrBlockName = btr.Name;

// get attribute

string lstrAttValue = string.Empty;

Autodesk.AutoCAD.DatabaseServices.AttributeCollection attcol = br.AttributeCollection;

foreach (ObjectId attId in attcol)

{

AttributeReference attRef = tr.GetObject(attId, OpenMode.ForWrite) as AttributeReference;

if (pstrAttTag.Equals(attRef.Tag))

{

lstrAttValue = attRef.TextString;

}

}

// get insert point

Point3d lpntInsertPoint = br.Position;

// csv version

string lstrInsertPoint = lpntInsertPoint.X.ToString() + "," + lpntInsertPoint.Y.ToString() + "," + lpntInsertPoint.Z.ToString();

// assemble return string

lstrReturnValue = lstrInsertPoint + "," + lstrBlockName + "," + lstrAttValue;

}

}

tr.Commit();

}

return lstrReturnValue;

}

 

</code>

Dale




______________
Yes, I'm Satoshi.
0 Likes
Message 6 of 8

Anonymous
Not applicable
We need both.
0 Likes
Message 7 of 8

Anonymous
Not applicable
We also want to read drawing file without installing AutoCAD in machine.

Is it possible ?
0 Likes
Message 8 of 8

Dale.Bartlett
Collaborator
Collaborator

If you wish to access a dwg database you will need either AutoCAD installed and licenced, or a licence for RealDWG. Dale 




______________
Yes, I'm Satoshi.
0 Likes