zoom with object in Layout-Viewports

zoom with object in Layout-Viewports

VallimanalanT
Enthusiast Enthusiast
640 Views
1 Reply
Message 1 of 2

zoom with object in Layout-Viewports

VallimanalanT
Enthusiast
Enthusiast

Hi,

 

Am trying to assign a view in layout-viewport through Zoom-->object-->Single-->Groupname (from modelspace). the command execution is not working properly and also unable switch from modelspace to paperspace in layout

 

 [CommandMethod("LayoutsViews")]
        public void LayoutsViews()
        {
            // Get the current document and database
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            acCurDb.TileMode = false;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBDictionary layoutIDs = acTrans.GetObject(acCurDb.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;

                // Reference the Layout Manager
                LayoutManager acLayoutMgr = LayoutManager.Current;

                // Step through and list each named layout and Model
                foreach (DBDictionaryEntry layoutID in layoutIDs)
                {
                    
                    Layout CurrentLo = acTrans.GetObject(layoutID.Value, OpenMode.ForRead) as Layout;

                    string layoutName = CurrentLo.LayoutName.ToUpper().ToString();

                    if ((layoutName != "LAYOUT1") && (layoutName != "LAYOUT2") && (layoutName != "MODEL"))
                    {
                        //this.viewPort(CurrentLo, layoutName);
                        ObjectIdCollection idCollection = CurrentLo.GetViewports();

                        foreach (ObjectId ID in idCollection)
                        {
                            Viewport VP = acTrans.GetObject(ID, OpenMode.ForRead) as Viewport;

                            if (VP != null)
                            {
                                VP.UpgradeOpen();
                                VP.On = true;
                                VP.SetDatabaseDefaults();
                                VP.Visible = true;

                                // Activate model space in the viewport
                                acDoc.Editor.SwitchToModelSpace();

                                string command = string.Empty;

                                command = "._zoom _Object _SIngle _Group " + layoutName.ToString() + " ";

                                acDoc.SendStringToExecute(command, true, false, true);

                                acDoc.SendStringToExecute("._regen ", true, false, false);

                                VP.UpdateDisplay();

                                break;

                            }
                        }

                    }
                        ////Activate model space in the viewport
                        //acDoc.Editor.SwitchToPaperSpace();
                    }

                    //Activate model space in the viewport
                    // acDoc.Editor.SwitchToPaperSpace();
                    // Abort the changes to the database
                    acTrans.Commit();
                }
            }
0 Likes
Accepted solutions (1)
641 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

SenStringToExecute runs asynchronously (i.e. after the method ended).

If you target AutoCAD 2015 or later, you can use the Editor.Command() method.

 

ed.Command("._zoom", "_Object", "_Group ", layoutName, "");


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes