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

eInvalidInput while reading block attributes

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1369 Views, 4 Replies

eInvalidInput while reading block attributes

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;
}

Tags (1)
4 REPLIES 4
Message 2 of 5
_gile
in reply to: Anonymous


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

Message 3 of 5
Juergen_Becker
in reply to: Anonymous

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

Message 4 of 5
Anonymous
in reply to: _gile

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.

Message 5 of 5
_gile
in reply to: Anonymous


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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report