Get to Text objects within Imported Dwg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I am successfully importing a dwg and extracting a collection of blocks, their coordinates and rotation.
Problem is I also need to get to the Text objects within the imported DWG for which the only method I know is to Explode the DWG which then reveals the Text as TextNote objects. This gives me what i need all be it with the expense of exploding the DWG (I remove the elements after) but the issue here is that the Explode command only supports up to 10000 elements meaning I can’t get to the Text objects within the dwg Import if this limit is exceeded.
If anyone out there knows how to get the Text objects from a single dwg ImportInstance without Exploding first I would be extremely graceful in finding out. Interestingly you can get to a single Text object through the UI by selecting the Imported DWG and then clicking the Query Button under the Modify Tab.
The simplified code that loops looking for GeometryInstance (blocks) is listed below.
string FileName = ""; ElementId elementid = null; DWGImportOptions options = new DWGImportOptions(); options.SetRefPoint(new XYZ(0, 0, 0)); options.Placement = Autodesk.Revit.DB.ImportPlacement.Centered; options.OrientToView = true; doc.Import(FileName, options, doc.ActiveView, out elementid); // Get hold of the imported dwg object and drill down through the
//elements picking out the blocks ImportInstance dwg = doc.GetElement(elementid) as ImportInstance; if (dwg == null) return Result.Failed; foreach (GeometryObject geometryObj in dwg.get_Geometry(new Options())) { if (geometryObj is GeometryInstance) // This will be the whole thing { GeometryInstance dwgInstance = geometryObj as GeometryInstance; foreach (GeometryObject blockObject in dwgInstance.SymbolGeometry) { if (blockObject is GeometryInstance) // This could be a block { //get the object name and coordinates and rotation and
//load into my own class clsBlockInstance blockCls = new clsBlockInstance(); GeometryInstance blockInstance = blockObject as GeometryInstance; string name = blockInstance.Symbol.Name; Transform transform = blockInstance.Transform; XYZ origin = transform.Origin; XYZ vectorTran = transform.OfVector(transform.BasisX.Normalize()); double rot = transform.BasisX.AngleOnPlaneTo(vectorTran, transform.BasisZ.Normalize()); // radians rot = rot * (180 / Math.PI); // degrees blockCls.Name = name; blockCls.Origin = origin; blockCls.Rotation = rot; blockInstanceCollection.Add(blockCls); } } } }