我正在尝试在AutoCad中使用"Window“作为PlotType
进行绘图。代码如下:
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转换为返回Extents2d的DCS坐标。我不想让用户选择点数(在互联网上有一些这样的例子)。我唯一想要的是让"first“和"second”变量成为一个Point3d。第一个必须是ModelSpace中图形的左上角,第二个也必须是模型空间图形中的右下角。我怎么能这么做呢?在PlotType (或其他东西)中有没有一种配置可以为我管理所有这些,例如,不要求用户选择角落并在模型空间中为我选择整个图形?
发布于 2013-01-18 15:59:25
我的经验不是使用C#和AutoCad。我受过AutoLISP方面的训练。但是知道AC是如何工作的,我会说你最好的办法就是以documented here的身份控制命令提示符。
根据您所说的,我假设您喜欢打印模型空间中的所有内容,对吗?
当您在PaperSpace中时,可以通过在命令行中输入._MSPACE
切换到ModelSpace。这将使您能够通过PSpace中的漏洞在MSpace中工作-可以这么说。因此,如果PSpace中的布局没有显示MSpace的全部内容,您可以切换到MSpace并在命令行中输入z
或zoom
。然后,您将拥有任何用户在模型空间中使用zoom
工具( all /Center/Dynamic...)的所有选项。All
可能是最好的选择。
因此,当用户单击您的按钮或输入您的别名时,您可以自动执行整个过程。您可以切换到MSpace-> zoom all -> plot -> layout (要打印什么)。
更新:
我现在意识到,我的链接没有将您带到我想要的特定主题。
这是我认为你应该尝试的一小段-
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命令行需要使用空格键、return,或者如果设置正确,单击鼠标即可执行任何命令。这就是为什么一些参数之间有空格的原因。这样做是必要的,否则它们将被解释为未知命令。
您可能需要尝试一下,查看API参考资料,或者使用不同的缩放类型。如果您有多个具有不同风格的用户,缩放可能会变得棘手,特别是在管理松散的商店中。如果这将在一个人们意识到它的局限性的环境中实现,它应该是很好的。
另外,让自己熟悉AC也是很好的。您可以使用命令行作为调试器,因为它会显示输入的所有命令和任何错误消息的列表。它还允许您提前进行设计。只需在AC中输入命令,记下提示的顺序和用途,并相应地编写代码。还有一种方法可以将动作记录到宏中,这是许多没有编程知识的人所采用的方法。
祝你好运~
发布于 2013-04-13 02:46:12
尝尝这个。
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));
https://stackoverflow.com/questions/14388918
复制相似问题