Пример #1
0
        public static DBObject Create(this Grevit.Types.Wall w, Transaction tr, Grevit.Types.Point from = null, Grevit.Types.Point to = null)
        {
            DictionaryWallStyle ws = new DictionaryWallStyle(Command.Database);

            try
            {
                if (from == null && to == null && w.curve.GetType() == typeof(Grevit.Types.PLine))
                {
                    Grevit.Types.PLine pline = (Grevit.Types.PLine)w.curve;
                    for (int i = 0; i < pline.points.Count; i++)
                    {
                        if (i == pline.points.Count - 1)
                        {
                            if (pline.closed)
                            {
                                w.Create(tr, pline.points[i], pline.points[0]);
                            }
                        }
                        else
                        {
                            w.Create(tr, pline.points[i], pline.points[i + 1]);
                        }
                    }
                }
                else
                {
                    Wall       wall = new Wall();
                    LayerTable lt   = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);

                    bool newEnt = false;

                    if (Command.existing_objects.ContainsKey(w.GID))
                    {
                        wall = (Wall)tr.GetObject(Command.existing_objects[w.GID], OpenMode.ForWrite);
                    }
                    else
                    {
                        wall.SetDatabaseDefaults(Command.Database);
                        wall.SetToStandard(Command.Database);
                        newEnt = true;
                        wall.JustificationType = WallJustificationType.Center;
                    }

                    if (w.TypeOrLayer != "")
                    {
                        if (lt.Has(w.TypeOrLayer))
                        {
                            wall.LayerId = lt[w.TypeOrLayer];
                        }
                    }
                    if (ws.Has(w.FamilyOrStyle, tr))
                    {
                        wall.StyleId = ws.GetAt(w.FamilyOrStyle);
                    }



                    if (from != null && to != null)
                    {
                        wall.Set(from.ToPoint3d(), to.ToPoint3d(), Vector3d.ZAxis);
                    }
                    else
                    {
                        if (w.curve.GetType() == typeof(Grevit.Types.Line))
                        {
                            Grevit.Types.Line baseline = (Grevit.Types.Line)w.curve;
                            wall.Set(baseline.from.ToPoint3d(), baseline.to.ToPoint3d(), Vector3d.ZAxis);
                        }
                        else if (w.curve.GetType() == typeof(Grevit.Types.Arc))
                        {
                            Grevit.Types.Arc baseline = (Grevit.Types.Arc)w.curve;
                            CircularArc3d    arc      = new CircularArc3d(baseline.center.ToPoint3d(), Vector3d.ZAxis, Vector3d.ZAxis, baseline.radius, baseline.start, baseline.end);
                            wall.Set(arc, Vector3d.ZAxis);
                        }
                        else if (w.curve.GetType() == typeof(Grevit.Types.Curve3Points))
                        {
                            Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)w.curve;
                            wall.Set(baseline.a.ToPoint3d(), baseline.b.ToPoint3d(), baseline.c.ToPoint3d(), Vector3d.ZAxis);
                        }
                    }


                    wall.BaseHeight = w.height;

                    if (newEnt)
                    {
                        BlockTable       bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                        BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                        ms.AppendEntity(wall);
                        tr.AddNewlyCreatedDBObject(wall, true);
                    }

                    return(wall);
                }
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }

            return(null);
        }
Пример #2
0
 public static Point2d ToPoint2d(this Grevit.Types.Point p)
 {
     return(new Point2d(p.x, p.y));
 }