/// <summary> /// Creates one model curve on a plane with an origin at 0,0,0 /// </summary> /// <param name="mc1"></param> protected void CreateOneModelCurve(out ModelCurve mc1) { //create two model curves using (_trans = _trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "CreateTwoModelCurves")) { _trans.Start(); var p1 = new Plane(XYZ.BasisZ, XYZ.Zero); SketchPlane sp1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p1); Curve c1 = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0)); mc1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c1, sp1); _trans.Commit(); } }
/// <summary> /// Creates two model curves separated in Z. /// </summary> /// <param name="mc1"></param> /// <param name="mc2"></param> protected void CreateTwoModelCurves(out ModelCurve mc1, out ModelCurve mc2) { //create two model curves using (_trans = _trans = new Transaction(dynRevitSettings.Doc.Document, "CreateTwoModelCurves")) { _trans.Start(); Plane p1 = new Plane(XYZ.BasisZ, XYZ.Zero); Plane p2 = new Plane(XYZ.BasisZ, new XYZ(0, 0, 5)); SketchPlane sp1 = dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(p1); SketchPlane sp2 = dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(p2); Curve c1 = dynRevitSettings.Revit.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0)); Curve c2 = dynRevitSettings.Revit.Application.Create.NewLineBound(new XYZ(0, 0, 5), new XYZ(1, 0, 5)); mc1 = dynRevitSettings.Doc.Document.FamilyCreate.NewModelCurve(c1, sp1); mc2 = dynRevitSettings.Doc.Document.FamilyCreate.NewModelCurve(c2, sp2); _trans.Commit(); } }
/// <summary> /// Creates two model curves separated in Z. /// </summary> /// <param name="mc1"></param> /// <param name="mc2"></param> protected void CreateTwoModelCurves(out ModelCurve mc1, out ModelCurve mc2) { //create two model curves using (_trans = _trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "CreateTwoModelCurves")) { _trans.Start(); var p1 = new Plane(XYZ.BasisZ, XYZ.Zero); var p2 = new Plane(XYZ.BasisZ, new XYZ(0, 0, 5)); SketchPlane sp1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p1); SketchPlane sp2 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewSketchPlane(p2); Curve c1 = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0)); Curve c2 = DocumentManager.Instance.CurrentUIApplication.Application.Create.NewLineBound(new XYZ(0, 0, 5), new XYZ(1, 0, 5)); mc1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c1, sp1); mc2 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewModelCurve(c2, sp2); _trans.Commit(); } }
public bool CanConvertToSpeckle(object @object) { return(@object switch { DB.DetailCurve _ => true, DB.DirectShape _ => true, DB.FamilyInstance _ => true, DB.Floor _ => true, DB.Level _ => true, DB.View _ => true, DB.ModelCurve _ => true, DB.Opening _ => true, DB.RoofBase _ => true, DB.Area _ => true, DB.Architecture.Room _ => true, DB.Architecture.TopographySurface _ => true, DB.Wall _ => true, DB.Mechanical.Duct _ => true, DB.Mechanical.Space _ => true, DB.Plumbing.Pipe _ => true, DB.Electrical.Wire _ => true, DB.CurtainGridLine _ => true, //these should be handled by curtain walls DB.Architecture.BuildingPad _ => true, DB.Architecture.Stairs _ => true, DB.Architecture.StairsRun _ => true, DB.Architecture.StairsLanding _ => true, DB.Architecture.Railing _ => true, DB.Architecture.TopRail _ => true, DB.Ceiling _ => true, DB.PointCloudInstance _ => true, DB.Group _ => true, DB.ProjectInfo _ => true, DB.ElementType _ => true, DB.Grid _ => true, DB.ReferencePoint _ => true, DB.Structure.AnalyticalModelStick _ => true, DB.Structure.AnalyticalModelSurface _ => true, DB.Structure.BoundaryConditions _ => true, _ => (@object as Element).IsElementSupported() });
public static ModelCurve Wrap(Autodesk.Revit.DB.ModelCurve ele, bool isRevitOwned) { return(ModelCurve.FromExisting(ele, isRevitOwned)); }
/// <summary> /// Initialize a ModelCurve element /// </summary> /// <param name="curve"></param> private void InitModelCurve(Autodesk.Revit.DB.ModelCurve curve) { InternalSetCurveElement(curve); }
/// <summary> /// Construct a model curve from the document. The result is Dynamo owned /// </summary> /// <param name="curve"></param> private ModelCurve(Autodesk.Revit.DB.ModelCurve curve) { SafeInit(() => InitModelCurve(curve)); }
public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args) { var c = (Curve)((FScheme.Value.Container)args[0]).Item; Autodesk.Revit.DB.ModelCurve mc = null; Curve flattenCurve = null; Autodesk.Revit.DB.Plane plane = dynRevitUtils.GetPlaneFromCurve(c, false); //instead of changing Revit curve keep it "as is" //user might have trouble modifying curve in Revit if it is off the sketch plane if (this.Elements.Any()) { bool needsRemake = false; if (dynUtils.TryGetElement(this.Elements[0], out mc)) { ElementId idSpUnused = ModelCurve.resetSketchPlaneMethod(mc, c, plane, out needsRemake); if (idSpUnused != ElementId.InvalidElementId) { this.DeleteElement(idSpUnused); } //mc.SketchPlane = sp; if (!needsRemake) { if (!mc.GeometryCurve.IsBound && c.IsBound) { c = c.Clone(); c.MakeUnbound(); } ModelCurve.setCurveMethod(mc, c); //mc.GeometryCurve = c; } else { this.DeleteElement(this.Elements[0]); } } else { needsRemake = true; } if (needsRemake) { var sp = dynRevitUtils.GetSketchPlaneFromCurve(c); if (dynRevitUtils.GetPlaneFromCurve(c, true) == null) { flattenCurve = dynRevitUtils.Flatten3dCurveOnPlane(c, plane); mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(flattenCurve, sp) : this.UIDocument.Document.Create.NewModelCurve(flattenCurve, sp); ModelCurve.setCurveMethod(mc, c); } else { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(c, sp) : this.UIDocument.Document.Create.NewModelCurve(c, sp); } mc.ChangeToReferenceLine(); this.Elements[0] = mc.Id; //mc.SketchPlane = sp; if (mc.SketchPlane.Id != sp.Id) { //THIS BIZARRE as Revit could use different existing SP, so if Revit had found better plane this sketch plane has no use this.DeleteElement(sp.Id); } this.Elements[0] = mc.Id; } } else { var sp = dynRevitUtils.GetSketchPlaneFromCurve(c); if (dynRevitUtils.GetPlaneFromCurve(c, true) == null) { flattenCurve = dynRevitUtils.Flatten3dCurveOnPlane(c, plane); mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(flattenCurve, sp) : this.UIDocument.Document.Create.NewModelCurve(flattenCurve, sp); ModelCurve.setCurveMethod(mc, c); } else { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(c, sp) : this.UIDocument.Document.Create.NewModelCurve(c, sp); } this.Elements.Add(mc.Id); mc.ChangeToReferenceLine(); //mc.SketchPlane = sp; if (mc.SketchPlane.Id != sp.Id) { //found better plane this.DeleteElement(sp.Id); } } return(FScheme.Value.NewContainer(mc)); }
/// <summary> /// Convert an input Value into and expected type if possible. /// Ex. If a node expects an XYZ, a user can pass in a ReferencePoint object /// and the position (XYZ) of that object will be returned. /// </summary> /// <param name="input">The value of the input.</param> /// <param name="output">The desired output type.</param> /// <returns></returns> public static object ConvertInput(Value input, Type output) { if (input.IsContainer) { object item = ((Value.Container)input).Item; #region ModelCurve if (item.GetType() == typeof(ModelCurve)) { ModelCurve a = (ModelCurve)item; if (output == typeof(Curve)) { return(((ModelCurve)item).GeometryCurve); } } #endregion #region SketchPlane else if (item.GetType() == typeof(SketchPlane)) { SketchPlane a = (SketchPlane)item; if (output == typeof(Plane)) { return(a.Plane); } else if (output == typeof(ReferencePlane)) { return(a.Plane); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2},{3},{4},{5}", a.Plane.Origin.X, a.Plane.Origin.Y, a.Plane.Origin.Z, a.Plane.Normal.X, a.Plane.Normal.Y, a.Plane.Normal.Z)); } } #endregion #region Point else if (item.GetType() == typeof(Point)) { Point a = (Point)item; if (output == typeof(XYZ)) { return(a.Coord); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2}", a.Coord.X, a.Coord.Y, a.Coord.Z)); } } #endregion #region ReferencePoint else if (item.GetType() == typeof(ReferencePoint)) { ReferencePoint a = (ReferencePoint)item; if (output == typeof(XYZ)) { return(a.Position); } else if (output == typeof(Reference)) { return(a.GetCoordinatePlaneReferenceXY()); } else if (output == typeof(Transform)) { return(a.GetCoordinateSystem()); } else if (output == typeof(string)) { return(string.Format("{0},{1},{2}", a.Position.X, a.Position.Y, a.Position.Z)); } else if (output == typeof(ElementId)) { return(a.Id); } } #endregion #region ElementId else if (item.GetType() == typeof(ElementId)) { if (output == typeof(ReferencePoint)) { ElementId a = (ElementId)item; Element el = dynRevitSettings.Doc.Document.GetElement(a); ReferencePoint rp = (ReferencePoint)el; return(rp); } } #endregion #region Reference else if (item.GetType() == typeof(Reference)) { Reference a = (Reference)item; if (output.IsAssignableFrom(typeof(Element))) { Element e = dynRevitSettings.Doc.Document.GetElement(a); } else if (output == typeof(Face)) { Face f = (Face)dynRevitSettings.Doc.Document.GetElement(a.ElementId).GetGeometryObjectFromReference(a); return(f); } } #endregion #region XYZ if (item.GetType() == typeof(XYZ)) { XYZ a = (XYZ)item; if (output == typeof(Transform)) { Transform t = Transform.get_Translation(a); return(t); } } #endregion return(item); } else if (input.IsNumber) { double a = (double)((Value.Number)input).Item; if (output == typeof(bool)) { return(Convert.ToBoolean(a)); } else if (output == typeof(Int32)) { return(Convert.ToInt32(a)); } return(a); } else if (input.IsString) { string a = ((Value.String)input).Item.ToString(); return(a); } else if (input.IsList) { FSharpList <Value> a = ((Value.List)input).Item; if (output == typeof(ReferenceArrayArray)) { return(DynamoTypeConverter.ConvertFSharpListListToReferenceArrayArray(a)); } else if (output == typeof(ReferenceArray)) { return(DynamoTypeConverter.ConvertFSharpListListToReferenceArray(a)); } else if (output == typeof(CurveArrArray)) { return(DynamoTypeConverter.ConvertFSharpListListToCurveArray(a)); } else if (output == typeof(CurveArray)) { return(DynamoTypeConverter.ConvertFSharpListListToCurveArray(a)); } return(a); } //return the input by default return(input); }
/// <summary> /// Creates one model curve on a plane with an origin at 0,0,0 /// </summary> /// <param name="mc1"></param> protected void CreateOneModelCurve(out ModelCurve mc1) { //create two model curves using (_trans = _trans = new Transaction(dynRevitSettings.Doc.Document, "CreateTwoModelCurves")) { _trans.Start(); Plane p1 = new Plane(XYZ.BasisZ, XYZ.Zero); SketchPlane sp1 = dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(p1); Curve c1 = dynRevitSettings.Revit.Application.Create.NewLineBound(XYZ.Zero, new XYZ(1, 0, 0)); mc1 = dynRevitSettings.Doc.Document.FamilyCreate.NewModelCurve(c1, sp1); _trans.Commit(); } }
//returns unused sketch plane id static public ElementId resetSketchPlaneMethod(Autodesk.Revit.DB.ModelCurve mc, Curve c, Autodesk.Revit.DB.Plane flattenedOnPlane, out bool needsSketchPlaneReset) { //do we need to reset? needsSketchPlaneReset = false; Autodesk.Revit.DB.Plane newPlane = flattenedOnPlane != null ? flattenedOnPlane : dynRevitUtils.GetPlaneFromCurve(c, false); Autodesk.Revit.DB.Plane curPlane = mc.SketchPlane.Plane; bool resetPlane = false; { double llSqCur = curPlane.Normal.DotProduct(curPlane.Normal); double llSqNew = newPlane.Normal.DotProduct(newPlane.Normal); double dotP = newPlane.Normal.DotProduct(curPlane.Normal); double dotSqNormalized = (dotP / llSqCur) * (dotP / llSqNew); double angleTol = Math.PI / 1800.0; if (dotSqNormalized < 1.0 - angleTol * angleTol) { resetPlane = true; } } Autodesk.Revit.DB.SketchPlane sp = null; if (!resetPlane) { double originDiff = curPlane.Normal.DotProduct(curPlane.Origin - newPlane.Origin); double tolerance = 0.000001; if (originDiff > tolerance || originDiff < -tolerance) { sp = dynRevitUtils.GetSketchPlaneFromCurve(c); mc.SketchPlane = dynRevitUtils.GetSketchPlaneFromCurve(c); } return((sp == null || mc.SketchPlane.Id == sp.Id) ? ElementId.InvalidElementId : sp.Id); } //do reset if method is available bool foundMethod = false; if (hasMethodResetSketchPlane) { Type CurveElementType = typeof(Autodesk.Revit.DB.CurveElement); MethodInfo[] curveElementMethods = CurveElementType.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); System.String nameOfMethodSetCurve = "ResetSketchPlaneAndCurve"; System.String nameOfMethodSetCurveAlt = "SetSketchPlaneAndCurve"; foreach (MethodInfo m in curveElementMethods) { if (m.Name == nameOfMethodSetCurve || m.Name == nameOfMethodSetCurveAlt) { object[] argsM = new object[2]; sp = dynRevitUtils.GetSketchPlaneFromCurve(c); argsM[0] = sp; argsM[1] = null; foundMethod = true; m.Invoke(mc, argsM); break; } } } if (!foundMethod) { //sp = dynRevitUtils.GetSketchPlaneFromCurve(c); hasMethodResetSketchPlane = false; needsSketchPlaneReset = true; //expect exception, so try to keep old plane? //mc.SketchPlane = sp; return(ElementId.InvalidElementId); } if (sp != null && mc.SketchPlane.Id != sp.Id) { return(sp.Id); } return(ElementId.InvalidElementId); }
public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args) { Autodesk.Revit.DB.CurveLoop cl = (Autodesk.Revit.DB.CurveLoop)((FScheme.Value.Container)args[0]).Item; if (cl == null) { throw new InvalidOperationException("No curve loop"); } Autodesk.Revit.DB.Plane plane = cl.GetPlane(); if (plane == null) { throw new InvalidOperationException("Curve loop is not planar"); } var mcs = new System.Collections.Generic.List <Autodesk.Revit.DB.ModelCurve>(); var listCurves = new System.Collections.Generic.List <Curve> (); CurveLoopIterator CLiter = cl.GetCurveLoopIterator(); for (; CLiter.MoveNext();) { listCurves.Add(CLiter.Current.Clone()); } int numCurves = listCurves.Count; Autodesk.Revit.DB.SketchPlane sp = null; for (int index = 0; index < numCurves; index++) { //instead of changing Revit curve keep it "as is" //user might have trouble modifying curve in Revit if it is off the sketch plane Autodesk.Revit.DB.ModelCurve mc = null; if (this.Elements.Any() && index < this.Elements.Count) { bool needsRemake = false; if (dynUtils.TryGetElement(this.Elements[index], out mc)) { ElementId idSpUnused = ModelCurve.resetSketchPlaneMethod(mc, listCurves[index], plane, out needsRemake); if (idSpUnused != ElementId.InvalidElementId && index == numCurves - 1) { this.DeleteElement(idSpUnused); } if (!needsRemake) { if (!mc.GeometryCurve.IsBound && listCurves[index].IsBound) { listCurves[index] = listCurves[index].Clone(); listCurves[index].MakeUnbound(); } ModelCurve.setCurveMethod(mc, listCurves[index]); // mc.GeometryCurve = c; } else { this.DeleteElement(this.Elements[index]); } } else { needsRemake = true; } if (needsRemake) { if (sp == null) { sp = dynRevitSettings.Doc.Document.IsFamilyDocument ? dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(plane) : dynRevitSettings.Doc.Document.Create.NewSketchPlane(plane); } if (dynRevitUtils.GetPlaneFromCurve(listCurves[index], true) == null) { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp) : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp); ModelCurve.setCurveMethod(mc, listCurves[index]); } else { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp) : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp); } if (index < this.Elements.Count) { this.Elements[index] = mc.Id; } else { this.Elements.Add(mc.Id); } if (mc.SketchPlane.Id != sp.Id && index == numCurves - 1) { //THIS BIZARRE as Revit could use different existing SP, so if Revit had found better plane this sketch plane has no use this.DeleteElement(sp.Id); } } } else { if (sp == null) { sp = dynRevitSettings.Doc.Document.IsFamilyDocument ? dynRevitSettings.Doc.Document.FamilyCreate.NewSketchPlane(plane) : dynRevitSettings.Doc.Document.Create.NewSketchPlane(plane); } if (dynRevitUtils.GetPlaneFromCurve(listCurves[index], true) == null) { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp) : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp); ModelCurve.setCurveMethod(mc, listCurves[index]); } else { mc = this.UIDocument.Document.IsFamilyDocument ? this.UIDocument.Document.FamilyCreate.NewModelCurve(listCurves[index], sp) : this.UIDocument.Document.Create.NewModelCurve(listCurves[index], sp); } this.Elements.Add(mc.Id); if (mc.SketchPlane.Id != sp.Id && index == numCurves - 1) { //found better plane this.DeleteElement(sp.Id); } } if (mc != null) { mcs.Add(mc); } } FSharpList <FScheme.Value> results = FSharpList <FScheme.Value> .Empty; foreach (var mc in mcs) { results = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(mc), results); } return(FScheme.Value.NewList(Utils.SequenceToFSharpList(results.Reverse()))); }