【发布时间】:2020-03-22 19:45:42
【问题描述】:
目前我有一个使用 AutoCAD 类绘制的对象,但我可以选择在绘制后镜像它。我不知道该怎么做。
[CommandMethod("DrawTestDoor")]
public void DrawTestDoor()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
var ed = acDoc.Editor;
XDDoor s1 = new XDDoor();
PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("");
pKeyOpts.Message = "\nIt is Rated ";
pKeyOpts.Keywords.Add("True");
pKeyOpts.Keywords.Add("False");
pKeyOpts.Keywords.Default = "True";
pKeyOpts.AllowNone = true;
PromptResult pKeyRes = acDoc.Editor.GetKeywords(pKeyOpts);
bool fireRated = Convert.ToBoolean(pKeyRes.StringResult);
var promptResultheight = ed.GetString("\nEnter the Frame height: ");
double height = Convert.ToDouble(promptResultheight.StringResult);
var promptResultwidth = ed.GetString("\nFrame Width: ");
double width = Convert.ToDouble(promptResultwidth.StringResult);
var promptResultFrameDepthChange = ed.GetString("\nEnter the frame depth change ");
double frameDepthChange = Convert.ToDouble(promptResultFrameDepthChange.StringResult);
PromptKeywordOptions pKeyOpts1 = new PromptKeywordOptions("");
pKeyOpts1.Message = "\nDoor Handle Side";
pKeyOpts1.Keywords.Add("Left");
pKeyOpts1.Keywords.Add("Right");
pKeyOpts1.Keywords.Default = "Left";
pKeyOpts1.AllowNone = true;
s1.DrawSingleXDDoor(height, width, fireRated, frameDepthChange);
Matrix2d md = new Matrix2d();
md.Translation.Mirror()
}
这个md.Translation.Mirror() 是我认为需要改变的行。我已经尝试了很多方法来做镜像,但我一直回到这个问题,因为我不知道s1 对象是这样保存的。也许认为它需要转换为实体?
public void DrawSingleXDDoor(double height, double width, bool fireRated, double frameDepthChange)
{
DrawLid("lid", leafHeight, lidWidth);
}
public void DrawLid(string type, double height, double width)
{
DrawShapes d1 = new DrawShapes();
DrawComponents xd = new DrawComponents();
d1.DrawRectangle(0, 0, height, width);
}
public void DrawRectangle(double startx, double starty, double recHeight, double recWidth)
{
double height = recHeight;
double width = recWidth;
//Get the drawing document and the dataabses object
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt;
bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr;
btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Polyline p1 = new Polyline();
p1.AddVertexAt(0, new Point2d(startx + 0, starty + 0), 0, 0, 0);
p1.AddVertexAt(0, new Point2d(startx + 0, starty + height), 0, 0, 0);
p1.AddVertexAt(0, new Point2d(startx + width, starty + height), 0, 0, 0);
p1.AddVertexAt(0, new Point2d(startx + width, starty + 0), 0, 0, 0);
p1.AddVertexAt(0, new Point2d(startx + 0, starty + 0), 0, 0, 0);
p1.SetDatabaseDefaults();
btr.AppendEntity(p1);
trans.AddNewlyCreatedDBObject(p1, true);
trans.Commit();
}
catch (System.Exception ex)
{
doc.Editor.WriteMessage("Error encountered: " + ex.Message);
trans.Abort();
}
}
}
【问题讨论】:
-
嗯,看起来你试图镜像什么。你有一个没有数据的默认实例化二维矩阵......所以你的镜像不起作用是有道理的。您需要引用某种模型空间对象才能镜像。您很可能需要创建一个新事务来将新镜像的对象插入模型空间。对不起,如果我的术语被关闭了,我已经有几年没有为 autocad 编程了。
-
@TraeMoore 我不知道如何去照镜子,所以你说得对,事实上我没有引用任何东西。 s1 正在按照我希望的方式绘制。但是我不确定如何在它被实例化的命令中镜像它。
标签: c# .net visual-studio autocad autodesk