gpt4 book ai didi

c# - 用 C# 模仿 AutoCAD 的 viewcube 的行为

转载 作者:行者123 更新时间:2023-11-30 12:58:00 27 4
gpt4 key购买 nike

我有一个对象,它是我从程序中在 AutoCAD 中绘制的。绘制对象后,我设置了相机,以便它缩放到从顶 View 向下看的墙上。然后我想让它做的是向前 View 向下旋转 45 度,向左 View 向左旋转 45 度。这实质上模拟了在 AutoCAD 中选择对象,然后单击 View 立方体。

enter image description here

这是我的轨道方法。

/// <summary>
/// Orbit the angle around a passed axis
/// </summary>
public static void Orbit(Vector3d axis, Point3d pivotPoint, Angle angle)
{
Editor activeEditor = AcadApp.DocumentManager.MdiActiveDocument.Editor; //Get editor for current document
ViewTableRecord activeView = activeEditor.GetCurrentView(); //Get current view table
activeView.ViewDirection = activeView.ViewDirection.TransformBy(Matrix3d.Rotation(angle.Radians, axis, pivotPoint)); //Adjust the ViewTableRecord
activeEditor.SetCurrentView(activeView); //Set it as the current view
}

下面是我如何调用轨道方法

CameraMethods.Orbit(Vector3d.XAxis, GeometryAdapter.ClearspanPointToAcadPoint(wallToZoomTo.FrontLine.MidPoint), new Angle(AngleType.Radian, Math.PI / 4));
CameraMethods.Orbit(Vector3d.ZAxis, GeometryAdapter.ClearspanPointToAcadPoint(wallToZoomTo.FrontLine.MidPoint), new Angle(AngleType.Radian, Math.PI / 4));

问题是,当我经过墙壁对象的中点时,它会围绕相机旋转,因此它离得很远(在 View 左上角的某个地方)

有没有人有办法通过 C# 在 AutoCAD 中轻松绕着选定对象旋转?提前致谢!

最佳答案

试试这个:

[CommandMethod("MYORBIT")]
public void MyOrbit()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

PromptPointResult ppr = ed.GetPoint("\nSelect orbit point: ");
if (ppr.Status == PromptStatus.Cancel) return;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
short cvport = (short)Application.GetSystemVariable("CVPORT");
using (Manager gm = doc.GraphicsManager)
using (var kd = new KernelDescriptor())
{
kd.addRequirement(Autodesk.AutoCAD.UniqueString.Intern("3D Drawing"));
using (View view = gm.ObtainAcGsView(cvport, kd))
{
double d = view.Position.DistanceTo(view.Target);
view.SetView(ppr.Value + new Vector3d(-1, -1, 1).GetNormal() * d,
ppr.Value, Vector3d.ZAxis, view.FieldWidth, view.FieldHeight);
gm.SetViewportFromView(cvport, view, true, true, true);
}
}

// Needed if wireframe 2D
ed.Regen();

tr.Commit();
}
}

关于c# - 用 C# 模仿 AutoCAD 的 viewcube 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31897576/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com