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.