.NET

Reply
Active Member
giackserva
Posts: 7
Registered: ‎06-18-2012
Message 1 of 4 (220 Views)

Fatal error during execution

220 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)
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

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 4 (161 Views)

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


Active Member
giackserva
Posts: 7
Registered: ‎06-18-2012
Message 3 of 4 (147 Views)

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 :smileyhappy:
Can you explain me how to pass argoument?
Thanks
*Expert Elite*
_gile
Posts: 2,083
Registered: ‎04-29-2006
Message 4 of 4 (138 Views)

Re: Fatal error during execution

07-11-2013 01:18 AM 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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.