嗨,Jerry,我的VBA咬伤了,也许你可以翻译一下。我在几个端口进行了测试,其中一些端口进行了旋转(dview),它似乎可以工作。YMMV,但我希望它能让你开始
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using BricscadApp;
- using BricscadDb;
- using RxNet.ApplicationServices;
- using RxNet.Runtime;
- using RxNet.Geometry;
- using RxNet.RxGlobal;
- namespace Bricscad
- {
- public static class Commands
- {
- // from papaerspace vp is active
- [CommandMethod("doit")]
- public static void test01()
- {
- try
- {
- // get app stuff
- var app = Application.AcadApplication as AcadApplication;
- var doc = app.ActiveDocument;
- var mspace = doc.ModelSpace;
- GlobalFunctions.MSpace();
- //select an entity and copy
- object opnt, oent, pairs = null;
- doc.Utility.GetEntity(out oent, out opnt, "Select Entity");
- AcadEntity entity = oent as AcadEntity;
- AcadEntity[] ocol = { entity };
- object[] ncol = doc.CopyObjects((object)ocol, doc.PaperSpace, ref pairs);
- AcadEntity nentity = ncol[0] as AcadEntity;
- // get the center of both entities bounding box
- Point3d cenent = getBBCenter(entity);
- Point3d cennent = getBBCenter(nentity);
- // scale
- nentity.ScaleEntity(cennent.ToArray(), doc.ActivePViewport.CustomScale);
- // rotate
- nentity.Rotate(cennent.ToArray(), doc.ActivePViewport.TwistAngle);
- // move
- nentity.Move(cennent.ToArray(),
- doc.Utility.TranslateCoordinates(
- cenent.ToArray(), AcCoordinateSystem.acUCS, AcCoordinateSystem.acPaperSpaceDCS, 0));
- // delete
- entity.Delete();
- GlobalFunctions.PSpace();
- }
- catch (System.Exception ex)
- {
- GlobalFunctions.Printf("\n{0}\n{1}",
- ex.Message, ex.StackTrace);
- }
- }
- static Point3d getBBCenter(AcadEntity ent)
- {
- object omin, omax;
- ent.GetBoundingBox(out omin, out omax);
- Point3d min = new Point3d((double[])omin);
- Point3d max = new Point3d((double[])omax);
- return new Point3d(min[0] + ((max[0] - min[0]) / 2),
- min[1] + ((max[1] - min[1]) / 2), 0);
- }
- }
- }
|