public static void Create(Grevit.Types.DrawingPoint a) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); Point3d pp = GrevitPtoPoint3d(a.point); DBPoint ppp = new DBPoint(pp); ppp.SetDatabaseDefaults(db); if (a.TypeOrLayer != "") { if (lt.Has(a.TypeOrLayer)) ppp.LayerId = lt[a.TypeOrLayer]; } BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(ppp); tr.AddNewlyCreatedDBObject(ppp, true); writeProperties(ppp, a.parameters, tr); storeID(a, ppp.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Database db, Grevit.Types.Door door, Wall wall, Transaction tr, BlockTableRecord ms) { Door d = new Door(); DictionaryDoorStyle dds = new DictionaryDoorStyle(db); bool newEnt = false; if (Command.existing_objects.ContainsKey(door.GID)) { d = (Door)tr.GetObject(Command.existing_objects[door.GID], OpenMode.ForWrite); } else { d.SetDatabaseDefaults(db); d.SetToStandard(db); AnchorOpeningBaseToWall w = new AnchorOpeningBaseToWall(); w.SetToStandard(db); w.SubSetDatabaseDefaults(db); d.SetAnchor(w); newEnt = true; w.SetSingleReference(wall.Id, Autodesk.Aec.DatabaseServices.RelationType.OwnedBy); } Point3d pkt = new Point3d(door.locationPoint.x, door.locationPoint.y + (wall.Width / 2), door.locationPoint.z); d.Location = pkt; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (door.TypeOrLayer != "") { if (lt.Has(door.TypeOrLayer)) d.LayerId = lt[door.TypeOrLayer]; } if (dds.Has(door.FamilyOrStyle, tr)) d.StyleId = dds.GetAt(door.FamilyOrStyle); if (newEnt) { AddXData(door, d); ms.AppendEntity(d); tr.AddNewlyCreatedDBObject(d, true); } writeProperties(d, door.parameters, tr); storeID(door, d.Id); }
// Invokable method to set received component collections to the static component collection private void AddComponents(Grevit.Types.ComponentCollection componentCollection) { if (this.debugTextBox.InvokeRequired) { SetComponentsCallback d = new SetComponentsCallback(AddComponents); this.Invoke(d, new object[] { componentCollection }); } else { this.componentCollection = componentCollection; } }
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; }
public static void AddXData(this DBObject dbobject, Grevit.Types.Component comp, Transaction tr) { AddRegAppTableRecord("Grevit",tr); Entity ent = (Entity)tr.GetObject(dbobject.Id, OpenMode.ForWrite); ResultBuffer rbs = new ResultBuffer(new TypedValue(1001, "Grevit"), new TypedValue(1000, comp.GID)); ent.XData = rbs; rbs.Dispose(); ent.Dispose(); }
public static Dictionary<string, ObjectId> getExistingObjectIDs(Grevit.Types.ComponentCollection cs) { Dictionary<string, ObjectId> existingObjects = new Dictionary<string, ObjectId>(); if (cs.update) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); List<string> banned = new List<string>(); foreach (ObjectId id in ms) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead); ResultBuffer rb = ent.XData; if (rb != null) { bool hasGrevitId = false; string GrevitId = ""; foreach (TypedValue tv in rb) { if (tv.TypeCode == 1001 && tv.Value.ToString() == "Grevit") hasGrevitId = true; if (tv.TypeCode == 1000 && tv.Value != null) GrevitId = tv.Value.ToString(); } rb.Dispose(); if (hasGrevitId && GrevitId.Length > 0) { foreach (Grevit.Types.Component c in cs.Items) { if (c.GID == GrevitId) { if (!existingObjects.ContainsKey(c.GID)) { if (!banned.Contains(c.GID)) existingObjects.Add(c.GID, ent.Id); } else { existingObjects.Remove(c.GID); banned.Add(c.GID); } } } } } } } Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(existingObjects.Count.ToString()); } return existingObjects; }
public XYZ ApplyOverride(Grevit.Types.Point point) { switch (Coordinate) { case Revit.Coordinate.X: return new XYZ(Value, point.y, point.z); case Revit.Coordinate.Y: return new XYZ(point.x, Value, point.z); case Revit.Coordinate.Z: return new XYZ(point.x, point.y, Value); default: return new XYZ(point.x, point.y, point.z); } }
// Invokable method to set received component collections to the static component collection private void AddComponents(Grevit.Types.ComponentCollection componentCollection) { this.Dispatcher.Invoke(new Action(() => { this.componentCollection = componentCollection; })); }
public static void Create(Grevit.Types.Line l) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); try { Line line = new Line(GrevitPtoPoint3d(l.from), GrevitPtoPoint3d(l.to)); line.SetDatabaseDefaults(db); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); AddXData(l, line); if (lt.Has(l.TypeOrLayer)) line.LayerId = lt[l.TypeOrLayer]; ms.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); writeProperties(line, l.parameters, tr); storeID(l, line.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Grevit.Types.Column c) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); DictionaryMemberStyle mst = new DictionaryMemberStyle(db); try { Member member = new Member(); member.MemberType = MemberType.Column; if (Command.existing_objects.ContainsKey(c.GID)) { member = (Member)tr.GetObject(Command.existing_objects[c.GID], OpenMode.ForWrite); } else { member.SetDatabaseDefaults(db); member.SetToStandard(db); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(member); tr.AddNewlyCreatedDBObject(member, true); } LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (c.TypeOrLayer != "") { if (lt.Has(c.TypeOrLayer)) member.LayerId = lt[c.TypeOrLayer]; } if (mst.Has(c.FamilyOrStyle, tr)) member.StyleId = mst.GetAt(c.FamilyOrStyle); member.Set(GrevitPtoPoint3d(c.location), GrevitPtoPoint3d(c.locationTop)); writeProperties(member, c.parameters, tr); AddXData(c, member); storeID(c, member.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Grevit.Types.Slab s) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; // DictionarySlabStyle ss = new DictionarySlabStyle(db); try { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // Polyline acPoly = new Polyline(); //acPoly.SetDatabaseDefaults(); //int i = 0; DBObjectCollection objColl = new DBObjectCollection(); Point3dCollection ptcol = new Point3dCollection(); foreach (Grevit.Types.Component p in s.surface.outline) { parse3dCurve(ptcol, p); //Curve3dCollection collt = parse3dCurve(p); //acPoly.AppendVertex(new PolylineVertex3d(new Point3d(p.x, p.y, p.z))); //acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); //i++; //foreach (Curve3d curve in collt) //{ // objColl.Add(Autodesk.AutoCAD.DatabaseServices.Curve.CreateFromGeCurve(curve)); //} } ed.WriteMessage(ptcol.Count.ToString()); Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, ptcol, true); objColl.Add(face); //Polyline3d face = new Polyline3d(); //ETC... // or from your settings // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true); DBObjectCollection myRegionColl = new DBObjectCollection(); // create a single region Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region(); DBObjectCollection objRegions = new DBObjectCollection(); try { objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl); objreg = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region; } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // eInvalidInput exception Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message); } //acPoly.Closed = true; //ms.AppendEntity(acPoly); //tr.AddNewlyCreatedDBObject(acPoly, true); //atrix3d mm = Matrix3d.Displacement(new Vector3d(0, 0, r.outline[0].z)); //acPoly.TransformBy(mm); //Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem); //Slab slab = new Slab(); //slab.SetDatabaseDefaults(db); //slab.SetToStandard(db); //slab.Location = new Point3d(0, 0, 0); //slab.SetBaseProfile(myProfile, Matrix3d.Identity); //DBObjectCollection col = acPoly.GetOffsetCurves(0); //DBObjectCollection res = Region.CreateFromCurves(coll); //Region reg = res[0] as Region; Solid3d solid = new Solid3d(); solid.Extrude(objreg, s.height, s.slope); LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (s.TypeOrLayer != "") { if (lt.Has(s.TypeOrLayer)) solid.LayerId = lt[s.TypeOrLayer]; } //if (ss.Has(r.family, tr)) slab.StyleId = ss.GetAt(r.family); ms.AppendEntity(solid); tr.AddNewlyCreatedDBObject(solid, true); writeProperties(solid, s.parameters, tr); storeID(s, solid.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Grevit.Types.Room r) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; DictionarySpaceStyle ss = new DictionarySpaceStyle(db); try { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Polyline acPoly = new Polyline(); acPoly.SetDatabaseDefaults(); int i = 0; foreach (Grevit.Types.Point p in r.points) { acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); i++; } acPoly.Closed = true; ms.AppendEntity(acPoly); tr.AddNewlyCreatedDBObject(acPoly, true); Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem); Space space; bool newEnt = false; if (Command.existing_objects.ContainsKey(r.GID)) { space = (Space)tr.GetObject(Command.existing_objects[r.GID], OpenMode.ForWrite); } else { newEnt = true; space = new Space(); space.SetDatabaseDefaults(db); space.SetToStandard(db); } space.Associative = r.associative; space.Name = r.name; space.GeometryType = SpaceGeometryType.TwoD; space.Location = new Point3d(0, 0, 0); space.SetBaseProfile(myProfile, Matrix3d.Identity); LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (r.TypeOrLayer != "") { if (lt.Has(r.TypeOrLayer)) space.LayerId = lt[r.TypeOrLayer]; } if (ss.Has(r.FamilyOrStyle, tr)) space.StyleId = ss.GetAt(r.FamilyOrStyle); if (newEnt) { ms.AppendEntity(space); tr.AddNewlyCreatedDBObject(space, true); } AddXData(r, space); writeProperties(space, r.parameters, tr); storeID(r, space.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Grevit.Types.Arc a) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); Arc arc = new Arc(GrevitPtoPoint3d(a.center), a.radius, a.start, a.end); arc.SetDatabaseDefaults(db); if (lt.Has(a.TypeOrLayer)) arc.LayerId = lt[a.TypeOrLayer]; BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(arc); tr.AddNewlyCreatedDBObject(arc, true); writeProperties(arc, a.parameters, tr); storeID(a, arc.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
public static void Create(Grevit.Types.Spline s) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); try { Point3dCollection points = new Point3dCollection(); foreach (Grevit.Types.Point p in s.controlPoints) points.Add(GrevitPtoPoint3d(p)); DoubleCollection dc = new DoubleCollection(); foreach (double dbl in s.weights) dc.Add(dbl); DoubleCollection dcc = new DoubleCollection(); foreach (double dbl in s.knots) dcc.Add(dbl); Spline sp = new Spline(s.degree, s.isRational, s.isClosed, s.isPeriodic, points, dcc, dc, 0, 0); sp.SetDatabaseDefaults(db); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); AddXData(s, sp); if (lt.Has(s.TypeOrLayer)) sp.LayerId = lt[s.TypeOrLayer]; ms.AppendEntity(sp); tr.AddNewlyCreatedDBObject(sp, true); writeProperties(sp, s.parameters, tr); storeID(s, sp.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }
/// <summary> /// Create Revit Wall /// </summary> /// <param name="grevitWall"></param> /// <param name="from">Optional Point From</param> /// <param name="to">Optional Point To</param> /// <returns></returns> public static Element Create(this Grevit.Types.Wall grevitWall, Grevit.Types.Point from = null, Grevit.Types.Point to = null) { #region baseLineCurve // The Baseline curve for the wall Autodesk.Revit.DB.Curve baselineCurve = null; // If the from and the to point have been set // Draw a line using those points (linear wall) if (from != null && to != null) { XYZ a = from.ToXYZ(); XYZ b = to.ToXYZ(); if (a.DistanceTo(b) > 0.01) { baselineCurve = Autodesk.Revit.DB.Line.CreateBound(a, b); } } // Otherwise check the curve type else { // If the curve is a polyline (linear) split it into segments and create walls of them if (grevitWall.curve.GetType() == typeof(Grevit.Types.PLine)) { Grevit.Types.PLine pline = (Grevit.Types.PLine)grevitWall.curve; // Walk thru all points and create segments for (int i = 0; i < pline.points.Count; i++) { if (i == pline.points.Count - 1) { if (pline.closed) grevitWall.Create(pline.points[i], pline.points[0]); } else grevitWall.Create(pline.points[i], pline.points[i + 1]); } } // If the curve is a line just create a line else if (grevitWall.curve.GetType() == typeof(Grevit.Types.Line)) { Grevit.Types.Line baseline = (Grevit.Types.Line)grevitWall.curve; baselineCurve = Autodesk.Revit.DB.Line.CreateBound(baseline.from.ToXYZ(), baseline.to.ToXYZ()); } // If the curve is an Arc create an Arc with Centerpoint, start, radius and end else if (grevitWall.curve.GetType() == typeof(Grevit.Types.Arc)) { Grevit.Types.Arc baseline = (Grevit.Types.Arc)grevitWall.curve; baselineCurve = Autodesk.Revit.DB.Arc.Create(baseline.center.ToXYZ(), baseline.radius, baseline.start, baseline.end, XYZ.BasisX, XYZ.BasisY); } // If the curve is a 3Point Arc, create a new 3 Point based arc. else if (grevitWall.curve.GetType() == typeof(Grevit.Types.Curve3Points)) { Grevit.Types.Curve3Points baseline = (Grevit.Types.Curve3Points)grevitWall.curve; baselineCurve = Autodesk.Revit.DB.Arc.Create(baseline.a.ToXYZ(), baseline.c.ToXYZ(), baseline.b.ToXYZ()); } } #endregion // Get the Wall type and the level Element wallTypeElement = GrevitBuildModel.document.GetElementByName(typeof(Autodesk.Revit.DB.WallType), grevitWall.TypeOrLayer); if (wallTypeElement != null && baselineCurve != null) { Element levelElement = GrevitBuildModel.document.GetLevelByName(grevitWall.levelbottom, baselineCurve.GetEndPoint(0).Z); if (levelElement == null) return null; Autodesk.Revit.DB.Wall wall; // If the wall already exists update the baseline curve // Otherwise create a new wall if (GrevitBuildModel.existing_Elements.ContainsKey(grevitWall.GID)) { wall = (Autodesk.Revit.DB.Wall)GrevitBuildModel.document.GetElement(GrevitBuildModel.existing_Elements[grevitWall.GID]); LocationCurve locationCurve = (LocationCurve)wall.Location; locationCurve.Curve = baselineCurve; } else wall = Autodesk.Revit.DB.Wall.Create(GrevitBuildModel.document, baselineCurve, wallTypeElement.Id, levelElement.Id, grevitWall.height, 0, false, true); // Apply the automatic join setting if (!grevitWall.join) { WallUtils.DisallowWallJoinAtEnd(wall, 0); WallUtils.DisallowWallJoinAtEnd(wall, 1); } // Apply Flipped status if (grevitWall.flip) wall.Flip(); // This method is applying the parameters and GID settings // itself because it might run recursively (see Polyline) grevitWall.SetParameters(wall); grevitWall.StoreGID(wall.Id); } // Always returns null as it handles // parameters and GIDs within this method return null; }
public Result BuildModel(Grevit.Types.ComponentCollection components) { bool delete = false; if (components == null) { // Create new Grevit Client sending existing Families Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies()); //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies()); // Show Client Dialog grevitClientDialog.ShowWindow(); //if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return Result.Cancelled; // Set the received component collection components = grevitClientDialog.componentCollection; delete = grevitClientDialog.componentCollection.delete; Scale = grevitClientDialog.componentCollection.scale; } // Set up a List for stalled components (with References) List<Component> componentsWithReferences = new List<Component>(); // Get all existing Grevit Elements from the Document // If Update is false this will just be an empty List existing_Elements = document.GetExistingGrevitElements(components.update); // Set up an empty List for created Elements created_Elements = new Dictionary<string, ElementId>(); #region createComponents Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate"); trans.Start(); // Walk thru all received components foreach (Component component in components.Items) { // If they are not reference dependent, create them directly // Otherwise add the component to a List of stalled elements if (!component.stalledForReference) component.Build(false); else componentsWithReferences.Add(component); } // Walk thru all elements which are stalled because they are depending on // an Element which needed to be created first foreach (Component component in componentsWithReferences) component.Build(true); trans.Commit(); trans.Dispose(); #endregion // If Delete Setting is activated if (delete) { // Create a new transaction Transaction transaction = new Transaction(document, "GrevitDelete"); transaction.Start(); // get the Difference between existing and new elements to erase them IEnumerable<KeyValuePair<string, ElementId>> unused = existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements)); // Delete those elements from the document foreach (KeyValuePair<string, ElementId> element in unused) document.Delete(element.Value); // commit and dispose the transaction transaction.Commit(); transaction.Dispose(); } return Result.Succeeded; }
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(); } }