void ReconstructSketchPlaneByPlane ( Document doc, ref Autodesk.Revit.DB.Element element, Rhino.Geometry.Plane plane ) { if (!plane.IsValid) { ThrowArgumentException(nameof(plane), "Plane is not valid."); } var scaleFactor = 1.0 / Revit.ModelUnits; plane = plane.ChangeUnits(scaleFactor); if (element is SketchPlane sketchPlane) { bool pinned = element.Pinned; element.Pinned = false; var plane0 = sketchPlane.GetPlane(); using (var plane1 = plane.ToHost()) { if (!plane0.Normal.IsParallelTo(plane1.Normal)) { var axisDirection = plane0.Normal.CrossProduct(plane1.Normal); double angle = plane0.Normal.AngleTo(plane1.Normal); using (var axis = Line.CreateUnbound(plane0.Origin, axisDirection)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); plane0 = sketchPlane.GetPlane(); } { double angle = plane0.XVec.AngleOnPlaneTo(plane1.XVec, plane1.Normal); if (angle != 0.0) { using (var axis = Line.CreateUnbound(plane0.Origin, plane1.Normal)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); } } var trans = plane1.Origin - plane0.Origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(doc, element.Id, trans); } } element.Pinned = pinned; } else { ReplaceElement(ref element, SketchPlane.Create(doc, plane.ToHost())); } }
void CommitInstance ( Document doc, IGH_DataAccess DA, int Iteration, Rhino.Geometry.Plane plane ) { var element = PreviousElement(doc, Iteration); try { if (!plane.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is not valid.", Params.Input[0].Name)); } else { var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { plane = plane.Scale(scaleFactor); } element = SketchPlane.Create(doc, plane.ToHost()); } } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); } finally { ReplaceElement(doc, DA, Iteration, element); } }
void CommitInstance ( Document doc, IGH_DataAccess DA, int Iteration, Rhino.Geometry.Plane plane ) { var element = PreviousElement(doc, Iteration); try { if (!plane.IsValid) { throw new Exception(string.Format("Parameter '{0}' is not valid.", Params.Input[0].Name)); } var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { plane = plane.Scale(scaleFactor); } if (element is SketchPlane sketchPlane) { bool pinned = element.Pinned; element.Pinned = false; var plane0 = sketchPlane.GetPlane(); using (var plane1 = plane.ToHost()) { if (!plane0.Normal.IsParallelTo(plane1.Normal)) { var axisDirection = plane0.Normal.CrossProduct(plane1.Normal); double angle = plane0.Normal.AngleTo(plane1.Normal); using (var axis = Line.CreateUnbound(plane0.Origin, axisDirection)) ElementTransformUtils.RotateElement(Revit.ActiveDBDocument, element.Id, axis, angle); plane0 = sketchPlane.GetPlane(); } { double angle = plane0.XVec.AngleOnPlaneTo(plane1.XVec, plane1.Normal); if (angle != 0.0) { using (var axis = Line.CreateUnbound(plane0.Origin, plane1.Normal)) ElementTransformUtils.RotateElement(Revit.ActiveDBDocument, element.Id, axis, angle); } } var trans = plane1.Origin - plane0.Origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(Revit.ActiveDBDocument, element.Id, trans); } } element.Pinned = pinned; } else { element = CopyParametersFrom(SketchPlane.Create(doc, plane.ToHost()), element); } ReplaceElement(doc, DA, Iteration, element); } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); ReplaceElement(doc, DA, Iteration, null); } }