- UID
- 110840
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-3-8
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
C#-add a new annotative scale
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Internal;
namespace AnnotationScaling
{
public class Commands
{
[CommandMethod("ADS")]
static public void addScale()
{
Dcument doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
try
{
ObjectContextManager ocm =
db.ObjectContextManager;
if (ocm != null)
{
// Now get the Annotation Scaling context collection
// (named ACDB_ANNOTATIONSCALES_COLLECTION)
ObjectContextCollection occ =
ocm.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());
}
}
[CommandMethod("ATS")]
static public void attachScale()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectContextManager ocm =
db.ObjectContextManager;
ObjectContextCollection occ =
ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
Transaction tr =
doc.TransactionManager.StartTransaction();
using (tr)
{
PromptEntityOptions opts =
new PromptEntityOptions("\nSelect entity: ");
opts.SetRejectMessage(
"\nEntity must support annotation scaling."
);
opts.AddAllowedClass(typeof(DBText), false);
opts.AddAllowedClass(typeof(MText), false);
opts.AddAllowedClass(typeof(Dimension), false);
opts.AddAllowedClass(typeof(Leader), false);
opts.AddAllowdClass(typeof(Hatch), false);
PromptEntityResult per = ed.GetEntity(opts);
if (per.ObjectId != ObjectId.Null)
{
DBObject obj =
tr.GetObject(per.ObjectId, OpenMode.ForRead);
if (obj != null)
{
obj.UpgradeOpen();
obj.Annotative = AnnotativeStates.True;
ObjectContexts.AddContext(obj, occ.GetContext("1:1"));
ObjectContexts.AddContext(obj, occ.GetContext("1:2"));
ObjectContexts.AddContext(obj, occ.GetContext("1:10"));
ObjectContext oc = occ.GetContext("MyScale 1:28");
if (oc != null)
{
ObjectContexts.AddContext(obj, oc);
}
}
}
tr.Commit();
}
}
}
} |
|