Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API: Zoom in Civil 3D doesn´t work?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
joantopo
921 Views, 4 Replies

API: Zoom in Civil 3D doesn´t work?

I have this:

[CommandMethod("ZoomCenter")]
static public void ZoomCenter()
{
  // Center the view at 5,5,0
  Zoom(new Point3d(), new Point3d(), new Point3d(5, 5, 0), 1);
}

 and

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
 
static void Zoom(Point3d pMin, Point3d pMax, Point3d pCenter, double dFactor)
{
  // Get the current document and database
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  Database acCurDb = acDoc.Database;
 
  int nCurVport = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));
 
  // Get the extents of the current space no points 
  // or only a center point is provided
  // Check to see if Model space is current
  if (acCurDb.TileMode == true)
  {
      if (pMin.Equals(new Point3d()) == true && 
          pMax.Equals(new Point3d()) == true)
      {
          pMin = acCurDb.Extmin;
          pMax = acCurDb.Extmax;
      }
  }
  else
  {
      // Check to see if Paper space is current
      if (nCurVport == 1)
      {
          // Get the extents of Paper space
          if (pMin.Equals(new Point3d()) == true && 
              pMax.Equals(new Point3d()) == true)
          {
              pMin = acCurDb.Pextmin;
              pMax = acCurDb.Pextmax;
          }
      }
      else
      {
          // Get the extents of Model space
          if (pMin.Equals(new Point3d()) == true && 
              pMax.Equals(new Point3d()) == true)
          {
              pMin = acCurDb.Extmin;
              pMax = acCurDb.Extmax;
          }
      }
  }
 
  // Start a transaction
  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  {
      // Get the current view
      using (ViewTableRecord acView = acDoc.Editor.GetCurrentView())
      {
          Extents3d eExtents;
 
          // Translate WCS coordinates to DCS
          Matrix3d matWCS2DCS;
          matWCS2DCS = Matrix3d.PlaneToWorld(acView.ViewDirection);
          matWCS2DCS = Matrix3d.Displacement(acView.Target - Point3d.Origin) * matWCS2DCS;
          matWCS2DCS = Matrix3d.Rotation(-acView.ViewTwist,
                                         acView.ViewDirection,
                                         acView.Target) * matWCS2DCS;
 
          // If a center point is specified, define the min and max 
          // point of the extents
          // for Center and Scale modes
          if (pCenter.DistanceTo(Point3d.Origin) != 0)
          {
              pMin = new Point3d(pCenter.X - (acView.Width / 2),
                                 pCenter.Y - (acView.Height / 2), 0);
 
              pMax = new Point3d((acView.Width / 2) + pCenter.X,
                                 (acView.Height / 2) + pCenter.Y, 0);
          }
 
          // Create an extents object using a line
          using (Line acLine = new Line(pMin, pMax))
          {
              eExtents = new Extents3d(acLine.Bounds.Value.MinPoint,
                                       acLine.Bounds.Value.MaxPoint);
          }
 
          // Calculate the ratio between the width and height of the current view
          double dViewRatio;
          dViewRatio = (acView.Width / acView.Height);
 
          // Tranform the extents of the view
          matWCS2DCS = matWCS2DCS.Inverse();
          eExtents.TransformBy(matWCS2DCS);
 
          double dWidth;
          double dHeight;
          Point2d pNewCentPt;
 
          // Check to see if a center point was provided (Center and Scale modes)
          if (pCenter.DistanceTo(Point3d.Origin) != 0)
          {
              dWidth = acView.Width;
              dHeight = acView.Height;
 
              if (dFactor == 0)
              {
                  pCenter = pCenter.TransformBy(matWCS2DCS);
              }
 
              pNewCentPt = new Point2d(pCenter.X, pCenter.Y);
          }
          else // Working in Window, Extents and Limits mode
          {
              // Calculate the new width and height of the current view
              dWidth = eExtents.MaxPoint.X - eExtents.MinPoint.X;
              dHeight = eExtents.MaxPoint.Y - eExtents.MinPoint.Y;
 
              // Get the center of the view
              pNewCentPt = new Point2d(((eExtents.MaxPoint.X + eExtents.MinPoint.X) * 0.5),
                                       ((eExtents.MaxPoint.Y + eExtents.MinPoint.Y) * 0.5));
          }
 
          // Check to see if the new width fits in current window
          if (dWidth > (dHeight * dViewRatio)) dHeight = dWidth / dViewRatio;
 
          // Resize and scale the view
          if (dFactor != 0)
          {
              acView.Height = dHeight * dFactor;
              acView.Width = dWidth * dFactor;
          }
 
          // Set the center of the view
          acView.CenterPoint = pNewCentPt;
 
          // Set the current view
          acDoc.Editor.SetCurrentView(acView);
      }
 
      // Commit the changes
      acTrans.Commit();
  }
}

 Both code block  are original from:

http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-FAC1A5EB-2D9E-497B-8FD9-E11D2FF87B93...

 

I´m using Civil 3D 2013 but I type the command "ZoomCenter", the center point of zoom isn´t in (5,5).

 

What´s the matter?

Thank you.

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
4 REPLIES 4
Message 2 of 5
Partha.Sarkar
in reply to: joantopo

Hi,

 

Is this behavior specific to a DWG file ? Does it work fine in any other DWG file ?

I didn't try to debug your code here to see what's happening, but in-general you would see many code snippet on Zoom functionality to test and see if something going wrong in your code vs the available code snippets.

 

Here is a link of code snippet in ADN AutoCAD DevBlog -

http://adndevblog.typepad.com/autocad/2012/07/implementing-zoom-commands-with-net.html

 

Does it help ?

Thanks,

Partha



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 3 of 5
joantopo
in reply to: Partha.Sarkar

Hi Partha.

I have the same trouble with this code block:

 

  public static void ZoomToPoint( Autodesk.AutoCAD.Geometry.Point2d center, double scale)
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            //get the current view
            ViewTableRecord view = ed.GetCurrentView();
            //start transaction
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //get the entity' extends
                //configure the new current view
                view.Width = view.Width * scale;
                view.Height = view.Height * scale;
                view.CenterPoint = new Autodesk.AutoCAD.Geometry.Point2d(center.X, center.Y);

                //update the view
                ed.SetCurrentView(view);
                trans.Commit();
               
            }
        }

 default scale value is 1.

 

I don´t understand what happen.

I check center.X and center.Y in debugger and they are right but in drawing they aren´t the center.

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 4 of 5
joantopo
in reply to: joantopo

Hi. 

With imperial units drawing, it works well, but I´m using metric drawings.

I use SCP=Universal.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 5 of 5
joantopo
in reply to: joantopo

Solved, it´s not depend if drawing is imperial or metric.

 

This line is the solution:

"view.Target = new Autodesk.AutoCAD.Geometry.Point3d(0,0,0);" because my drawing uses other target.

 

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report