1、说明
可进行缩放性注释的对象有:文字、标注、图案填充、公差、多重引线、块及属性。
2、为图形添加、删除注释比例步骤
1)使用AnnotationScale类(在DatabaseServices命名空间下)构造函数创建注释比例对象并设置相关属性;
2)使用图形的注释比例列表(ObjectContextCollection);
3)使用(ObjectContextCollection类)的AddText函数将新建的注释比例对象添加到注释比例列表中。
2、具体代码
1 public static AnnotationScale AddScale(this Database db, string scaleName, double paperUnits, double drawdingUnits) 2 { 3 AnnotationScale scale = null; 4 5 ObjectContextManager manager = db.ObjectContextManager; 6 7 //获得当前图形的注释比例列表,名为“ACDB_ANNOTATIONSCALES” 8 ObjectContextCollection occ = manager.GetContextCollection("ACDB_ANNOTATIONSCALES"); 9 10 if (!occ.HasContext(scaleName)) 11 { 12 scale = new AnnotationScale(); 13 scale.Name = scaleName; 14 15 scale.PaperUnits = paperUnits; 16 scale.DrawingUnits = drawdingUnits; 17 occ.AddContext(scale); 18 } 19 return scale; 20 21 }
1 /// <summary> 2 /// 为实体添加指定的注释比例 3 /// </summary> 4 /// <param name="entId">实体的ObjectId</param> 5 /// <param name="scaleNames">注释比例名列表</param> 6 public static void AttachScale(this ObjectId entId, params string[] scaleNames) 7 { 8 Database db = entId.Database; 9 10 DBObject obj = entId.GetObject(OpenMode.ForRead);//获取entID的实体对象 11 12 if (obj.Annotative != AnnotativeStates.NotApplicable)//如果实体支持注释缩 放 13 { 14 if (obj is BlockReference) 15 { 16 BlockReference br = obj as BlockReference; 17 //打开对应的块表记录 18 BlockTableRecord btr = (BlockTableRecord)br.BlockTableRecord.GetObject(OpenMode.ForWrite); 19 //设置块表记录为可注释缩放 20 btr.Annotative = AnnotativeStates.True; 21 } 22 else if (obj.Annotative == AnnotativeStates.False) 23 obj.Annotative = AnnotativeStates.True; 24 25 obj.UpgradeOpen();//切换实体为写的状态以添加注释比例 26 //获取当前图形的对象比例管理器 27 ObjectContextManager ocm = db.ObjectContextManager; 28 29 //获得当前的图形的注释比例列表, 30 ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES"); 31 foreach (string scaleName in scaleNames) 32 { 33 //获取名为scaleName的注释比例 34 ObjectContext scale = occ.GetContext(scaleName); 35 //若不存在scaleName的注释比例,则结束本次循环 36 if (scale == null) continue; 37 //为实体添加名为scaleName的注释比例 38 39 ObjectContexts.AddContext(obj, scale);// ObjectContexts要添加acmgdinternal.dll引用 40 } 41 obj.DowngradeOpen();//为了安全将实体切换为读的状态 42 } 43 44 }