Esempio n. 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);
        }
Esempio n. 2
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;

        }
Esempio n. 3
0
        public static void Create(Grevit.Types.Wall w)
        {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            DictionaryWallStyle ws = new DictionaryWallStyle(db);
            try
            {
                Wall wall = new Wall();
                LayerTable lt = (LayerTable)tr.GetObject(db.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(db);
                    wall.SetToStandard(db);
                    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 (w.from != null && w.to != null)
                {
                    wall.Set(GrevitPtoPoint3d(w.from), GrevitPtoPoint3d(w.to), Vector3d.ZAxis);
                }
                else
                {
                    if (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.from = pline.points[i];
                                    w.to = pline.points[0];
                                    Create(w);
                                }
                            }
                            else
                            {
                                w.from = pline.points[i];
                                w.to = pline.points[i + 1];
                                Create(w);
                            }
                        }

                    }
                    else if (w.curve.GetType() == typeof(Grevit.Types.Line))
                    {
                        Grevit.Types.Line baseline = (Grevit.Types.Line)w.curve;
                        wall.Set(GrevitPtoPoint3d(baseline.from), GrevitPtoPoint3d(baseline.to), Vector3d.ZAxis);
                    }
                    else if (w.curve.GetType() == typeof(Grevit.Types.Arc))
                    {
                        Grevit.Types.Arc baseline = (Grevit.Types.Arc)w.curve;
                        CircularArc3d arc = new CircularArc3d(GrevitPtoPoint3d(baseline.center), 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(GrevitPtoPoint3d(baseline.a), GrevitPtoPoint3d(baseline.b), GrevitPtoPoint3d(baseline.c), Vector3d.ZAxis);
                    }
                }

                wall.BaseHeight = w.height;

                if (newEnt)
                {
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    AddXData(w, wall);
                    ms.AppendEntity(wall);
                    tr.AddNewlyCreatedDBObject(wall, true);
                    storeID(w, wall.Id);
                }
                writeProperties(wall, w.parameters, tr);
                tr.Commit();
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                ed.WriteMessage(e.Message);
                tr.Abort();
            }

            finally
            {
                tr.Dispose();
            }
        }