找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 669|回复: 0

[ARX程序]:C#代码forCAD2007-2008 抛砖引玉,望大家多发些代码来.

[复制链接]
发表于 2007-5-11 10:13:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
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();
      }
    }
  }
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-24 02:34 , Processed in 0.273588 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表