Post 1 of 4

Fatal error during execution

267 Views, 3 Replies
07-04-2013 03:33 AM

Hi everybody,

i coded this simple utility that allows the user to edit some dbtext without using the mouse (after selection).

It works but sometimes, it seems randomly, i get a fatal error.


This is the code


public void Run(object param)
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;

PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "\nSelect texts";
pso.AllowDuplicates = false;
pso.AllowSubSelections = false;

SelectionFilter sf = new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.Start, "TEXT") });

PromptSelectionResult psr = ed.GetSelection(pso, sf);
if (psr.Status != PromptStatus.OK)

foreach (SelectedObject so in psr.Value)
ed.SetImpliedSelection(new ObjectId[] { so.ObjectId });
executeSyncro("_textedit ");


void executeSyncro(string command)
AcadApplication app = (AcadApplication)Application.AcadApplication;


The run function it's called from a commandmethod with the CommandFlags.Session flag.

Where's the problem?



Post 2 of 4

Re: Fatal error during execution

07-10-2013 02:55 PM in reply to: giackserva

We have a technology inside of AutoCAD called fibers. This technology is used to handle our command line interface within the MDI, here's an example:


Open 2 documents, in document 1, start the line command, switch to document 2 (no command running) start the circle command, now switch back to document 1 (line command is still running) - very cool. What is happening is, the fiber technology is basically swapping the call stack in and out for us.


Now, Microsoft has stopped supporting fibers, most likely because fibers cause havoc with .NET, that's why we are removing fibers from AutoCAD.


Wherever we have .NET touching fibers, and where we have not coded defensively for that scenario, we have issues. For instance, you are all aware of the Visual Studio Debugger not hitting break points for .NET code right? Well, that's fibers rearing their ugly head again. 


So, your code: starts a command from the session context (application context) which requires document command line input, which in turn calls the ActiveX API to pumps a command to the command line asynchronously from the while your .NET application is running - you a not just touching fibers from .NET but poking it!!


Try this:


1) Create the command as Modal (Document context)

2) PInvoke acedCmd() - http://adndevblog.typepad.com/autocad/2012/04/synchronously-send-and-wait-for-commands-in-autocad-us...



Fenton Webb

Developer Technical Services

Autodesk Developer Network

Post 3 of 4

Re: Fatal error during execution

07-11-2013 12:47 AM in reply to: fenton.webb
Thanks for the reply Fenton.
I already see and use that piece of code and in this case it seems like the best solution. I stop using it because i can't understand how can i pass some argoument at the command like: "_move 0,0,0 ". I rarely use autocad command in my routine and on of this case was when i had to move a solid in 3d and give up with the jig :)
Can you explain me how to pass argoument?
Post 4 of 4

Re: Fatal error during execution

07-11-2013 01:18 AM in reply to: giackserva



Instead of P/Invoking acedCommand, you can use you can use the wrapper for the Editor.RunCommand() non-public method shared by Tony Tanzillo here:


It defines a Command() extension method for the Editor class which accepts managed types arguments.


Using example assuming ed is the active document Editor and id the ObjectId of the entity to move (where "" (empty string) stands for Enter and "\\" for a pause for user input):


ed.Command("_move", id, "", Point3d.Origin, "\\");


Gilles Chanteau
Programmation AutoCAD LISP/.NET

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post