Access Violation Reading Exception when using Editor.selectAll()

Access Violation Reading Exception when using Editor.selectAll()

Anonymous
Not applicable
1,039 Views
5 Replies
Message 1 of 6

Access Violation Reading Exception when using Editor.selectAll()

Anonymous
Not applicable

Hello,

I'm curently developing an AutoCAD plugin which need to retrieve a BlockReference from the layer "SNIE_BETON". Being the only object on that layer, i tried to use a SelectionFilter for the Editor.SelectAll() method. But when i try to execute the code, AutoCAD crashes and throw an "Unhandled Access Violation Reading 0x0000 Exception" error before closing.

I used the example on this website 

Any ideas?

 

I'm on AutoCAD 2018 and developing in C#

Here's the code :

TypedValue[] tvs = new TypedValue[1] { new TypedValue( (int)DxfCode.LayoutName, "SNIE_BETON" ) };
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = DOC.Editor.SelectAll(sf);
ObjectIdCollection oic = new ObjectIdCollection(psr.Value.GetObjectIds());
DOC.Editor.WriteMessage("\nFound {0} entity on SNIE_BETON", oic.Count);
concrete_plan = (BlockReference)Trans.GetObject(oic[0], OpenMode.ForWrite);
0 Likes
Accepted solutions (1)
1,040 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

not sure about the crash, but what I see is that you one time speak about "layer" and in your code you refer to "layout" ... that are different things and maybe that already solves your issue 😉

 

20190313_195351.png

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hello,

Well, my bad. When i saw that it wasn't working with the DFX layer, i tried with layout but i ended up with the same issue anyway.

I forgot to change my code, i'll change that immediately.

 

EDIT : Well it looks like i can't change my original post anymore… 😕

0 Likes
Message 4 of 6

Anonymous
Not applicable

Here's the code that i'm currently testing

TypedValue[] tvs = new TypedValue[1] { new TypedValue( (int)DxfCode.LayerName, "SNIE_BETON" ) };
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = DOC.Editor.SelectAll(sf);
ObjectIdCollection oic = new ObjectIdCollection(psr.Value.GetObjectIds());
DOC.Editor.WriteMessage("\nFound {0} entity on SNIE_BETON", oic.Count);
concrete_plan = (BlockReference)Trans.GetObject(oic[0], OpenMode.ForWrite);
0 Likes
Message 5 of 6

Anonymous
Not applicable

I tried this to see where exactly the program crashes :

 

TypedValue[] tvs = new TypedValue[1] { new TypedValue( (int)DxfCode.LayerName, "SNIE_BETON" ) };
DOC.Editor.WriteMessage("\n1");
SelectionFilter sf = new SelectionFilter(tvs);
DOC.Editor.WriteMessage("\n2");
PromptSelectionResult psr = DOC.Editor.SelectAll(sf);
DOC.Editor.WriteMessage("\n3");
ObjectIdCollection oic = new ObjectIdCollection(psr.Value.GetObjectIds());
DOC.Editor.WriteMessage("\n4");
DOC.Editor.WriteMessage("\nFound {0} entity on SNIE_BETON", oic.Count);
DOC.Editor.WriteMessage("\n5");
concrete_plan = (BlockReference)Trans.GetObject(oic[0], OpenMode.ForWrite);
DOC.Editor.WriteMessage("\n6");

AutoCAD displays "1" and "2" before crashing so i can conclude that "PromptSelectionResult psr = DOC.Editor.SelectAll(sf);" is the problem

 

 

 

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

Found the problem!

I was thinking it was coming from my code but it was even simpler.

The object wasn't on the right layer… I moved it and now everything's fine.

Sorry for the inconvenience

0 Likes