Using the .NET API to add a scale to a drawing

By Virupaksha Aithal

Below C# code shows the procedure to add a scale to scale list.

[CommandMethod("AddScale")]
static public void addScale()
{
 Document doc = Application.DocumentManager.MdiActiveDocument;
 Database db = doc.Database;
 // next get the objectContextManager            
 try
 {
     ObjectContextManager contextManager = 
                                    db.ObjectContextManager;
     // if ok                
     if (contextManager != null)
     {
         // now get the Annotation Scaling context collection 
         // (named ACDB_ANNOTATIONSCALES_COLLECTION)                    
         ObjectContextCollection contextCollection =
           contextManager.GetContextCollection(
                                    "ACDB_ANNOTATIONSCALES");
         // if ok                    
         if (contextCollection != null)
         {
             // create a brand new scale context                        
             AnnotationScale annotationScale = 
                                    new AnnotationScale();
             annotationScale.Name = "WBScale2 1:28";
             annotationScale.PaperUnits = 1;
             annotationScale.DrawingUnits = 28;
             // now add to the drawing's context collection                        
             contextCollection.AddContext(annotationScale);
         }
     }
 }
 catch (System.Exception ex)
 {
     Editor ed = doc.Editor;
     ed.WriteMessage(ex.ToString());
 }
}

Comments

2 responses to “Using the .NET API to add a scale to a drawing”

  1. David Prontnicki Avatar
    David Prontnicki

    I have added a list of scales to this, how can this be modified to check if annoscale is there already and ignore if already exists?

  2. Alexandre Avatar
    Alexandre

    if !(contextCollection.hascontext(annotationScale.Name)) contextCollection.AddContext(annotationScale);

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading