Jump to content

Scale Viewports


vince1327

Recommended Posts

Hey Everyone,

 

Right now i'm trying to create a command that will allow a user to input a default viewport size when creating a drawing however i'm stuck on a few things. The first is how do i make it so that this default viewport size applies to both model space and all layouts, or does this happen automatically? The second is how to I actually set the custom viewport size using c#?

 

Below is some code that allows me to query the scale of an existing viewport.

[CommandMethod("CHVScale")]
       public void CurrentVportScale()
       {
           Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
           ObjectId vpid = ed.CurrentViewportObjectId;
           using (Transaction tr =
           ed.Document.TransactionManager.StartTransaction())
           {
               Viewport vport = (Viewport)tr.GetObject(vpid, OpenMode.ForRead);
               ed.WriteMessage(vport.CustomScale.ToString());

           }
       }

I attempted to change the last few lines to

vport.CustomScale.Equals(2:1);
tr.commit();
tr.dispose();

but to no avail. Any insight would be appreciated. For what it's worth, i have a command the runs previous (but can run after) that creates "x" number of layouts based on user input, so these layouts will also need to accept the new viewport scale.

 

Thanks in advance!

Edited by vince1327
Link to comment
Share on other sites

Apologies, I'm assuming the issue was with the formatting, it has now been fixed, sorry for being a bother.

 

You are not a bother and thanks for placing your code in tags. :thumbsup:

Link to comment
Share on other sites

StandardScale can be set with StandardScaleType enum

if it is not a standard scale you can set it with CustomScale property(You can set it with Custom Scale property even if it is Standard scale but pass in the 'doulble' value)

Link to comment
Share on other sites

Thanks for the assistance so far, much appreciated. Is there an example of how to do this somewhere in the developers manual or somewhere else. I'm still a bit lost and my code seems to throw an awful lot of fatal errors.

Link to comment
Share on other sites

Like I mentioned in earlier post you change it with standard scale and pass one of the enumerated values

 

 [CommandMethod("StandardScaleViewPort")]
       public void StandardScaleViewPort()
       {
           Document doc = Application.DocumentManager.MdiActiveDocument;
           Database db = doc.Database;
           Editor ed = doc.Editor;
           using (Transaction trx = db.TransactionManager.StartTransaction())
           {
               PromptEntityOptions peo = new PromptEntityOptions("\nSelect Viewport: ");
               peo.SetRejectMessage("\nInvalid selection...");
               peo.AddAllowedClass(typeof(Viewport), true);
               PromptEntityResult per = ed.GetEntity(peo);
               if (per.Status != PromptStatus.OK)
               {
                   return;
               }
               Viewport vp = trx.GetObject(per.ObjectId, OpenMode.ForWrite) as Viewport;

               vp.StandardScale = StandardScaleType.Scale1To8inchAnd1ft;

               trx.Commit();
           }
       }

 

Or you use custom scale and pass in a double, this is same as first command except it ask for a scale and uses customscale property

 

  [CommandMethod("CustomScaleViewport")]
          public void CustomScaleViewport()
          {
              Document doc = Application.DocumentManager.MdiActiveDocument;
              Database db = doc.Database;
              Editor ed = doc.Editor;
              using (Transaction trx = db.TransactionManager.StartTransaction())
              {             
                  PromptEntityOptions peo = new PromptEntityOptions("\nSelect Viewport: ");
                  peo.SetRejectMessage("\nInvalid selection...");
                  peo.AddAllowedClass(typeof(Viewport), true);
                  PromptEntityResult per = ed.GetEntity(peo);
                  if (per.Status != PromptStatus.OK)
                  {
                      return;
                  }
                  Viewport vp = trx.GetObject(per.ObjectId, OpenMode.ForWrite) as Viewport;
                  PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter Scale");
                  PromptDoubleResult pdr = ed.GetDouble(pdo);
                  if (pdr.Status != PromptStatus.OK)
                  {
                      return;
                  }
                  vp.CustomScale = pdr.Value;

                  trx.Commit();
              }
          }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...