TheSwamp

Code Red => .NET => Topic started by: latour_g on June 08, 2017, 04:37:14 PM

Title: Viewport - match standard scale and annotation scale
Post by: latour_g 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;
Title: Re: Viewport - match standard scale and annotation scale
Post by: Jeff H 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.
Title: Re: Viewport - match standard scale and annotation scale
Post by: Keith Brown 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.
Title: Re: Viewport - match standard scale and annotation scale
Post by: latour_g 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)
Title: Re: Viewport - match standard scale and annotation scale
Post by: Jeff H 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
Title: Re: Viewport - match standard scale and annotation scale
Post by: Jeff H 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.  
Title: Re: Viewport - match standard scale and annotation scale
Post by: latour_g 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.  
Title: Re: Viewport - match standard scale and annotation scale
Post by: kdub_nz on June 18, 2017, 09:34:25 PM

Good pickup Jeff !