Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

eInvalidInput while reading block attributes

Anonymous

eInvalidInput while reading block attributes

Anonymous
Not applicable

Trying to read block attributes from drawing gives me eInvalidInput most of the time

I don't really understand this error 

This was working fine 2 days ago and now is just failing most of the time.

 

Anyone could help me out. The class Atribute map is just a simple Key/Value pair class that store the block attributes.

 

this is the code is failing

 

/// <see cref="https://forums.autodesk.com/t5/net/find-block-inside-a-polyline/td-p/7586489"/>
public static IEnumerable<AttributeMap> GetBlockAttributesInsidePolyline(ObjectId id)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.LockDocument();
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId[] ids = null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Polyline pline = (Polyline)tr.GetObject(id, OpenMode.ForRead);
PromptSelectionResult selection = ed.SelectByPolyline(pline, PolygonSelectionMode.Window, new TypedValue(0, "INSERT"));
if (selection.Status == PromptStatus.OK)
{
ed.SetImpliedSelection(selection.Value);
ids = selection.Value.GetObjectIds(); ----------->here is whare it hapens most of the time---------------------------------------
}
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
Controller.TagController.CurrentDrawing.Logger.Error(string.Format("Polyline Handle {0} had an error: {1} ",
id.Handle.ToString(), e.Message));
}
}

return GetBlockAttributes(ids);

}

 

/// <see cref="http://through-the-interface.typepad.com/through_the_interface/2006/09/getting_autocad.html"/>
/// <param name="ids">ObjectIds</param>
public static IEnumerable<AttributeMap> GetBlockAttributes(ObjectId[] ids)
{
//There should be just one object Id in the ids
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.LockDocument();
Database db = doc.Database;
List<AttributeMap> attributes = new List<AttributeMap>();
if (ids != null)
{
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
foreach (ObjectId id in ids)
{
BlockReference blkRef = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
Controller.TagController.CurrentDrawing.Logger.Info("Block: " + btr.Name);
btr.Dispose();

AttributeCollection attCol = blkRef.AttributeCollection;
foreach (ObjectId attId in attCol)
{
AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);
string str = string.Format(" Attribute Tag: {0}{1} Attribute String: {2}", attRef.Tag, System.Environment.NewLine, attRef.TextString);
Controller.TagController.CurrentDrawing.Logger.Info(str);
attributes.Add(new AttributeMap { Field = attRef.Tag, Value = attRef.TextString });
}
}
tr.Commit();
}
}
return attributes;
}

0 Likes
Reply
Accepted solutions (1)
1,472 Views
4 Replies
Replies (4)

_gile
Mentor
Mentor
Accepted solution

aramosvizcarra a écrit :

 

this is the code is failing

 

/// <see cref="https://forums.autodesk.com/t5/net/find-block-inside-a-polyline/td-p/7586489"/>
public static IEnumerable<AttributeMap> GetBlockAttributesInsidePolyline(ObjectId id)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.LockDocument();
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId[] ids = null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Polyline pline = (Polyline)tr.GetObject(id, OpenMode.ForRead);
PromptSelectionResult selection = ed.SelectByPolyline(pline, PolygonSelectionMode.Window, new TypedValue(0, "INSERT"));
if (selection.Status == PromptStatus.OK)
{
ed.SetImpliedSelection(selection.Value);
ids = selection.Value.GetObjectIds(); ----------->here is whare it hapens most of the time---------------------------------------
}
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
Controller.TagController.CurrentDrawing.Logger.Error(string.Format("Polyline Handle {0} had an error: {1} ",
id.Handle.ToString(), e.Message));
}
}

return GetBlockAttributes(ids);

}

 


Try removing: ed.SetImpliedSelection(selection.Value);

This expression was only a way to display the result of the selection in the example.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

Juergen_Becker
Advocate
Advocate

Hi,

in which line does the error accure?

Regards Jürgen

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

0 Likes

Anonymous
Not applicable

Thank once again,that seems to solved it.

 

Just for curiosity why that line may be causing the issue?.

I couldn't find in the reference document that method.

0 Likes

_gile
Mentor
Mentor

aramosvizcarra a écrit :

Thank once again,that seems to solved it.

 

Just for curiosity why that line may be causing the issue?.

I couldn't find in the reference document that method.


After calling Editor.SetImpliedSelection, the selection set entities are highlighted/gripped, in other words, the selection set is "opened" for adding or removing entities to it. That's why you cannot acces to the SelectionSet.GetObjectIds() method.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub