vince1327 Posted November 14, 2011 Share Posted November 14, 2011 (edited) 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 November 14, 2011 by vince1327 Quote Link to comment Share on other sites More sharing options...
ReMark Posted November 14, 2011 Share Posted November 14, 2011 You want to apply the scale to both the objects in model space and the viewports in your paper space layout? Quote Link to comment Share on other sites More sharing options...
vince1327 Posted November 14, 2011 Author Share Posted November 14, 2011 I just double checked, it actually only needs to apply to the paper space layouts Quote Link to comment Share on other sites More sharing options...
ReMark Posted November 14, 2011 Share Posted November 14, 2011 That's good. You had me confused there for a moment. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted November 14, 2011 Share Posted November 14, 2011 Please read the CODE POSTING GUIDELINES. Quote Link to comment Share on other sites More sharing options...
vince1327 Posted November 14, 2011 Author Share Posted November 14, 2011 Apologies, I'm assuming the issue was with the formatting, it has now been fixed, sorry for being a bother. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted November 14, 2011 Share Posted November 14, 2011 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. Quote Link to comment Share on other sites More sharing options...
Jeff H Posted November 14, 2011 Share Posted November 14, 2011 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) Quote Link to comment Share on other sites More sharing options...
vince1327 Posted November 16, 2011 Author Share Posted November 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Jeff H Posted November 17, 2011 Share Posted November 17, 2011 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(); } } Quote Link to comment Share on other sites More sharing options...
vince1327 Posted November 17, 2011 Author Share Posted November 17, 2011 Thanks for the help, i'll give it a shot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.