Editor.GetPoint Cancelled Automatically After MdiActiveDocument Set In ACAD 2015

Editor.GetPoint Cancelled Automatically After MdiActiveDocument Set In ACAD 2015

Anonymous
Not applicable
2,308 Views
11 Replies
Message 1 of 12

Editor.GetPoint Cancelled Automatically After MdiActiveDocument Set In ACAD 2015

Anonymous
Not applicable

I have a pluggin which programatically activates a Drawing's Document by setting MdiActiveDocument, then imediately calls Editor.GetPoint. The code in question functions correctly in AutoCAD 2013 and 2014. However, in AutoCAD 2015 the Editor.GetPoint command is cancelled. Calling Editor.GetPoint seemingly does nothing. The Status member of the PromptPointResult returned by Editor.GetPoint is always set to Cancel. 

 

Note that before setting MdiActiveDocument to the target Drawing's Document, I set DocumentManager.DocumentActivationEnabled to True.

 

This code is not directly invoked by a Command. My plugin is "run" initially when a Command is executed. The command causes multiple PalletSets to be displayed. The affected code described previously is invoked when a button on one of the PalletSets is clicked. Acutally, the button causes a dialog window to be shown, and the code in question is invoked from the dialog.

 

After some searching, I tried setting the CommandFlag for the definition of the command used to initialize my pluggin to Session. But this had no effect. And even if this did correct the problem, it does not explain why my code runs as expected in 2013 and 2014 but not 2015.

 

Thanks in advance,

Kevin

0 Likes
Accepted solutions (1)
2,309 Views
11 Replies
Replies (11)
Message 2 of 12

FRFR1426
Collaborator
Collaborator

Fiber issue? There are now  inactive in AutoCAD 2015. Try to set the system variable NEXTFIBERWORLD to 1, then restart AutoCAD and test your command. If it works, you have to find a way to rewrite your command to support this new scheme.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 12

norman.yuan
Mentor
Mentor

So, your command bring up a PaletteSet; user clicks a button on one of the Palette in the PaletteSet, which display a dialog box; then user click something on the dialog box, which leads the code Editor.GetPoint() to be called.

 

Here are more things to know:

 

Is the dialog box a modal or modeless dialog?

How do you hide the dialog for user to pick (i.e. do you call Editor.StartUserInteraction() )?

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 12

Anonymous
Not applicable

Turning on NEXTFIBERWORLD did resolve the issue in 2015. Any idea what I might need to do to restore this to working order in 2015 without turning on NEXTFIBERWORLD?

 

Thanks,

Kevin

0 Likes
Message 5 of 12

Anonymous
Not applicable

The dialog is Modal. Initially, I use the ShowModalDialog method of Application when showing the dialog:

 

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle, frm, False)

 

As to what I do to hide the dialog while the user selects a point, just calling Editor.GetPoint seems to accomplish what I need. The dialog is hidden, and the user is prompted to select a point:

 

.....

Dim targetPointResult As PromptPointResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(Environment.NewLine + "Select Target Point: ")
If targetPointResult.Status = PromptStatus.OK Then

.....

 

When the code runs in 2015, the user is never prompted and PromptPointResult.Status is set to Cancel.

 

Setting NEXTFIBERWORLD to 1 resolves the issue. So now the issue is, how do I alter my code so that setting NEXTFIBERWORLD is not necessary in 2015? I'm reading up on Fibers in AutoCAD now.

 

Thanks,

Kevin

0 Likes
Message 6 of 12

FRFR1426
Collaborator
Collaborator

Rule #1 for palette: always execute a command when you want to perform an action on a document. When a button of your palette is clicked, use SendStringToExecute to launch a command like in this post: http://through-the-interface.typepad.com/through_the_interface/2011/02/managing-drag-drop-from-a-pal...

 

there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute().

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 7 of 12

Anonymous
Not applicable

FRFR suggests I must use SendStringToExecute to get around the removal of Fibers in 2015. Is this really necessary? Can you provide any further suggestions? Note that I answered your initial questions earlier in a separate response.

 

Thanks,

Kevin

0 Likes
Message 8 of 12

Anonymous
Not applicable

