|
- <li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">/////////////////////////////////////////////////////////////////////////////////////////////////</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">//深入浅出AutoCAD二次开发(李冠亿)</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">//http://www.bimcad.org</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">/////////////////////////////////////////////////////////////////////////////////////////////////</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">using System;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">using Autodesk.AutoCAD.DatabaseServices;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">using Autodesk.AutoCAD.Geometry;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">using Autodesk.AutoCAD.Runtime;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">[assembly: CommandClass(typeof(Sample.AddSolid))]</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">namespace Sample</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">{</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> class AddSolid</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> [CommandMethod("AddSolid")]</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> public void Add()</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid3d T = Torus(200, 30);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Move(T, new Point3d(100, 100, 0));</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> ToModelSpace(T);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid3d B = Box(100, 300,100);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Move(B, new Point3d(-300, -300, 0));</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> ToModelSpace(B);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// 添加对象到模型空间</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// </summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="ent">要添加的对象</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <returns></returns></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> public static ObjectId ToModelSpace(Entity ent)</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Database db = HostApplicationServices.WorkingDatabase;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> ObjectId entId;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> using (Transaction trans = db.TransactionManager.StartTransaction())</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> entId = btr.AppendEntity(ent);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> trans.AddNewlyCreatedDBObject(ent, true);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> trans.Commit();</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> return entId;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// 圆环</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// </summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="MajorRadius">主圆半径</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="MinorRadius">圆环半径</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <returns></returns></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> public static Solid3d Torus(double MajorRadius, int MinorRadius)</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid3d Solid = new Solid3d();</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid.CreateTorus(MajorRadius, MinorRadius);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> return Solid;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// 创建长方体</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// </summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="X">长</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="Y">宽</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="Z">高</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <returns></returns></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> public static Solid3d Box(double X, double Y, double Z)</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid3d Solid = new Solid3d();</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Solid.CreateBox(X, Y, Z);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> return Solid;</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">
- </span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// 以原点为基点,指定目标点移动实体</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// </summary></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="ent">实体对象</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> /// <param name="pt">目标点</param></span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> public static void Move(Entity ent, Point3d pt)</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> {</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> Matrix3d mt = Matrix3d.Displacement(pt - new Point3d());</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> ent.TransformBy(mt);</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;"> }</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">}</span></font></li><li style="padding-left: 10px; list-style-type: decimal-leading-zero; "><font color="#666666" face="Monaco, Consolas, Lucida Console, Courier New, serif"><span style="font-size: 12px; line-height: 21.600000381469727px;">复制代码</span></font></li>
复制代码
|
|