unable to pan and orbit while run from modal dialog

unable to pan and orbit while run from modal dialog

autojinx
Participant Participant
1,234 Views
12 Replies
Message 1 of 13

unable to pan and orbit while run from modal dialog

autojinx
Participant
Participant

Hi,

I was wondering if anyone could point me in a right direction here,

I'm writing a small cad application and when I call out my form as ModelessDialog then I'm having this issue where when I click on my button to GetPoints from autocad I cannot pan or orbit, only zoom would work

but if I call my form as ModalDialog the GetPoint button clicked gives me the option to pan and orbit while looking for a point to click,

also I have noticed that when run as ModelessDialog I can get the pan and orbit working only if I run my command using SendStringToExecute, and if it's called out as a function is again does not give me an option to midmousebutton pan or orbit,

any chance for some help at all?

 

0 Likes
Accepted solutions (1)
1,235 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Hi,

 

Difficult to reply without seeing the code.

 

Just a guess, do you explicitly set the focus to the document window?

        private void button1_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            doc.Window.Focus();
            var result = ed.GetPoint("\nPick a point: ");
            if (result.Status == PromptStatus.OK)
                textBox1.Text = $"{result.Value:0.00}";
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

autojinx
Participant
Participant

I don't explicitly focus on any window, I don't use focus at all, maybe I should?

the code is as follows:

call up my main window with various buttons and as described modeless does not function for pan and orbit

 

Dim Form As Form1
Form = New Form1
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(Form)

 

then under the button there's following code to select a point:

 

Private Sub ButtonGetPoint_Click(sender As Object, e As EventArgs) Handles ButtonGetPoint.Click
            Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim n As Integer = 0
            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim pPtRes As PromptPointResult
            Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
            Dim pts As Point3dCollection = New Point3dCollection
            
            pPtOpts.AllowNone = True

            Me.Hide()
            
            pPtOpts.Message = vbLf & "Pick a point: "
            pPtRes = acDoc.Editor.GetPoint(pPtOpts)
            Dim pt As Point3d = pPtRes.Value
            
            If pPtRes.Status = PromptStatus.OK Then
                TextBoxFX.Text = (Math.Round(pt.X, 2)).ToString
                TextBoxFY.Text = (Math.Round(pt.Y, 2)).ToString
                TextBoxFZ.Text = (Math.Round(pt.Z, 2)).ToString
            Else
            End If
            Me.Show()
        End Sub

 

 

0 Likes
Message 4 of 13

fieldguy
Advisor
Advisor

just a guess. try without "Hide()" and "Show()". Editor.Getpoint will handle the focus. is it necessary to hide your form?

0 Likes
Message 5 of 13

autojinx
Participant
Participant

Hiding my form is more of a cosmetic so not that important to maintain, but not using it does not help the problem,

0 Likes
Message 6 of 13

fieldguy
Advisor
Advisor

my windows "forms" are instances of "usercontrol" and added to paletteset. never had a problem with editor interaction.  

0 Likes
Message 7 of 13

autojinx
Participant
Participant

hmm, maybe that's where I'm going wrong then? my form probably isn't what you say it maybe should be.

where can I get a bit more info on how to built my form as an instance of "usercontrol" and add to paletteset?

0 Likes
Message 8 of 13

_gile
Consultant
Consultant

Hi,

 

Here's the translation of a "tutorial" about AutoCAD and user interfaces, I hope it helps:

http://gilecad.azurewebsites.net/UserInterfaces_EN.aspx



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

lena.talkhina
Alumni
Alumni

Hello @autojinx  !

Great to see you here on .NET Forum.

Did you find a solution?
If yes, please click on the "Accept as Solution" button as then also other community users can easily find and benefit from the information.
If not please don't hesitate to give an update here in your topic so all members know what ́s the progression on your question is and what might be helpful to achieve what you ́re looking for. 🙂

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes
Message 10 of 13

autojinx
Participant
Participant

Please excuse maybe a little slow reply, but I'm an amateur programmer and it took me a while to study the suggestions from the guys, 

her's what I found further, 

I have rewritten the same code to an autocad palette and calling a get point function from a button from the autocad palette gives me the same issue, and maybe another clue here, please see attached screenshot - after I click on my GetPoint button the hint by the cursor says "pick point..." and when I try to pan (which still doesn't work) and hit middle mouse button it adds "invalid point" ,   

orbit obviously still gives the same issue,

any further clues at all Guys?

Screen.png

0 Likes
Message 11 of 13

_gile
Consultant
Consultant
Accepted solution

Here's a way, following Kean Walmsley advice:

"Once again 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()."

 

The CustomPalette class which exposes the control as property:

using Autodesk.AutoCAD.Windows;

using System;

namespace ModalModelessDialog
{
    internal class CustomPaletteSet : PaletteSet
    {
        public UserControl1 GetPointControl { get; }

        /// <summary>
        /// Crée une nouvelle instance de CustomPaletteSet
        /// </summary>
        public CustomPaletteSet()
            : base("Palette", "CMD_PALETTE", new Guid("{ABC4C47C-16A9-4C82-98CD-6636C02B1A4E}"))
        {
            Style =
                PaletteSetStyles.ShowAutoHideButton |
                PaletteSetStyles.ShowCloseButton |
                PaletteSetStyles.ShowPropertiesMenu;
            MinimumSize = new System.Drawing.Size(250, 150);
            GetPointControl = new UserControl1();
            Add("Get Point", GetPointControl);
        }
    }
}

 

The UserControl1 class with a read/write Point property and the Button1.Click handler which calls a custom command:

using Autodesk.AutoCAD.Geometry;
using System;
using System.Windows.Forms;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ModalModelessDialog
{
    public partial class UserControl1 : UserControl
    {
        Point3d point;

        public UserControl1()
        {
            InitializeComponent();
        }

        public Point3d Point
        {
            get { return point; }
            set
            {
                point = value;
                textBoxX.Text = $"{point.X:0.00}";
                textBoxY.Text = $"{point.Y:0.00}";
                textBoxZ.Text = $"{point.Z:0.00}";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
            {
                doc.SendStringToExecute("GetPointFromPaletteCommand ", false, false, true);
            }
        }
    }
}

 

The commands class with a command to show the palette and another one to prompt the use to specify a point and pass the result to the palette user control property:

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;

namespace ModalModelessDialog
{
    public class Commands
    {
        static CustomPaletteSet palette;

        [CommandMethod("CMD_PALETTE")]
        public void ShowPaletteSet()
        {
            if (palette == null)
                palette = new CustomPaletteSet();
            palette.Visible = true;
        }

        [CommandMethod("GetPointFromPaletteCommand")]
        public void GetPointFromPaletteCommand()
        {
            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
            var ppo = new PromptPointOptions("\nPick a point: ");
            ppo.AllowNone = true;
            var ppr = ed.GetPoint(ppo);
            if (ppr.Status == PromptStatus.OK)
            {
                palette.GetPointControl.Point = ppr.Value;
            }
        }
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 13

autojinx
Participant
Participant

Thank You for an extensive answer in this matter, I've tried to got through the code in my own pace and as far as I understand we are back to using SendStringToExecute, 

this has worked before but there were two issues I came across with this:

1. SendStringToExecute run command/code asynchronously, and other stuff from my routines gets messed up,

2. SendStringToExecute does not allow me to pass some arguments which comes in handy later on in my code, not critical I suppose, but nice to have and running it via function works all good, apart from the mentioned problem with pan/orbit,

What I'm trying to achieve is something like - click-> getpointfromuser->function does some calcs based on received coordinates -> function changes view-> ask user for more points -> do further calculations in the routing-> draw entity i.e. circle (saved in temp item list) and on and on few times changing views and asking for more points from user, 

Any other way to bring the mouse pan/orbit functionality back?

0 Likes
Message 13 of 13

autojinx
Participant
Participant

after further insight into the topic I must admit that this is a solution, and probably the only one as whatever I've tried other than this wouldn't work. 

In this case calling a function via sendcommandtoexecute results in full mouse functionality while "in running command" and a function can be defined more extensively/multiple steps etc and it still works ok, 

thank You very much for support,

0 Likes