乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 133|回复: 9

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

[复制链接]

19

主题

90

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
166
发表于 2007-8-25 08:55:00 | 显示全部楼层 |阅读模式
这是我自已写的,原版文件在这里,如果使用中有什么问题,请与我联系




// (C) Copyright 2002-2005 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//using System ;
using Autodesk..Runtime ;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
[assembly: CommandClass(typeof(Caiqs.Cutility))]
//蔡全胜 QQ 361865648 实体镜像,阵列,旋转通用类库
namespace Caiqs
{
///
/// Summary description for CQSClass.
///
public class Cutility
{
  static public Database  db;
  static public Editor ed;
  public Cutility()
  {
   //
   // TODO: Add constructor logic here
   //
  }
  [CommandMethod("Comm")]
  static public void comm()
  {
   return;
  }
  
  //通过Entity对实体进行矩阵matrix3D的变换
  static public void Transform(Entity acadEntity,Matrix3d matrix3D)
  {
   try
   {
    if (acadEntity.IsWriteEnabled==true)
    {acadEntity.TransformBy(matrix3D);}
    else
    {
     Transform(acadEntity.ObjectId ,matrix3D);
    }
   }
   catch (Exception e)
   {
   throw(e);
   }
   return;
  }
  //通过Entity实体数组进行矩阵matrix3D的变换
  static public void Transform(Entity[] acadEntity,Matrix3d matrix3D)
  {
   
   int i;
   for(i=0;i
  //通过实体id对实体进行矩阵matrix3D的变换并复制实体
  static public Entity Ctransform(ObjectId objectId,Matrix3d matrix3D)
  {
   Transaction  tm;
   db = HostApplicationServices.WorkingDatabase;
   tm = db.TransactionManager.StartTransaction();
   Entity retuEnt;
   try
   {
    BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);
    Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead);
    BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);
    retuEnt=(Entity)acadEntity.Clone();
    btr.AppendEntity(retuEnt);
    tm.AddNewlyCreatedDBObject(retuEnt,true);
    Transform(retuEnt.ObjectId,matrix3D);
    tm.Commit();}
   finally
   {
    tm.Dispose();
   }
   return retuEnt;
  }
  //通过实体id数组对实体进行矩阵matrix3D的变换并复制实体
  static public Entity[] Ctransform(ObjectId[] objectId,Matrix3d matrix3D)
  {
   //   db = HostApplicationServices.WorkingDatabase;
   //   tm = db.TransactionManager.StartTransaction();
   //   BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead,true);
   //   BlockTableRecord btr=(BlockTableRecord)tm.GetObject(db.CurrentSpaceId,OpenMode.ForWrite,true);
   //   //Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead);
   //   int i;
   Entity[] retuEnt=new Entity[objectId.Length];
   //   for(i=0;i
   return retuEnt;
  }
  //Id转成实体
  static public Entity IdtoEntity(ObjectId objectId)
  {
   Transaction  tm;
   db = HostApplicationServices.WorkingDatabase;
   tm = db.TransactionManager.StartTransaction();
   Entity acadEntity = (Entity)tm.GetObject(objectId, OpenMode.ForRead );
   tm.Commit();
   tm.Dispose();
   return acadEntity;
  }
  //Id数组转成实体数组
  static public Entity[] IdarraytoEntity(ObjectId[] objectId)
  {
   Transaction  tm;
   db = HostApplicationServices.WorkingDatabase;
   tm = db.TransactionManager.StartTransaction();
   Entity[] retuEnt=new Entity[objectId.Length];
   int i;
   for (i=0;i
   return;
  }
  [CommandMethod("Cmove")]
  static public void Cmove()
  {
   ed=Application.DocumentManager.MdiActiveDocument.Editor;
   ed.WriteMessage("\n选择移动的实体: ");   
  &nbspromptSelectionResult res=ed.GetSelection();
   if (res.Status!= PromptStatus.OK) return;
  &nbspromptPointResult res1=ed.GetPoint("\n起点:");
   if (res1.Status!= PromptStatus.OK) return;
  &nbspromptPointResult res2=ed.GetPoint("\n终点:");
   if (res2.Status!= PromptStatus.OK) return;
   SelectionSet SS = res.Value;
   //Ctransform(SS.GetObjectIds,
   Move(SS,res1.Value,res2.Value);
      System.GC.Collect();
   return;
  }
  [CommandMethod("CRotate")]
  static public void Crotate()
  {
   ed=Application.DocumentManager.MdiActiveDocument.Editor;
   ed.WriteMessage("\n选择旋转的实体: ");   
  &nbspromptSelectionResult res=ed.GetSelection();
   if (res.Status!= PromptStatus.OK) return;
  &nbspromptPointResult res1=ed.GetPoint("\n基点:");
   if (res1.Status!= PromptStatus.OK) return;
  &nbspromptDoubleResult res2=ed.GetDouble("\n旋转角度(弧度): ");
   if (res2.Status!= PromptStatus.OK) return;
   SelectionSet SS = res.Value;
   Rotate(SS,res1.Value,res2.Value);
      System.GC.Collect();
   return;
  }
  [CommandMethod("Cmirror")]
  static public void Cmirror() // This method can have any name
  {
   ed=Application.DocumentManager.MdiActiveDocument.Editor;
   ed.WriteMessage("\n选择要镜像的实体: ");   
  &nbspromptSelectionResult res=ed.GetSelection();
   if (res.Status!= PromptStatus.OK) return;
  &nbspromptPointResult res1=ed.GetPoint("\n镜像线第一点::");
   if (res1.Status!= PromptStatus.OK) return;
  &nbspromptPointResult res2=ed.GetPoint("\n镜像线第二点::");
   if (res2.Status!= PromptStatus.OK) return;
   SelectionSet SS = res.Value;
   Mirror(SS,res1.Value,res2.Value);
      System.GC.Collect();
   return;
  }
  //移动单个实体  
  static public void Move(Entity acadEntity,Point3d pt1,Point3d pt2)
  {
   Vector3d vect=pt2.GetVectorTo(pt1);
   Matrix3d tf = Matrix3d.Displacement(vect);
   //Transform(acadEntity.ObjectId ,tf);
   Transform(acadEntity,tf);
   return;
  }
  //实体移动复制
  static public Entity Copymove(Entity acadEntity,Point3d pt1,Point3d pt2)
  {
   Vector3d vect=pt2.GetVectorTo(pt1);
   Matrix3d tf = Matrix3d.Displacement(vect);
   //   if (acadEntity.IsWriteEnabled==true)
   //   {acadEntity.TransformBy(tf);}
   //   else
   //   {
   //    Transform(acadEntity.ObjectId ,tf);
   //   }
   return (Ctransform(acadEntity.ObjectId,tf));
  }
  //通过ID移动单个实体
  static public void Move(ObjectId objectId,Point3d pt1,Point3d pt2)
  {
   Vector3d vect=pt2.GetVectorTo(pt1);
   Matrix3d tf = Matrix3d.Displacement(vect);
   Transform(objectId,tf);
   return;
  }
  //移动选择集  
  static public void Move(SelectionSet ss,Point3d pt1,Point3d pt2)
  {
   ObjectId[] idArray;
   idArray = ss.GetObjectIds();
   Vector3d vect=pt2.GetVectorTo(pt1);
   Matrix3d tf = Matrix3d.Displacement(vect);
   //Transform(idArray,tf);
   Ctransform(idArray,tf);
   return;
  }
  //通过实体iD数组移动实体
  static public void Move(ObjectId[] idArray,Point3d pt1,Point3d pt2)
  {
   Vector3d vect=pt2.GetVectorTo(pt1);
   Matrix3d tf = Matrix3d.Displacement(vect);
   //Transform(idArray,tf);
   Ctransform(idArray,tf);
   return;
  }
  //XY平面内旋转Entity实体
  static public void Rotate(Entity acadEntity,Point3d baspt,double Rangle)
  {
   Vector3d vect=new Vector3d(0,0,1);
   Matrix3d tf=Matrix3d.Rotation(Rangle,vect,baspt);
   Transform(acadEntity ,tf);
   return;
  }
  //XY平面内旋转实体Id
  static public void Rotate(ObjectId objectId,Point3d baspt,double Rangle)
  {
   Vector3d vect=new Vector3d(0,0,1);
   Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);
   Transform(objectId,tf);
   return;
  }
  //旋转选择集
  static public void Rotate(SelectionSet ss,Point3d baspt,double Rangle)
  {
   ObjectId[] idArray;
   idArray = ss.GetObjectIds();
   Vector3d vect=new Vector3d(0,0,1);
   Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);
   Transform(idArray,tf);
   return;
  }
  //旋转实体Id数组
  static public void Rotate(ObjectId[] idArray,Point3d baspt,double Rangle)
  {
   Vector3d vect=new Vector3d(0,0,1);
   Matrix3d tf = Matrix3d.Rotation(Rangle,vect,baspt);
   Transform(idArray,tf);
   return;
  }
  //镜像实体
  static public void Mirror(Entity acadEntity,Point3d p1,Point3d p2)
  {
  &nbsplane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);
   Matrix3d tf=Matrix3d.Mirroring(Myplane);
   Transform(acadEntity,tf);
   return;
  }
  //通过Id镜像实体
  static public void Mirror(ObjectId objectId,Point3d p1,Point3d p2)
  {
  &nbsplane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);
   Matrix3d tf=Matrix3d.Mirroring(Myplane);
   Transform(objectId,tf);
   return;
  }
  //镜像选择集
  static public void Mirror(SelectionSet ss,Point3d p1,Point3d p2)
  {
   ObjectId[] idArray;
   idArray = ss.GetObjectIds();
  &nbsplane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);
   Matrix3d tf=Matrix3d.Mirroring(Myplane);
   Transform(idArray,tf);
   return;
  }
  //镜像实体Id数组
  static public void Mirror(ObjectId[] idArray,Point3d p1,Point3d p2)
  {
  &nbsplane Myplane=new Plane(p1,new Point3d(p2.X ,p2.Y ,-100),p2);
   Matrix3d tf=Matrix3d.Mirroring(Myplane);
   Transform(idArray,tf);
   return;
  }
  //实体缩放
  static public void Scale(Entity acadEntity,Point3d basepoint,double scale)
  {
   Matrix3d tf=Matrix3d.Scaling(scale,basepoint);
   Transform(acadEntity,tf);
   return;
  }
  //实体Id缩放
  static public void Scale(ObjectId objectId,Point3d basepoint,double scale)
  {
   Matrix3d tf=Matrix3d.Scaling(scale,basepoint);
   Transform(objectId ,tf);
   return;
  }
  //选择集缩放
  static public void Scale(SelectionSet ss,Point3d basepoint,double scale)
  {
   ObjectId[] idArray;
   Matrix3d tf=Matrix3d.Scaling(scale,basepoint);
   idArray = ss.GetObjectIds();
   Transform(idArray ,tf);
   return;
  }
  //实体id数组缩放
  static public void Scale(ObjectId[] objectId,Point3d basepoint,double scale)
  {
   Matrix3d tf=Matrix3d.Scaling(scale,basepoint);
   Transform(objectId ,tf);
   return;
  }
  
}
}

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

