caiqs 发表于 2007-8-25 08:55:00

C#类库源码: 实体(选择集)镜像,阵列,移动,旋转,缩放

本帖最后由 作者 于 2007-8-25 9:26:50 编辑 <br /><br /> <p>这是我自已写的,原版文件在这里,如果使用中有什么问题,请与我联系</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>// (C) Copyright 2002-2005 by Autodesk, Inc. <br/>//<br/>// Permission to use, copy, modify, and distribute this software in<br/>// object code form for any purpose and without fee is hereby granted, <br/>// provided that the above copyright notice appears in all copies and <br/>// that both that copyright notice and the limited warranty and<br/>// restricted rights notice below appear in all supporting <br/>// documentation.<br/>//<br/>// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. <br/>// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF<br/>// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.&nbsp; AUTODESK, INC. <br/>// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<br/>// UNINTERRUPTED OR ERROR FREE.<br/>//<br/>// Use, duplication, or disclosure by the U.S. Government is subject to <br/>// restrictions set forth in FAR 52.227-19 (Commercial Computer<br/>// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<br/>// (Rights in Technical Data and Computer Software), as applicable.<br/>//</p><p>//using System ;<br/>using Autodesk.AutoCAD.Runtime ;<br/>using Autodesk.AutoCAD.DatabaseServices;<br/>using Autodesk.AutoCAD.Geometry;<br/>using Autodesk.AutoCAD.EditorInput;<br/>using Autodesk.AutoCAD.ApplicationServices;<br/><br/>//蔡全胜 QQ 361865648 实体镜像,阵列,旋转通用类库<br/>namespace Caiqs<br/>{<br/>&nbsp;/// &lt;summary&gt;<br/>&nbsp;/// Summary description for CQSClass.<br/>&nbsp;/// &lt;/summary&gt;<br/>&nbsp;public class Cutility<br/>&nbsp;{<br/>&nbsp;&nbsp;static public Database&nbsp; db;<br/>&nbsp;&nbsp;static public Editor ed;<br/>&nbsp;&nbsp;public Cutility()<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//<br/>&nbsp;&nbsp;&nbsp;// TODO: Add constructor logic here<br/>&nbsp;&nbsp;&nbsp;//<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;static public void comm()<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;//通过Entity对实体进行矩阵matrix3D的变换<br/>&nbsp;&nbsp;static public void Transform(Entity acadEntity,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (acadEntity.IsWriteEnabled==true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;{acadEntity.TransformBy(matrix3D);}<br/>&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transform(acadEntity.ObjectId ,matrix3D);<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;catch (Exception e)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;throw(e);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//通过Entity实体数组进行矩阵matrix3D的变换<br/>&nbsp;&nbsp;static public void Transform(Entity[] acadEntity,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;for(i=0;i&lt;acadEntity.Length;i++)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (acadEntity.IsWriteEnabled==true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;{acadEntity.TransformBy(matrix3D);}<br/>&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;{Transform(acadEntity.ObjectId ,matrix3D);}<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//通过实体id对实体进行矩阵matrix3D的变换<br/>&nbsp;&nbsp;static public void Transform(ObjectId objectId,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForWrite); <br/>&nbsp;&nbsp;&nbsp;&nbsp;acadEntity.TransformBy(matrix3D);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Commit();}<br/>&nbsp;&nbsp;&nbsp;finally<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//&nbsp;&nbsp;//实体克窿<br/>&nbsp;&nbsp;static public Entity Clone(Entity acadEntity)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;Entity retuEnt;<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (acadEntity.IsReadEnabled==true)<br/>&nbsp;&nbsp;&nbsp;&nbsp;{retuEnt=(Entity)acadEntity.Clone();}<br/>&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entity Ent = (Entity)tm.GetObject(acadEntity.ObjectId, OpenMode.ForRead); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retuEnt=(Entity)Ent.Clone();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(retuEnt);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.AddNewlyCreatedDBObject(retuEnt,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Commit();}<br/>&nbsp;&nbsp;&nbsp;finally<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return retuEnt;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体数组克隆<br/>&nbsp;&nbsp;static public Entity[] Clone(Entity[] acadEntity)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;Entity[] retuEnt=new Entity;<br/>&nbsp;&nbsp;&nbsp;for(i=0;i&lt;acadEntity.Length;i++)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;retuEnt=Clone(acadEntity);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return retuEnt;<br/>&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;//通过实体id对实体进行矩阵matrix3D的变换并复制实体<br/>&nbsp;&nbsp;static public Entity Ctransform(ObjectId objectId,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;Entity retuEnt;<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead); <br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;retuEnt=(Entity)acadEntity.Clone();<br/>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(retuEnt);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.AddNewlyCreatedDBObject(retuEnt,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;Transform(retuEnt.ObjectId,matrix3D);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Commit();}<br/>&nbsp;&nbsp;&nbsp;finally<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return retuEnt;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//通过实体id数组对实体进行矩阵matrix3D的变换并复制实体<br/>&nbsp;&nbsp;static public Entity[] Ctransform(ObjectId[] objectId,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;//Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead); <br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;Entity[] retuEnt=new Entity;<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;for(i=0;i&lt;objectId.Length;i++)<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead ); <br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;retuEnt=(Entity)acadEntity.Clone();<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(retuEnt);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;tm.AddNewlyCreatedDBObject(retuEnt,true);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;retuEnt=Clone(IdarraytoEntity(objectId));<br/>&nbsp;&nbsp;&nbsp;Transform(retuEnt,matrix3D);</p><p>&nbsp;&nbsp;&nbsp;return retuEnt;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//Id转成实体<br/>&nbsp;&nbsp;static public Entity IdtoEntity(ObjectId objectId)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead );<br/>&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;return acadEntity;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//Id数组转成实体数组<br/>&nbsp;&nbsp;static public Entity[] IdarraytoEntity(ObjectId[] objectId)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;Entity[] retuEnt=new Entity;<br/>&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;for (i=0;i&lt;objectId.Length;i++)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;retuEnt = (Entity)tm.GetObject(objectId, OpenMode.ForRead );<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;return retuEnt;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//对id数组进行矩阵matrix3D的变换<br/>&nbsp;&nbsp;static public void Transform(ObjectId[] idArray,Matrix3d matrix3D)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;for(i=0;i&lt;idArray.Length;i++)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;Entity acadEntity = (Entity)tm.GetObject(idArray, OpenMode.ForWrite); <br/>&nbsp;&nbsp;&nbsp;&nbsp;acadEntity.TransformBy(matrix3D);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//单个实体加入数据库<br/>&nbsp;&nbsp;static public void Apptodb(Entity acadEntity)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;ed=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;<br/>&nbsp;&nbsp;&nbsp;ed.WriteMessage(acadEntity.IsNewObject.ToString());<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(acadEntity);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.AddNewlyCreatedDBObject(acadEntity,true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;catch (Exception e)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;throw(e);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体数组加入到数据库<br/>&nbsp;&nbsp;static public void Apptodb(Entity[] acadEntity)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Transaction&nbsp; tm;<br/>&nbsp;&nbsp;&nbsp;db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;tm = db.TransactionManager.StartTransaction();<br/>&nbsp;&nbsp;&nbsp;BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);<br/>&nbsp;&nbsp;&nbsp;BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);<br/>&nbsp;&nbsp;&nbsp;int i;<br/>&nbsp;&nbsp;&nbsp;for(i=0;i&lt;acadEntity.Length;i++)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(acadEntity);<br/>&nbsp;&nbsp;&nbsp;&nbsp;tm.AddNewlyCreatedDBObject(acadEntity,true);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;tm.Commit();<br/>&nbsp;&nbsp;&nbsp;tm.Dispose();<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;static public void Ccreat()<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//db = HostApplicationServices.WorkingDatabase;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ed=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;<br/>&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;Line ln1=new Line(new Point3d(0,0,0),new Point3d(50,50,50));<br/>&nbsp;&nbsp;&nbsp;&nbsp;Move(ln1,new Point3d(50,50,0),new Point3d(0,0,0));<br/>&nbsp;&nbsp;&nbsp;&nbsp;ed.WriteMessage("\n移动1完成");<br/>&nbsp;&nbsp;&nbsp;&nbsp;Mirror(ln1,new Point3d(50,50,0),new Point3d(0,0,0));<br/>ed.WriteMessage("\n镜像1完成");<br/>&nbsp;&nbsp;&nbsp;&nbsp;Rotate(ln1,new Point3d(50,50,0),3.14159/2.0);<br/>ed.WriteMessage("\n旋转完成");<br/>&nbsp;&nbsp;&nbsp;&nbsp;Apptodb(ln1);<br/>ed.WriteMessage("\n加入数据库完成");<br/>&nbsp;&nbsp;&nbsp;&nbsp;Copymove(ln1,new Point3d(0,0,0),new Point3d(50,50,0));<br/>ed.WriteMessage("\n复制完成");<br/>&nbsp;&nbsp;&nbsp;&nbsp;Mirror(ln1,new Point3d(50,50,0),new Point3d(0,0,0));<br/>&nbsp;&nbsp;&nbsp;&nbsp;ed.WriteMessage("\n镜像2完成");}<br/>&nbsp;&nbsp;&nbsp;catch (Exception e)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;throw(e);<br/>&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;static public void Cmove()<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ed=Application.DocumentManager.MdiActiveDocument.Editor;<br/>&nbsp;&nbsp;&nbsp;ed.WriteMessage("\n选择移动的实体: ");&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;PromptSelectionResult res=ed.GetSelection();<br/>&nbsp;&nbsp;&nbsp;if (res.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptPointResult res1=ed.GetPoint("\n起点:");<br/>&nbsp;&nbsp;&nbsp;if (res1.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptPointResult res2=ed.GetPoint("\n终点:");<br/>&nbsp;&nbsp;&nbsp;if (res2.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;SelectionSet SS = res.Value;<br/>&nbsp;&nbsp;&nbsp;//Ctransform(SS.GetObjectIds,<br/>&nbsp;&nbsp;&nbsp;Move(SS,res1.Value,res2.Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.GC.Collect();<br/>&nbsp;&nbsp;&nbsp;return;</p><p>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;static public void Crotate()<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ed=Application.DocumentManager.MdiActiveDocument.Editor;<br/>&nbsp;&nbsp;&nbsp;ed.WriteMessage("\n选择旋转的实体: ");&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;PromptSelectionResult res=ed.GetSelection();<br/>&nbsp;&nbsp;&nbsp;if (res.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptPointResult res1=ed.GetPoint("\n基点:");<br/>&nbsp;&nbsp;&nbsp;if (res1.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptDoubleResult res2=ed.GetDouble("\n旋转角度(弧度): ");<br/>&nbsp;&nbsp;&nbsp;if (res2.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;SelectionSet SS = res.Value;<br/>&nbsp;&nbsp;&nbsp;Rotate(SS,res1.Value,res2.Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.GC.Collect();<br/>&nbsp;&nbsp;&nbsp;return;</p><p>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;static public void Cmirror() // This method can have any name<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ed=Application.DocumentManager.MdiActiveDocument.Editor;<br/>&nbsp;&nbsp;&nbsp;ed.WriteMessage("\n选择要镜像的实体: ");&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;PromptSelectionResult res=ed.GetSelection();<br/>&nbsp;&nbsp;&nbsp;if (res.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptPointResult res1=ed.GetPoint("\n镜像线第一点::");<br/>&nbsp;&nbsp;&nbsp;if (res1.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;PromptPointResult res2=ed.GetPoint("\n镜像线第二点::");<br/>&nbsp;&nbsp;&nbsp;if (res2.Status!= PromptStatus.OK) return;<br/>&nbsp;&nbsp;&nbsp;SelectionSet SS = res.Value;<br/>&nbsp;&nbsp;&nbsp;Mirror(SS,res1.Value,res2.Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.GC.Collect();<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//移动单个实体&nbsp; <br/>&nbsp;&nbsp;static public void Move(Entity acadEntity,Point3d pt1,Point3d pt2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=pt2.GetVectorTo(pt1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Displacement(vect);<br/>&nbsp;&nbsp;&nbsp;//Transform(acadEntity.ObjectId ,tf);<br/>&nbsp;&nbsp;&nbsp;Transform(acadEntity,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体移动复制<br/>&nbsp;&nbsp;static public Entity Copymove(Entity acadEntity,Point3d pt1,Point3d pt2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=pt2.GetVectorTo(pt1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Displacement(vect);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;if (acadEntity.IsWriteEnabled==true)<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;{acadEntity.TransformBy(tf);}<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;Transform(acadEntity.ObjectId ,tf);<br/>&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;return (Ctransform(acadEntity.ObjectId,tf));<br/>&nbsp;&nbsp;}</p><p><br/>&nbsp;&nbsp;//通过ID移动单个实体<br/>&nbsp;&nbsp;static public void Move(ObjectId objectId,Point3d pt1,Point3d pt2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=pt2.GetVectorTo(pt1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Displacement(vect);<br/>&nbsp;&nbsp;&nbsp;Transform(objectId,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//移动选择集&nbsp; <br/>&nbsp;&nbsp;static public void Move(SelectionSet ss,Point3d pt1,Point3d pt2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ObjectId[] idArray;<br/>&nbsp;&nbsp;&nbsp;idArray = ss.GetObjectIds(); <br/>&nbsp;&nbsp;&nbsp;Vector3d vect=pt2.GetVectorTo(pt1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Displacement(vect);<br/>&nbsp;&nbsp;&nbsp;//Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;Ctransform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//通过实体iD数组移动实体<br/>&nbsp;&nbsp;static public void Move(ObjectId[] idArray,Point3d pt1,Point3d pt2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=pt2.GetVectorTo(pt1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Displacement(vect);<br/>&nbsp;&nbsp;&nbsp;//Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;Ctransform(idArray,tf);</p><p>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//XY平面内旋转Entity实体<br/>&nbsp;&nbsp;static public void Rotate(Entity acadEntity,Point3d baspt,double Rangle)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=new Vector3d(0,0,1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Rotation(Rangle,vect,baspt);<br/>&nbsp;&nbsp;&nbsp;Transform(acadEntity ,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//XY平面内旋转实体Id<br/>&nbsp;&nbsp;static public void Rotate(ObjectId objectId,Point3d baspt,double Rangle)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=new Vector3d(0,0,1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);<br/>&nbsp;&nbsp;&nbsp;Transform(objectId,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//旋转选择集<br/>&nbsp;&nbsp;static public void Rotate(SelectionSet ss,Point3d baspt,double Rangle)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ObjectId[] idArray;<br/>&nbsp;&nbsp;&nbsp;idArray = ss.GetObjectIds(); <br/>&nbsp;&nbsp;&nbsp;Vector3d vect=new Vector3d(0,0,1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);<br/>&nbsp;&nbsp;&nbsp;Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//旋转实体Id数组<br/>&nbsp;&nbsp;static public void Rotate(ObjectId[] idArray,Point3d baspt,double Rangle)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Vector3d vect=new Vector3d(0,0,1);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);<br/>&nbsp;&nbsp;&nbsp;Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//镜像实体<br/>&nbsp;&nbsp;static public void Mirror(Entity acadEntity,Point3d p1,Point3d p2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Plane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Mirroring(Myplane);<br/>&nbsp;&nbsp;&nbsp;Transform(acadEntity,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//通过Id镜像实体<br/>&nbsp;&nbsp;static public void Mirror(ObjectId objectId,Point3d p1,Point3d p2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Plane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Mirroring(Myplane);<br/>&nbsp;&nbsp;&nbsp;Transform(objectId,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//镜像选择集<br/>&nbsp;&nbsp;static public void Mirror(SelectionSet ss,Point3d p1,Point3d p2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ObjectId[] idArray;<br/>&nbsp;&nbsp;&nbsp;idArray = ss.GetObjectIds(); <br/>&nbsp;&nbsp;&nbsp;Plane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Mirroring(Myplane);<br/>&nbsp;&nbsp;&nbsp;Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//镜像实体Id数组<br/>&nbsp;&nbsp;static public void Mirror(ObjectId[] idArray,Point3d p1,Point3d p2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Plane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Mirroring(Myplane);<br/>&nbsp;&nbsp;&nbsp;Transform(idArray,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体缩放<br/>&nbsp;&nbsp;static public void Scale(Entity acadEntity,Point3d basepoint,double scale)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Scaling(scale,basepoint);<br/>&nbsp;&nbsp;&nbsp;Transform(acadEntity,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体Id缩放<br/>&nbsp;&nbsp;static public void Scale(ObjectId objectId,Point3d basepoint,double scale)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Scaling(scale,basepoint);<br/>&nbsp;&nbsp;&nbsp;Transform(objectId ,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//选择集缩放<br/>&nbsp;&nbsp;static public void Scale(SelectionSet ss,Point3d basepoint,double scale)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ObjectId[] idArray;<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Scaling(scale,basepoint);<br/>&nbsp;&nbsp;&nbsp;idArray = ss.GetObjectIds(); <br/>&nbsp;&nbsp;&nbsp;Transform(idArray ,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;//实体id数组缩放<br/>&nbsp;&nbsp;static public void Scale(ObjectId[] objectId,Point3d basepoint,double scale)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Matrix3d tf=Matrix3d.Scaling(scale,basepoint);<br/>&nbsp;&nbsp;&nbsp;Transform(objectId ,tf);<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}</p><p></p><p><br/>&nbsp;&nbsp;<br/>&nbsp;}<br/>}</p>

zml84 发表于 2007-8-25 09:03:00

支持一下,虽然我现在还看不懂,相信以后会有用的!<br/>谢谢!<br/>

caiqs 发表于 2007-8-25 09:05:00

本帖最后由 作者 于 2007-8-25 9:09:11 编辑

编译好的在这里

JOLMO 发表于 2007-8-25 12:05:00

冰块给你顶一下,

houlinbo 发表于 2007-8-27 14:27:00

好东西谢谢

一个样 发表于 2007-8-29 23:33:00

谢谢了,用得上。

qshzhangfan 发表于 2007-8-31 10:23:00

请问 <font color="#ff0000">如何</font>才能只选择1次呢, <font color="#6600ff">选择的时候我只要点中的一个实体就行了</font>

xyp1964 发表于 2007-9-27 10:44:00

太高了,看不懂,学习!

kk20021055 发表于 2007-10-15 12:23:00

ding

carrot1983 发表于 2007-12-24 16:22:00

<p>正要学习C#,</p><p>可惜objectarx 2006的教程是用C++,难道我要改学C++。。</p><p>楼上的代码先收藏。。学习学习</p>
页: [1] 2
查看完整版本: C#类库源码: 实体(选择集)镜像,阵列,移动,旋转,缩放