Author Topic: Viewport - match standard scale and annotation scale  (Read 2648 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Viewport - match standard scale and annotation scale
« on: June 08, 2017, 04:37:14 PM »
I have a command the create viewport with a specific scale.  I have no problem setting the customscale but I'm having an error when setting the annotationscale.
So far here is what I have, I'm getting the error on line vp.Annotative = AnnotativeStates.True;

(vp = viewport, aaa = AnnotationScale)

Code - C#: [Select]
  1. vp.CustomScale = aaa.Scale;
  2. vp.Annotative = AnnotativeStates.True;
  3. vp.AddContext(aaa);
  4. vp.AnnotationScale = aaa;

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Viewport - match standard scale and annotation scale
« Reply #1 on: June 09, 2017, 09:47:21 AM »
I think I have done this before and would need to go back and look but I think that error is because a viewport is not "annotative". It has a annotation scale but is not a annotative object.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Viewport - match standard scale and annotation scale
« Reply #2 on: June 09, 2017, 10:52:29 AM »
I think Jeff is right.  You can set the annotative scale but you cannot set the annotative property of the viewport.  The exception tells you that it is notimplemented yet.  So... you cannot use it.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

latour_g

  • Newt
  • Posts: 184
Re: Viewport - match standard scale and annotation scale
« Reply #3 on: June 13, 2017, 10:43:18 AM »
Well at first I only had vp.AnnotationScale = aaa but this alone was giving me an exception. 
See image. 
(aaa was found in existing annotation scale)

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Viewport - match standard scale and annotation scale
« Reply #4 on: June 14, 2017, 08:48:07 PM »
I just did a quick test and it worked for me I set the viewport.AnnotationScale to Database.CannoScale

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Viewport - match standard scale and annotation scale
« Reply #5 on: June 14, 2017, 09:14:37 PM »
I also tried setting it from a annotation scale I found in contextmanager and it worked.
I tried setting a viewport that was already database resident maybe try that?

Code - C#: [Select]
  1.         private static IntPtr ptrViewport = RXObject.GetClass(typeof(Viewport)).UnmanagedObject;
  2.         [CommandMethod("VpAnnoScale", CommandFlags.NoTileMode)]
  3.         public void VpAnnoScale()
  4.         {
  5.             var options = new PromptEntityOptions("\nSelect a ViewPort or its Boundry");
  6.             options.SetRejectMessage("\nSelect ViewPort");
  7.  
  8.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Viewport), false);
  9.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Circle), false);
  10.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);
  11.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline2d), false);
  12.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), false);
  13.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Ellipse), false);
  14.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Region), false);
  15.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Spline), false);
  16.             options.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Face), false);
  17.  
  18.             ObjectId vpId = ObjectId.Null;
  19.             while (vpId == ObjectId.Null)
  20.             {
  21.                 PromptEntityResult acSSPrompt = Ed.GetEntity(options);
  22.  
  23.                 if (acSSPrompt.Status != PromptStatus.OK)
  24.                 {
  25.                     return;
  26.                 }
  27.  
  28.                 vpId = acSSPrompt.ObjectId;
  29.                 if (vpId.ObjectClass.UnmanagedObject != ptrViewport)
  30.                 {
  31.                     vpId = LayoutManager.Current.GetNonRectangularViewportIdFromClipId(vpId);
  32.                 }
  33.             }
  34.  
  35.            
  36.             using (var temp = new TemporarySystemVariables() { CMDECHO = false, ATTDIA = false })
  37.             {
  38.                 using (Transaction trx = Doc.TransactionManager.StartTransaction())
  39.                 {
  40.                     Viewport vp = vpId.GetEntity<Viewport>(OpenMode.ForWrite);
  41.                     //vp.AnnotationScale = Db.Cannoscale;
  42.  
  43.                     ObjectContextManager ocm = Db.ObjectContextManager;
  44.                     ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
  45.                     foreach (var objcon in occ)
  46.                     {
  47.                        if(objcon.Name.StartsWith("1/8"))
  48.                        {
  49.                            vp.AnnotationScale = (AnnotationScale)objcon;
  50.                        }
  51.                     }
  52.                     trx.Commit();
  53.                 }
  54.  
  55.              
  56.                
  57.             }
  58.         }
  59.  
  60.  

latour_g

  • Newt
  • Posts: 184
Re: Viewport - match standard scale and annotation scale
« Reply #6 on: June 15, 2017, 09:25:21 AM »
THANK YOU JEFF !!  :-D
You are right, it need to be in the database first.  Like that it's working fine :

Code - C#: [Select]
  1. btr.AppendEntity(dTxt);
  2. tr.AddNewlyCreatedDBObject(dTxt, true);
  3. btr.AppendEntity(vp);
  4. tr.AddNewlyCreatedDBObject(vp, true);
  5. vp.On = true;
  6.  
  7. vp.AnnotationScale = aaa;
  8.  
  9. tr.Commit();
  10.  

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Viewport - match standard scale and annotation scale
« Reply #7 on: June 18, 2017, 09:34:25 PM »

Good pickup Jeff !

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.