5

主题

296

帖子

9

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
316
发表于 2007-8-25 09:03:00 | 显示全部楼层
支持一下,虽然我现在还看不懂,相信以后会有用的!
谢谢!
回复

使用道具 举报

19

主题

90

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
166
发表于 2007-8-25 09:05:00 | 显示全部楼层

编译好的在这里
请点击此处下载

请先注册会员后在进行下载

已注册会员,请先登录后下载

文件名称:rrmm423wgyz.rar 
下载次数:0  文件大小:4.1 KB  售价:2银币 [记录]
下载权限: 不限 以上或 Vip会员   [开通Vip]   [签到领银币]  [免费赚银币]

回复

使用道具 举报

0

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
6
发表于 2007-8-25 12:05:00 | 显示全部楼层
冰块给你顶一下,
回复

使用道具 举报

23

主题

122

帖子

7

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
214
发表于 2007-8-27 14:27:00 | 显示全部楼层
好东西谢谢
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2007-8-29 23:33:00 | 显示全部楼层
谢谢了,用得上。
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2007-8-31 10:23:00 | 显示全部楼层
请问 如何才能只选择1次呢, 选择的时候我只要点中的一个实体就行了
回复

使用道具 举报

74

主题

1603

帖子

24

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1906
发表于 2007-9-27 10:44:00 | 显示全部楼层
太高了,看不懂,学习!
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2007-10-15 12:23:00 | 显示全部楼层
ding
回复

使用道具 举报

52

主题

380

帖子

11

银币

中流砥柱

Rank: 25

铜币
588
发表于 2007-12-24 16:22:00 | 显示全部楼层
正要学习C#,
可惜objectarx 2006的教程是用C++,难道我要改学C++。。
楼上的代码先收藏。。学习学习
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 13:22 , Processed in 0.725813 second(s), 78 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表