/// <summary> /// Create the arc(ModelArc) /// </summary> /// <param name="sketchId">the id of the sketch plane</param> /// <param name="startPoint">the start point of the arc</param> /// <param name="endPoint">the end point of the arc</param> /// <param name="thirdPoint">the third point which is on the arc</param> public void CreateArc(ElementId sketchId, Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint, Autodesk.Revit.DB.XYZ thirdPoint) { try { // First get the sketch plane by the giving element id. SketchPlane workPlane = GetSketchPlaneById(sketchId); // Additional check: the start, end and third point should not be the same if (startPoint.Equals(endPoint) || startPoint.Equals(thirdPoint) || endPoint.Equals(thirdPoint)) { throw new ArgumentException("Three points should not be the same."); } // create the geometry arc Arc geometryArc = Arc.Create(startPoint, endPoint, thirdPoint); if (null == geometryArc) // assert the creation is successful { throw new Exception("Create the geometry arc failed."); } // create the ModelArc ModelArc arc = m_createDoc.NewModelCurve(geometryArc, workPlane) as ModelArc; if (null == arc) // assert the creation is successful { throw new Exception("Create the ModelArc failed."); } // Add the created ModelArc into the arc array m_arcArray.Append(arc); // Finally refresh information map. RefreshInformationMap(); } catch (Exception ex) { throw new Exception("Can not create the ModelArc, message: " + ex.Message); } }
void SetTangentLockInProfileSketch1( Document famdoc, Form [] extrusions) { ICollection <ElementId> delIds = null; List <ElementId> enmIDs = new List <ElementId>(); using (SubTransaction delTrans = new SubTransaction(famdoc)) { try { delTrans.Start(); delIds = famdoc.Delete(extrusions[0].Id); delTrans.RollBack(); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); } } // Get the model lines in the profile and use the // end points for reference the sketch dimensions diameter List <ModelArc> mArcsR1 = new List <ModelArc>(); List <ModelArc> mArcsR2 = new List <ModelArc>(); List <ModelLine> mLines = new List <ModelLine>(); foreach (ElementId id in delIds) { enmIDs.Add(id); } for (int i = 0; i < enmIDs.Count; i++) { Element ele = famdoc.GetElement(enmIDs[i]); if (ele is ModelArc) { ModelArc ma = ele as ModelArc; Curve c = ma.GeometryCurve; Arc a = c as Arc; if (Math.Round(r1, 6) == Math.Round(a.Radius, 6)) { mArcsR1.Add(ma); } if (Math.Round(r2, 6) == Math.Round(a.Radius, 6)) { mArcsR2.Add(ma); } } if (ele is ModelLine) { ModelLine ml = ele as ModelLine; Element before = null; Element after = null; ElementId beforeId = null; ElementId afterId = null; if (i > 0) { before = famdoc.GetElement(enmIDs[i - 1]); beforeId = enmIDs[i - 1]; } else { before = famdoc.GetElement(enmIDs[enmIDs.Count - 1]); beforeId = enmIDs[enmIDs.Count - 1]; } if (i == enmIDs.Count - 1) { after = famdoc.GetElement(enmIDs[0]); afterId = enmIDs[0]; } else { after = famdoc.GetElement(enmIDs[i + 1]); afterId = enmIDs[i + 1]; } if (before is ModelArc && after is ModelArc) { ml.SetTangentLock(0, beforeId, true); ml.SetTangentLock(1, afterId, true); } } } }
void SetTangentLockInProfileSketch2( Document famdoc, Form[] extrusions) { ICollection <ElementId> delIds = null; List <ElementId> enmIDs = new List <ElementId>(); using (SubTransaction delTrans = new SubTransaction(famdoc)) { try { delTrans.Start(); delIds = famdoc.Delete(extrusions[0].Id); delTrans.RollBack(); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); } } // Get the model lines in the profile and use the end // points for reference the sketch dimensions diameter List <ModelArc> mArcsR1 = new List <ModelArc>(); List <ModelArc> mArcsR2 = new List <ModelArc>(); List <ModelLine> mLines = new List <ModelLine>(); foreach (ElementId id in delIds) { enmIDs.Add(id); } for (int i = 0; i < enmIDs.Count; i++) { Element ele = famdoc.GetElement(enmIDs[i]); if (ele is ModelArc) { ModelArc ma = ele as ModelArc; Curve c = ma.GeometryCurve; Arc a = c as Arc; if (Math.Round(r1, 6) == Math.Round(a.Radius, 6)) { mArcsR1.Add(ma); } if (Math.Round(r2, 6) == Math.Round(a.Radius, 6)) { mArcsR2.Add(ma); } } if (ele is ModelLine) { ModelLine ml = ele as ModelLine; ElementId beforeId = null; ElementId afterId = null; ISet <ElementId> joinedBefore = ml.GetAdjoinedCurveElements(0); foreach (ElementId id in joinedBefore) { Element joinedEle = famdoc.GetElement(id); if (joinedEle is ModelArc) { beforeId = id; break; } } ISet <ElementId> joinedAfter = ml.GetAdjoinedCurveElements(1); foreach (ElementId id in joinedAfter) { Element joinedEle = famdoc.GetElement(id); if (joinedEle is ModelArc) { afterId = id; break; } } if (beforeId != null && afterId != null && ml.HasTangentJoin(0, beforeId) && ml.HasTangentJoin(1, afterId)) { ml.SetTangentLock(0, beforeId, true); ml.SetTangentLock(1, afterId, true); } } } }
private void Stream( ArrayList data, ModelArc modelCrv ) { data.Add( new Snoop.Data.ClassSeparator( typeof( ModelArc ) ) ); // no data at this level }
public void Execute(UIApplication uiapp) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name); if (doc.ActiveView.GetType() != typeof(View3D)) { MessageBox.Show("ActiveView is not typeof View3D."); return; } FamilyInstance myFamilyInstance_NerfGun = null; if (uidoc.Selection.GetElementIds().Count == 0) { string myString_RememberLast = doc.ProjectInformation.get_Parameter(BuiltInParameter.PROJECT_NUMBER).AsString(); int n; if (int.TryParse(myString_RememberLast, out n)) { myFamilyInstance_NerfGun = doc.GetElement(new ElementId(n)) as FamilyInstance; } } else { myFamilyInstance_NerfGun = doc.GetElement(uidoc.Selection.GetElementIds().First()) as FamilyInstance; } if (myFamilyInstance_NerfGun == null) { MessageBox.Show("Please perform step 5 of 19 first." + Environment.NewLine + Environment.NewLine + "(Placing Nerf Gun)"); return; } /// TECHNIQUE 14 OF 19 (EE14_Draw3D_IntersectorLines.cs) ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ DRAW INTERSECTOR LINES FROM NERF GUN ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ /// /// Interfaces and ENUM's: /// BuiltInParameter.POINT_ELEMENT_DRIVEN /// IFailuresPreprocessor /// /// /// Demonstrates classes: /// ReferencePoint /// AdaptiveComponentInstanceUtils /// Transform /// TransactionGroup /// Random* /// ElementMulticategoryFilter /// ReferenceIntersector /// /// /// Key methods: /// AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds( /// myReferencePoint.GetCoordinateSystem( /// refIntersector.FindNearest( /// myReferenceWithContext.GetReference( /// uidoc.RefreshActiveView(); /// /// /// /// * class is actually part of the .NET framework (not Revit API) /// /// /// https://github.com/joshnewzealand/Revit-API-Playpen-CSharp uidoc.Selection.SetElementIds(new List <ElementId>()); ReferencePoint myReferencePoint = doc.GetElement(AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(myFamilyInstance_NerfGun).First()) as ReferencePoint; Transform myTransform_FromNurfGun = myReferencePoint.GetCoordinateSystem(); using (TransactionGroup transGroup = new TransactionGroup(doc)) { transGroup.Start("Transaction Group"); if (!myReferencePoint.get_Parameter(BuiltInParameter.POINT_ELEMENT_DRIVEN).IsReadOnly) { using (Transaction tx = new Transaction(doc)) { tx.Start("Unhost"); myReferencePoint.get_Parameter(BuiltInParameter.POINT_ELEMENT_DRIVEN).Set(0); tx.Commit(); uidoc.RefreshActiveView(); } } MyPreProcessor preproccessor = new MyPreProcessor(); for (int i = 1; i <= 100; i++) { if (i > 100) { MessageBox.Show("Stopped at 'i > 100' because more will cause Revit to 'freeze up'."); break; } Random rnd = new Random(); OverrideGraphicSettings ogs = new OverrideGraphicSettings(); ogs.SetProjectionLineColor(new Autodesk.Revit.DB.Color((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256))); using (Transaction tx = new Transaction(doc)) { FailureHandlingOptions options = tx.GetFailureHandlingOptions(); options.SetFailuresPreprocessor(preproccessor); tx.SetFailureHandlingOptions(options); tx.Start("Splatter Gun"); Line myLine_BasisX = Line.CreateUnbound(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisX); myReferencePoint.Location.Rotate(myLine_BasisX, GetRandomNumber()); Line myLine_BasisZ = Line.CreateUnbound(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisZ); myReferencePoint.Location.Rotate(myLine_BasisZ, GetRandomNumber()); myTransform_FromNurfGun = myReferencePoint.GetCoordinateSystem(); List <BuiltInCategory> builtInCats = new List <BuiltInCategory>(); builtInCats.Add(BuiltInCategory.OST_Roofs); builtInCats.Add(BuiltInCategory.OST_Ceilings); builtInCats.Add(BuiltInCategory.OST_Floors); builtInCats.Add(BuiltInCategory.OST_Walls); builtInCats.Add(BuiltInCategory.OST_Doors); builtInCats.Add(BuiltInCategory.OST_Windows); builtInCats.Add(BuiltInCategory.OST_CurtainWallPanels); builtInCats.Add(BuiltInCategory.OST_CurtainWallMullions); ElementMulticategoryFilter intersectFilter = new ElementMulticategoryFilter(builtInCats); ReferenceIntersector refIntersector = new ReferenceIntersector(intersectFilter, FindReferenceTarget.Face, doc.ActiveView as View3D); ReferenceWithContext myReferenceWithContext = refIntersector.FindNearest(myTransform_FromNurfGun.Origin, myTransform_FromNurfGun.BasisZ); if (myReferenceWithContext != null) { Reference myReferenceHosting_Normal = myReferenceWithContext.GetReference(); Element myElement_ContainingFace = doc.GetElement(myReferenceHosting_Normal.ElementId); Face myFace = myElement_ContainingFace.GetGeometryObjectFromReference(myReferenceHosting_Normal) as Face; if (myFace.GetType() != typeof(PlanarFace)) { return; // continue; } Plane plane = Plane.CreateByNormalAndOrigin(myTransform_FromNurfGun.BasisX, myTransform_FromNurfGun.Origin); SketchPlane sketchPlane = SketchPlane.Create(doc, plane); if (myTransform_FromNurfGun.Origin.DistanceTo(myReferenceHosting_Normal.GlobalPoint) > 0.0026)//minimum lenth check { Line line = Line.CreateBound(myTransform_FromNurfGun.Origin, myReferenceHosting_Normal.GlobalPoint); ModelLine myModelLine = doc.Create.NewModelCurve(line, sketchPlane) as ModelLine; doc.ActiveView.SetElementOverrides(myModelLine.Id, ogs); myWindow1.myListElementID_SketchPlanesToDelete.Add(sketchPlane.Id); Transform myXYZ_FamilyTransform = Transform.Identity; if (myReferenceHosting_Normal.ConvertToStableRepresentation(doc).Contains("INSTANCE")) { myXYZ_FamilyTransform = (myElement_ContainingFace as FamilyInstance).GetTotalTransform(); } PlanarFace myPlanarFace = myFace as PlanarFace; Transform myTransform = Transform.Identity; myTransform.Origin = myReferenceHosting_Normal.GlobalPoint; myTransform.BasisX = myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector); myTransform.BasisY = myXYZ_FamilyTransform.OfVector(myPlanarFace.YVector); myTransform.BasisZ = myXYZ_FamilyTransform.OfVector(myPlanarFace.FaceNormal); SketchPlane mySketchPlane = SketchPlane.Create(doc, myReferenceHosting_Normal); // Create a geometry circle in Revit application XYZ xVec = myTransform.OfVector(XYZ.BasisX); XYZ yVec = myTransform.OfVector(XYZ.BasisY); double startAngle2 = 0; double endAngle2 = 2 * Math.PI; double radius2 = 1.23; Arc geomPlane3 = Arc.Create(myTransform.OfPoint(new XYZ(0, 0, 0)), radius2, startAngle2, endAngle2, xVec, yVec); ModelArc arc = doc.Create.NewModelCurve(geomPlane3, mySketchPlane) as ModelArc; //doc.Delete(sketch2.Id); doc.ActiveView.SetElementOverrides(arc.Id, ogs); } } tx.Commit(); uidoc.RefreshActiveView(); } } transGroup.Assimilate(); } } #region catch and finally catch (Exception ex) { _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE05_Part1" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true); } finally { } #endregion }