在 AutoCAD 中选择整个图形而不提示用户 [英] Select whole drawing in AutoCAD without prompting user

查看:37
本文介绍了在 AutoCAD 中选择整个图形而不提示用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 AutoCad 中使用Window"作为 PlotType 进行绘图.这是代码:

I'm trying to plot using "Window" as PlotType in AutoCad. This is the code:

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(或其他东西)中是否有任何配置之王可以为我管理所有这些,即不要求用户选择角并为我选择模型空间中的整个图形?

The TransformCoordinates method only receives two Point3d arguments (x and y) and transform them from UCS to DCS coordinates returning a Extents2d. I don't want to ask user to select points(There is some examples using this on the internet). The only thing that i want is that "first" and "second" variables becames a Point3d. The first must be the top left corner from the drawing in the ModelSpace and the second must be the bottom right corner in the model space drawing also. How could i do that? Is there any king of configuration in PlotType (Or other thing) that could manage all of this for me, i.e., not asking user to selected corners and select the whole drawing in model space for me?

推荐答案

我的经验不是 C# 和 AutoCad.我接受了 AutoLISP 的培训.但是知道 AC 是如何工作的,我会说你最好的办法是控制命令提示符 此处记录.

My experience is not with C# and AutoCad. I was trained on AutoLISP. But knowing how AC works I'd say your best bet is to take control over the command prompt as documented here.

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

By what you've said I'm assuming you'd like to print what ever is in model space; is that correct?

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

Well when you're in PaperSpace you can switch to ModelSpace by typing ._MSPACE on the command line. This will enable you to work in MSpace through a hole in PSpace - so to speak. So, if the layout in PSpace is not showing the entire contents of MSpace you can switch to MSpace and enter z or type zoom on the command line. You'll then have all the options any user would inside model space utilizing the zoom tool (All/Center/Dynamic...). All would probably be the best bet.

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

So when the user clicks your button or enters your alias you can automate the entire process. You can switch to MSpace-> zoom all -> plot -> layout (what to plot).

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

I realize now that my link did not take you to the specific topic I intended.(?)
Here is a snippet of what I think you should try -

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 中.现在继续执行其余的操作.

At this point your drawing should all be there in PaperSpace. Now just continue with the rest of your execution.

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

AC command line requires the space bar, return, or if set up correctly a mouse click to execute any command. That is why there are spaces between some parameters. It is essential to do it this way or they will be interpreted as unknown commands.

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

You might have to play around with it a bit, look at the API reference, or use a different zoom type. Zooms can get tricky if you have multiple users with different styles especially in a loosely managed shop. If this will be implemented in an environment where people are aware of it's limitations it should be fine.

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

Also - it'd be good to make yourself familiar with AC. You can use the command line as a debugger for it shows a list of all the commands entered and any error messages. It will also allow you to design in advance. Just enter the commands in AC make notes of the order and purpose of the prompts and code accordingly. There is also a way to record actions into a macro which is the route many with no programming knowledge take.

祝你好运~

这篇关于在 AutoCAD 中选择整个图形而不提示用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