I tried creating a command and using SendStringToExecute to run it. I even tried using Session in the command's defintion, and calling SendStringToExecute on different Document intances. This did not solve my problem, unfortunately. The prompt for point is still cancelled in 2015. And the command being called on the target Document rather than the Source Document presents a problem. I did not explain this before, but the affected functionality creates copies of dynamic blocks, either within the same Drawing or targeting a different Drawing. So first I prompt for a base point in the source drawing, and then prompt for a second point in the target drawing. The way my pluggin is structured, using SendStringToExecute really isn't a viable option for me unless I alter the structure of my code signifigantly. This code works just fine in 2013-2014, and I would rather not rework it unless I absolutely must. 

 

I do thank you for your suggestion, and for turning me on to Fibers being a possible source of the issue in 2015.

 

Best Regards,

Kevin

0 Likes
Message 9 of 12

FRFR1426
Collaborator
Collaborator
Accepted solution

As you can read in this presentation: http://aucache.autodesk.com/au2010/sessiondocuments/C/SID09823E52C525B91FD5E46817FCE482EC.pptx, fibers allows to do transparent MDI document switching. In AutoCAD 2015, there are disabled by default.

 

> Switching documents now:

> - Cancel all activity in previous document

> - Disables prompts (immediately return RTCAN)

 

So, if I've well understood your problem, your code look like this:

 

static Document FindInactiveDoc(Document activeDoc)
{
    foreach (Document doc in Application.DocumentManager)
    {
        if (doc != activeDoc)
            return doc;
    }
    return null;
}

[CommandMethod("CMD", CommandFlags.Session)]
public void Cmd()
{
    Document doc1 = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc1.Editor;
    ed.GetPoint("\nFirst point: ");
    Document doc2 = FindInactiveDoc(doc1);
    Application.DocumentManager.MdiActiveDocument = doc2;
    PromptPointResult ppr = doc2.Editor.GetPoint("\nSecond point: ");
    if (ppr.Status == PromptStatus.Cancel)
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nGetPoint cancelled");
        return;
    }
    Application.DocumentManager.MdiActiveDocument = doc1;
    ed.WriteMessage("\nSecond point: {0}", ppr.Value);
}

 

It runs perfectly on 2014, but on 2015 with fibers disabled GetPoint is cancelled.

 

You can rewrite it like this:

 

[CommandMethod("CMD1")]
public void Cmd1()
{
    Document activeDoc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = activeDoc.Editor;
    ed.GetPoint("\nFirst point: ");
    Document inactiveDoc = FindInactiveDoc(activeDoc);
    inactiveDoc.UserData["srcDoc"] = activeDoc;
// Pass true in activate argument to activate the document. inactiveDoc.SendStringToExecute("CMD2\n", true, false, true); } [CommandMethod("CMD2")] public void Cmd2() { Document activeDoc = Application.DocumentManager.MdiActiveDocument; Editor ed = activeDoc.Editor; PromptPointResult ppr = ed.GetPoint("\nSecond point: "); var srcDoc = ((Document)activeDoc.UserData["srcDoc"]); srcDoc.UserData["secPoint"] = ppr.Value; srcDoc.SendStringToExecute("CMD3\n", true, false, true); } [CommandMethod("CMD3")] public void Cmd3() { Document activeDoc = Application.DocumentManager.MdiActiveDocument; Editor ed = activeDoc.Editor; ed.WriteMessage("\nSecond point: {0}", activeDoc.UserData["secPoint"]); }

In fact, you have to break it into 3 commands and use Document.UserData to share data between your drawings. 

 

The MATCHPROP command works like this in 2015. There is a command PAINTPROP which is launched on the second drawing to end the processing : ftp://www.strikersystems.com/Customer/!AllanW/AutoCAD%20Longbow%20Porting%20Tips.docx

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 10 of 12

Anonymous
Not applicable

FRFR1426, do you work for AutoDesk (ADN)? I've been assuming you are not. I have been waiting for a response from ADN for a week or so.

 

I expect your solution would work, and I thank you for helping me. I'm just hoping there is a solution that doesn't involve encapsulating my code in commands. This code was never intended to be run as a command.

 

Thanks,

Kevin

0 Likes
Message 11 of 12

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

Yes, the comments of FRFR1426 are correct. So we did not update the post. This behavior is because of moving away from fibers in AutoCAD 2015. This is similar to belowScenario.

Start AutoCAD 2015

Open couple of drawings.

Start circle command in one drawing, now switch to second drawing. The circle command will be automatically cancelled.

You need to refactor you code in AutoCAD 2015.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 12 of 12

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi ,

 

sorry missed to mention in previous post

 

Are you using start user interaction object to take the input as shown in blog http://adndevblog.typepad.com/autocad/2012/05/taking-mouse-inputs-from-a-modal-dialog-box.html



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes