.NetArx终于在2010版实现了自定义实体的子集--规则重定义,算是个好消息,
虽然很晚,而且功能没有ObjectArx的自定义实体强,但好歹没有强:)
下面的例子利用多行文字重定义为序号球,
更多的相关例子请看
nnx4jfp0hci.JPG
-
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.GraphicsInterface;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- [assembly: CommandClass(typeof(TlsCad.XhqHelper))]
- [assembly: ExtensionApplication(typeof(TlsCad.TlsApplication))]
- namespace TlsCad
- {
- class TlsApplication : IExtensionApplication
- {
- void IExtensionApplication.Initialize()
- {
- XhqHelper.OverruleStart();
- Overrule.Overruling = true;
- }
- void IExtensionApplication.Terminate()
- {
- XhqHelper.OverruleEnd();
- Overrule.Overruling = false;
- }
- }
- #region Helper
- static class XhqHelper
- {
- public readonly static string RegAppName = "TlsCad.Xhq";
- public readonly static double Radius = 8;
- public readonly static double TextHeight = 8;
- //获取起点
- public static Point3d GetPoint(MText mtxt)
- {
- ResultBuffer rb = mtxt.GetXDataForApplication(RegAppName);
- return (Point3d)rb.AsArray()[1].Value;
- }
- //设置起点,注意这里使用1011组码保存点,支持Copy、Move、Mirror等命令时实时更新XData
- public static void SetPoint(MText mtxt, Point3d point)
- {
- ResultBuffer rb = new ResultBuffer(new TypedValue[] { new TypedValue(1001, RegAppName), new TypedValue(1011, point) });
- mtxt.XData = rb;
- }
- [CommandMethod("xh")]
- public static void XHQ()
- {
- PromptIntegerResult res1 = CadHelper.Editor.GetInteger(new PromptIntegerOptions("\n请输入序号:"));
- PromptPointResult res2 = CadHelper.Editor.GetPoint(new PromptPointOptions("\n请输入起点:"));
- XhqJig jig = new XhqJig(res2.Value, res1.Value.ToString());
- PromptResult res = CadHelper.Editor.Drag(jig); if (res.Status == PromptStatus.OK)
- {
- Database db = Application.DocumentManager.MdiActiveDocument.Database;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTableRecord btr =
- (BlockTableRecord)tr.GetObject(
- db.CurrentSpaceId,
- OpenMode.ForWrite,
- false);
- MText mtxt = jig.GetEntity();
- btr.AppendEntity(mtxt);
- tr.AddNewlyCreatedDBObject(mtxt, true);
- RegAppTable rat =
- (RegAppTable)tr.GetObject(
- db.RegAppTableId,
- OpenMode.ForRead,
- false);
- if (!rat.Has(RegAppName))
- {
- rat.UpgradeOpen();
- RegAppTableRecord regapp = new RegAppTableRecord();
- regapp.Name = RegAppName;
- rat.Add(regapp);
- tr.AddNewlyCreatedDBObject(regapp, true);
- }
- SetPoint(mtxt, res2.Value);
- tr.Commit();
- }
- }
- } public static void OverruleStart()
- {
- Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), XhqDrawOverrule.TheOverrule, false);
- Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), XhqGripOverrule.TheOverrule, false);
- Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), XhqOsnapOverrule.TheOverrule, false);
- Overrule.AddOverrule(RXObject.GetClass(typeof(MText)), XhqTransformOverrule.TheOverrule, false);
- }
- public static void OverruleEnd()
- {
- Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), XhqDrawOverrule.TheOverrule);
- Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), XhqGripOverrule.TheOverrule);
- Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), XhqOsnapOverrule.TheOverrule);
- Overrule.RemoveOverrule(RXObject.GetClass(typeof(MText)), XhqTransformOverrule.TheOverrule);
- }
- }
- #endregion
- #region Jig
- //序号球拖动类
- class XhqJig : DrawJig
- {
- Point3d m_Location;
- Line m_Line;
- MText m_MText;
- Circle m_Circle;
- public XhqJig(Point3d FirstPoint, string No)
- {
- m_MText = new MText();
- m_MText.Attachment = AttachmentPoint.MiddleCenter;
- m_MText.Location = FirstPoint;
- m_MText.TextHeight = XhqHelper.TextHeight;
- m_MText.Contents = No;
- m_Line = new Line(FirstPoint, FirstPoint);
- m_Circle = new Circle();
- m_Circle.Center = FirstPoint;
- m_Circle.Radius = XhqHelper.Radius;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptPointOptions jigOpts = new JigPromptPointOptions();
|