.NET

Reply
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 11 of 18 (329 Views)

Re: Zoom from modal dialog

01-02-2013 11:12 PM in reply to: autodeskprogrammer

autodeskprogrammer wrote:

but I implemented your code and it worked perfectly - only I disabled some part of your code 

<snip>

 


You didn't implement his code in the Click handler of a button on a modal dialog launched from a PaletteSet, because if you had, you would have needed to lock the document before modifying it.

 

The problem is not his code, it is the context in which it runs.

Contributor
autodeskprogrammer
Posts: 21
Registered: ‎08-20-2008
Message 12 of 18 (318 Views)

Re: Zoom from modal dialog

01-03-2013 03:15 AM in reply to: DiningPhilosopher

your right,
I implemented all the parts except palette but with palette and dock lock it works perfect

 

I agree "The problem is not his code, it is the context in which it runs."

Contributor
sfinch1
Posts: 12
Registered: ‎01-24-2007
Message 13 of 18 (294 Views)

Re: Zoom from modal dialog

01-07-2013 08:47 AM in reply to: DiningPhilosopher

Still having no luck getting the Zoom to work immediately when the user clicks the button on a modal dialog.

 

I tested the code from a button's click handler on a modeless dialog and it worked immediately as desired.  I then tested it from a button click event on a paletteset and it also zoomed immediately.

 

The modal dialog is launched from the paletteset.  I tried passing a ByRef reference to the calling paletteset as a parameter to the New() method of the modal dialog, and having the modal dialog click handler execute the code on the parent paletteset.  No luck.  The zoom still occurs only after the modal dialog is closed.

 

I also tried launching the modal dialog by using SendStringToExecute() to call a CommandMethod which launches the modal dialog.  Same result.

 

Here's my Zoom function (which works fine for me):

    Public Sub ZoomMapCenter(ZoomCenterPoint As Point3d, ObjectHeight As Double)
        'zoom to a specific point on the map at a reasonable zoom scale to view object

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Autodesk.AutoCAD.DatabaseServices.Database = doc.Database
        Dim ed As Editor = doc.Editor


        ZoomCenterPoint.TransformBy(ed.CurrentUserCoordinateSystem)

        Dim map As AcMapMap = AcMapMap.GetCurrentMap()
        Dim mapExtent As MgEnvelope = map.GetMapExtent()

        'There is some FDO feature source connected
        If Not mapExtent.IsNull() Then

            'set a reasonable zoom extent based on the object height passed to this method
            Dim newExtent As New MgEnvelope(ZoomCenterPoint.X - (ObjectHeight * 3.0), ZoomCenterPoint.Y - (ObjectHeight * 2.0), ZoomCenterPoint.X + (ObjectHeight * 3.0), ZoomCenterPoint.Y + (ObjectHeight * 2.0))

            Using acLckDoc As DocumentLock = doc.LockDocument()
                doc.LockDocument()

                map.ZoomToExtent(newExtent)

                AcMapMap.ForceScreenRefresh()

            End Using

        End If
    End Sub

 

I just need to get the above method to execute immediately when called from a modal dialog somehow.  Is there any way that I can do that?

 

Thanks again for all the help.

 

 

*Expert Elite*
_gile
Posts: 2,069
Registered: ‎04-29-2006
Message 14 of 18 (287 Views)

Re: Zoom from modal dialog

01-07-2013 10:05 AM in reply to: sfinch1

Hi,

 

here's a way working for me:

- the 'Test' command shows a Paletteset which contains a UserControl : 'ZoomControl'

- the 'ZoomControl' UserControl contains a button (btnDialog) to open a Form as modal dialog: 'Dialog'

- the 'Dialog' Form contains a button (btnZoom) which does a zoom extents.

 

It seems to me there's no need to call LockDocument() if you open the dialog using Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog() method.

 

The CommandMethods class where the PaletteSet is created

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;

[assembly: CommandClass(typeof(ZoomFromModalDialogFromPalette.CommandMethods))]

namespace ZoomFromModalDialogFromPalette
{
    public class CommandMethods
    {
        private static PaletteSet ps;

        [CommandMethod("Test", CommandFlags.Modal)]
        public void Test()
        {
            if (ps == null)
            {
                ps = new PaletteSet("zoom", new Guid("{BEE26D4D-DD21-4B01-8080-7B6E38AD3FBA}"));
                ps.Style =
                  PaletteSetStyles.ShowPropertiesMenu |
                  PaletteSetStyles.ShowAutoHideButton |
                  PaletteSetStyles.ShowCloseButton;
                ps.Name = "Test Zoom";
                ps.Add("Zoom", new ZoomControl());
            }
            ps.Visible = true;
        }
    }
}

 

