2

我正在尝试使用PlotTypeAutoCad 中的“窗口”进行绘图。这是代码:

ViewBorder border = new ViewBorder();

Point3d first = new Point3d(border.Width, 0, 0);
Point3d second = new Point3d(border.Height, 0, 0);

Extents2d window = TransformCoordinates(first, second);

psv.SetPlotWindowArea(ps, window);

psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

TransformCoordinates 方法仅接收两个 Point3d 参数(x 和 y)并将它们从 UCS 转换为 DCS 坐标,返回一个 Extents2d。我不想让用户选择点(互联网上有一些使用这个的例子)。我唯一想要的是“第一”和“第二”变量变成了 Point3d。第一个必须是模型空间绘图的左上角,第二个也必须是模型空间绘图的右下角。我怎么能这样做?PlotType(或其他东西)中是否有任何配置之王可以为我管理所有这些,即不要求用户选择角落并为我选择模型空间中的整个绘图?

4

2 回答 2

1

我的经验不是 C# 和 AutoCad。我接受过 AutoLISP 培训。但是知道 AC 是如何工作的,我想说你最好的选择是控制命令提示符,如此所述。

根据您所说的,我假设您想打印模型空间中的任何内容;那是对的吗?

好吧,当您在 PaperSpace 中时,您可以通过._MSPACE在命令行上键入来切换到 ModelSpace。这将使您能够通过 PSpace 中的一个洞在 MSpace 中工作——可以这么说。因此,如果 PSpace 中的布局没有显示 MSpace 的全部内容,您可以切换到 MSpace 并在命令行上输入z或键入。zoom然后,您将拥有任何用户使用该zoom工具在模型空间内的所有选项(全部/中心/动态...)。All可能是最好的选择。

因此,当用户单击您的按钮或输入您的别名时,您可以自动化整个过程。您可以切换到 MSpace-> 全部缩放 -> 绘图 -> 布局(要绘制的内容)。

更新:

我现在意识到我的链接没有将您带到我想要的特定主题。(?)
这是我认为您应该尝试的片段 -

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

[CommandMethod("selectEntireAutoCadDrawing")]
public static void selectEntireAutoCadDrawing()
{
  //This sets up your doc. Not sure if this is the way you're doing it.
  //I imagine you'd probably pass the doc into the method.
  Document yourACDoc = Application.DocumentManager.MdiActiveDocument;

  //When your plug-in is invoked the first thing I'd do is make sure they're
  //in PaperSpace
  yourACDoc.SendStringToExecute("tilemode 0 ");

  //Next enable ModelSpace through PaperSpace.
  yourACDoc.SendStringToExecute("_mspace ");

  //Now we zoom to the extents of the drawing.
  //Not sure about the bools at the end. The AC documentation has it there for a
  //zoom all example but AC doesn't ask any further questions after selecting the 
  //all or extents zoom types and doesn't elaborate on it?
  yourACDoc.SendStringToExecute("._zoom _extents "/*, true, false, false*/);

  //Head back to PaperSpace
  yourACDoc.SendStringToExecute("_pspace ");
}

此时,您的绘图应该都在 PaperSpace 中。现在继续执行其余的操作。

AC 命令行需要空格键、回车键,或者如果设置正确,则单击鼠标即可执行任何命令。这就是为什么某些参数之间有空格的原因。这样做很重要,否则它们将被解释为未知命令。

您可能需要尝试一下,查看 API 参考,或使用不同的缩放类型。如果您有多个具有不同风格的用户,尤其是在管理松散的商店中,缩放可能会变得很棘手。如果这将在人们意识到其局限性的环境中实施,那应该没问题。

另外 - 让自己熟悉 AC 会很好。您可以将命令行用作调试器,因为它会显示所有输入的命令和任何错误消息的列表。它还可以让您提前设计。只需在 AC 中输入命令,记下提示的顺序和目的并相应地编码。还有一种方法可以将动作记录到宏中,这是许多没有编程知识的人采用的方法。

祝你好运~

于 2013-01-18T07:59:25.183 回答
0

尝试这个。

using Autodesk.AutoCAD.ApplicationServices;
using App = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

Document curDoc = App.DocumentManager.MdiActiveDocument;
Extents3d allEntsExtents = new Extents3d();
using (Transaction tr = curDoc.TransactionManager.StartTransaction())
{
    BlockTable bt = tr.GetObject(curDoc.Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
    BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead, false) as BlockTableRecord;
    allEntsExtents.AddBlockExtents(btr);
    tr.Commit();
}
Plane plane = new Plane();
Extents2d window = new Extents2d(
    allEntsExtents.MinPoint.Convert2d(plane),
    allEntsExtents.MaxPoint.Convert2d(plane));
于 2013-04-12T18:46:11.893 回答