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

Fatal error during execution

3 REPLIES 3
Reply
Message 1 of 4
giackserva
483 Views, 3 Replies

Fatal error during execution

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)
return;

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

ed.Regen();
}

void executeSyncro(string command)
{
AcadApplication app = (AcadApplication)Application.AcadApplication;
app.ActiveDocument.SendCommand(command);
}

 

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

Where's the problem?

Thanks

 

3 REPLIES 3
Message 2 of 4
fenton.webb
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
AutoCAD Engineering
Autodesk

Message 3 of 4
giackserva
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?
Thanks
Message 4 of 4
_gile
in reply to: giackserva

Hi,

 

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:

http://www.theswamp.org/index.php?topic=43113.msg483306#msg483306

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
GileCAD
GitHub

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost