试图使用C#上的AutoCAD类镜像图形

问题描述 投票:2回答:1

目前,我有一个使用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();
                }
            }

        }
c# .net visual-studio autocad autodesk
1个回答
0
投票

似乎您错过了在转换上设置镜像点,并将镜像副本插入BlockTable。添加新的p1 (polyline)后,应立即执行以下代码。这似乎是您缺少的部分,我从here获得了此代码示例。试一试,让我知道。干杯!

 // Define the mirror line
        Point3d acPtFrom = new Point3d(0, 4.25, 0);
        Point3d acPtTo = new Point3d(4, 4.25, 0);
        Line3d acLine3d = new Line3d(acPtFrom, acPtTo);

        // Mirror the polyline across the X axis
        acPolyMirCopy.TransformBy(Matrix3d.Mirroring(acLine3d));

        // Add the new object to the block table record and the transaction
        acBlkTblRec.AppendEntity(acPolyMirCopy);
        acTrans.AddNewlyCreatedDBObject(acPolyMirCopy, true);
© www.soinside.com 2019 - 2024. All rights reserved.