用AutoCAD.NET二次开发目前还不支持自定义对象,不过我们可以用一些其他的方法来实现自定义对象的效果,规则重定义可以控制对象的显示效果,即线可以显示成一根管,点可以显示成一个圆。下面看看规则重定义的例子把AutoCAD里面的直线变成一个空心管。 using System;
- <div align="left"><font color="#696969" face="Calibri" size="2">using Autodesk.AutoCAD.DatabaseServices;</font></div><div align="left"><font color="#696969" face="Calibri" size="2">using Autodesk.AutoCAD.Geometry;</font></div><div align="left"><font color="#696969" face="Calibri" size="2">using Autodesk.AutoCAD.Runtime;</font></div><div align="left"><font color="#696969" face="Calibri" size="2">using Autodesk.AutoCAD.GraphicsInterface;</font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2">[assembly: CommandClass(typeof(Sample.LineToPipeOverule))]</font></div><div align="left"><font color="#696969" face="Calibri" size="2">namespace Sample</font></div><div align="left"><font color="#696969" face="Calibri" size="2">{</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> class LineToPipeOverule</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> [CommandMethod("LineToPipe")]</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public void Start()</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> LineToPipe line=new LineToPipe(10);</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> StartOverRule(RXClass.GetClass(typeof(Line)), line); </font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2"> [CommandMethod("EndOverRule")]</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public void End()</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> EndOverRule();</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// <summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// 启动重定义</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// </summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// <param name="CADClass">要重定义的类型</param></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// <param name="overrule">把要重定义的类型定义为的对象</param></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public static void StartOverRule(RXClass CADClass, Overrule overrule)</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> Overrule.AddOverrule(CADClass, overrule, false);</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> Overrule.Overruling = true;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// <summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// 关闭重定义</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// </summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public static void EndOverRule()</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> Overrule.Overruling = false;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2">
- </font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// <summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// 线显示成管</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> /// </summary></font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public class LineToPipe : DrawableOverrule</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> private double r;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public LineToPipe(double R)</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> r = R;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> public override bool WorldDraw(Drawable drawable, WorldDraw wd)</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> if (drawable is Line)</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> {</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> Line line = (Line)drawable;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> Circle circle = new Circle(line.StartPoint, line.EndPoint - line.StartPoint, r);</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> ExtrudedSurface pipe = new ExtrudedSurface();</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> pipe.CreateExtrudedSurface(circle, line.EndPoint - line.StartPoint, new SweepOptions());</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> pipe.WorldDraw(wd);</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> circle.Dispose();</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> pipe.Dispose();</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> return true;</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2"> }</font></div><div align="left"><font color="#696969" face="Calibri" size="2">}</font></div>
复制代码
|