Thanks to Nikolay Poleshchuk and Roland Feletic for suggesting this topic, and to Wayne Brill, from DevTech Americas, for providing the code.
In this post we're going to look at some functionality that's specific to AutoCAD 2008 - adding a new annotative scale to a drawing. The next post (assuming I can work out how to do it :-) will cover how you can attach a scale programmatically to make an entity annotative.
Firstly, I should cover what the annotation scaling feature is all about...
Here's a quick overview from the AutoCAD 2008 online help:
Objects that are commonly used to annotate drawings have a property called Annotative. This property allows you to automate the process of scaling annotations so that they plot or display at the correct size on the paper.
Instead of creating multiple annotations at different sizes and on separate layers, you can turn on the annotative property by object or by style, and set the annotation scale for layout or model viewports. The annotation scale controls the size of the annotative objects relative to the model geometry in the drawing.
The following objects are commonly used to annotate drawings and contain an annotative property:
- Text
- Dimensions
- Hatches
- Tolerances
- Multileaders
- Blocks
- Attributes
When the Annotative property for these objects is turned on (set to Yes), these objects are called annotative objects.
Here's some code in C# that creates a new annotation scale and adds it to the active drawing in AutoCAD:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace AnnotationScaling
{
public class Commands
{
[CommandMethod("AS")]
static public void addScale()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
ObjectContextManager cm =
db.ObjectContextManager;
if (cm != null)
{
// Now get the Annotation Scaling context collection
// (named ACDB_ANNOTATIONSCALES_COLLECTION)
ObjectContextCollection occ =
cm.GetContextCollection("ACDB_ANNOTATIONSCALES");
if (occ != null)
{
// Create a brand new scale context
AnnotationScale asc = new AnnotationScale();
asc.Name = "MyScale 1:28";
asc.PaperUnits = 1;
asc.DrawingUnits = 28;
// Add it to the drawing's context collection
occ.AddContext(asc);
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
}
}
}
Here's the new annotation scale, selected manually in the Property Palette after running the code:
In the next post we'll look at what it takes to make an object annotative programmatically, by setting its annotative property and annotation scale.


Subscribe via RSS
Kean, thank you. Before using your code I should add that AutoCAD documentation is not perfectly exact. The legacy leader object can be annotative too but scale influence on it is sometimes inpredictable.
Posted by: Nikolay Poleshchuk | April 25, 2007 at 07:51 AM
Thank you, Kean. Now i'm really curious about making an object annotative.
Posted by: Roland Feletic | April 25, 2007 at 09:50 AM
Hi all,
Can we reset the scale list in ACAD 2008 using .NET?
Thanks
Posted by: anonymous | February 13, 2008 at 08:13 AM
You should be able to enumerate the annotation scales in the ObjectContextCollection, and call RemoveContext() on each one. I haven't tried it, though.
Kean
Posted by: Kean | February 13, 2008 at 10:40 AM
how do you get the current drawing's current annotation scale object, i need that number as a factor on my program. thank you.
Posted by: wang890 | June 10, 2009 at 12:44 AM
Check the CANNOSCALE system variable (also accesible via the Database.Cannoscale property).
Kean
Posted by: Kean Walmsley | June 10, 2009 at 09:04 AM