The ZoomControl class with the btnDialog event handler

using System;
using System.Windows.Forms;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ZoomFromModalDialogFromPalette
{
    public partial class ZoomControl : UserControl
    {
        public ZoomControl()
        {
            InitializeComponent();
        }

        private void btnDialog_Click(object sender, EventArgs e)
        {
            Dialog dlg = new Dialog();
            AcAp.ShowModalDialog(dlg);
        }
    }
}

 

The Dialog class in which the btnZoom event handler is defined

using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ZoomFromModalDialogFromPalette
{
    public partial class Dialog : Form
    {
        public Dialog()
        {
            InitializeComponent();
        }

        private void btnZoom_Click(object sender, EventArgs e)
        {
            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (ViewTableRecord view = ed.GetCurrentView())
            {
                Matrix3d worldToEye =
                    (Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                    Matrix3d.Displacement(view.Target - Point3d.Origin) *
                    Matrix3d.PlaneToWorld(view.ViewDirection)).Inverse();
                Extents3d ext = (short)AcAp.GetSystemVariable("cvport") == 1 ?
                new Extents3d(db.Pextmin, db.Pextmax) :
                new Extents3d(db.Extmin, db.Extmax);
                ext.TransformBy(worldToEye);
                view.Width = ext.MaxPoint.X - ext.MinPoint.X;
                view.Height = ext.MaxPoint.Y - ext.MinPoint.Y;
                view.CenterPoint = new Point2d(
                    (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
                    (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
                ed.SetCurrentView(view);
            }
        }
    }
}

 

 

Gilles Chanteau
Contributor
sfinch1
Posts: 12
Registered: ‎01-24-2007
Message 15 of 18 (275 Views)

Re: Zoom from modal dialog

01-07-2013 12:49 PM in reply to: DiningPhilosopher

Gilles,

 

Thanks very much for the code example, but in my particular situation, I have to use the Map 3D AcMapMap.ZoomToExtent() method to get the correct zoom results. 

 

With the Zoom method in the API documentation or your example, the code depends on the extents of the drawing.  With a state plane coordinate system in use in my drawing, the extents are many miles across while the actual bounds of the existing entities are less than 1/2 mile across.  Zooms using those methods take me way out in space somewhere.  I found that the AcMapMap.ZoomToExtent() method works perfectly for me. and solves those issues.

 

I want to test your code, but I'm only slightly familiar with C# and am doing something wrong in getting the project references set up for testing.  What your example shows seems to be pretty much what I'm already doing other than the differences in the zoom methods.

 

Steve

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 16 of 18 (262 Views)

Re: Zoom from modal dialog

01-08-2013 04:41 AM in reply to: sfinch1

I'm not familiar with how the Map API is doing the zoom, but you might want to try setting your Form's Visible property to false, just before you call the API and as soon as it returns, set it to True. And you can for good measure, put a call to Application.DoEvents() right after the call to the MAP API.  Modal dialogs have their own message pump and that seems to be the problem here, so by temporarily hiding and then immediately showing your form, it should cause AutoCAD to process any pending messages.

Contributor
sfinch1
Posts: 12
Registered: ‎01-24-2007
Message 17 of 18 (236 Views)

Re: Zoom from modal dialog

01-15-2013 06:07 PM in reply to: norman.yuan
Thanks, I tried all of the calls below, but still nothing happens until the dialog is closed. AcMapMap.ForceScreenRefresh() ed.Regen() System.Windows.Forms.Application.DoEvents()
Distinguished Contributor
quigs
Posts: 143
Registered: ‎09-30-2008
Message 18 of 18 (233 Views)

Re: Zoom from modal dialog

01-16-2013 04:01 AM in reply to: sfinch1

Hi,

I use this code and it works Ok for me.  It is called from a button:

 

 

    Dim Insp As Point3d = New Point3d(500, 500, 0)
    Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication
    AcApp = CType(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, Autodesk.AutoCAD.Interop.AcadApplication)
    AcApp.ZoomCenter(Insp.ToArray(), 1000)
    Application.DocumentManager.MdiActiveDocument.Editor.Regen()

 

My name is Martin.. :smileyvery-happy:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community