public void Stream(Type type) { var part = _elem as Part; if (type == typeof(Element) && _elem is Element element) { _data.Add(new MemberSeparatorWithOffset(nameof(PartUtils))); _data.Add(new Bool(nameof(PartUtils.AreElementsValidForCreateParts), PartUtils.AreElementsValidForCreateParts(element.Document, new[] { element.Id }))); _data.Add(new Object(nameof(PartUtils.GetAssociatedPartMaker), PartUtils.GetAssociatedPartMaker(element.Document, element.Id))); _data.Add(new Bool(nameof(PartUtils.HasAssociatedParts), PartUtils.HasAssociatedParts(element.Document, element.Id))); _data.Add(new Bool(nameof(PartUtils.IsValidForCreateParts), PartUtils.IsValidForCreateParts(element.Document, new LinkElementId(element.Id)))); } if (type == typeof(Part) && part != null) { _data.Add(new MemberSeparatorWithOffset(nameof(PartUtils))); _data.Add(new Bool(nameof(PartUtils.ArePartsValidForDivide), PartUtils.ArePartsValidForDivide(part.Document, new[] { part.Id }))); _data.Add(new Bool(nameof(PartUtils.ArePartsValidForMerge), PartUtils.ArePartsValidForMerge(part.Document, new[] { part.Id }))); _data.Add(new Int(nameof(PartUtils.GetChainLengthToOriginal), PartUtils.GetChainLengthToOriginal(part))); var isMergedPart = PartUtils.IsMergedPart(part); _data.Add(new Enumerable(nameof(PartUtils.GetMergedParts), isMergedPart ? PartUtils.GetMergedParts(part) : Array.Empty <ElementId>(), part.Document)); _data.Add(new Bool(nameof(PartUtils.IsMergedPart), isMergedPart)); _data.Add(new Bool(nameof(PartUtils.IsPartDerivedFromLink), PartUtils.IsPartDerivedFromLink(part))); _data.Add(new MemberSeparatorWithOffset(nameof(Part))); _data.Add(new String(nameof(Part.OriginalCategoryId), ((BuiltInCategory)part.OriginalCategoryId.IntegerValue).ToString())); var sourceElementIds = part.GetSourceElementIds().Where(e => e.HostElementId != ElementId.InvalidElementId).Select(e => e.HostElementId).ToList(); _data.Add(new Enumerable(nameof(Part.GetSourceElementIds), sourceElementIds, part.Document)); var sourceCategoryIds = part.GetSourceElementOriginalCategoryIds().Select(e => (BuiltInCategory)e.IntegerValue).ToList(); _data.Add(new EnumerableAsString(nameof(Part.GetSourceElementOriginalCategoryIds), sourceCategoryIds)); } }
public bool Create() { IList <ElementId> idList = new List <ElementId>(); ICollection <ElementId> elementIdsToDivide = new List <ElementId>(); idList.Add(Floor.Id); if (PartUtils.AreElementsValidForCreateParts(PublicVariables.Doc, idList)) { using (Transaction tr = new Transaction(PublicVariables.Doc, "CreatePart")) { tr.Start(); try { PartUtils.CreateParts(PublicVariables.Doc, idList); tr.Commit(); } catch { tr.RollBack(); } elementIdsToDivide = PartUtils.GetAssociatedParts(PublicVariables.Doc , Floor.Id, true, true); } } ICollection <ElementId> intersectingReferenceIds = new List <ElementId>(); var curveList = (from Curve elem in BoundingSquare select elem).ToList(); using (Transaction tr = new Transaction(PublicVariables.Doc, "DivideParts")) { tr.Start(); try { SketchPlane sp = SketchPlane.Create(PublicVariables.Doc, Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), BoundingSquare[0].GetEndPoint(0))); PartMaker maker = PartUtils.DivideParts(PublicVariables.Doc, elementIdsToDivide, intersectingReferenceIds, curveList, sp.Id); Parameter partVisInView = PublicVariables.Doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY); partVisInView.Set(0); tr.Commit(); } catch { tr.RollBack(); } } return(true); }
public Result Execute( ExternalCommandData cmdData, ref string msg, ElementSet elems) { Result result = Result.Failed; UIApplication uiApp = cmdData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; Transaction transaction = new Transaction(doc); try { string strMsg = "Select walls"; ISelectionFilter filter = new WallSelectionFilter(); IList <Reference> walls = uiDoc.Selection.PickObjects( ObjectType.Element, filter, strMsg); if (walls.Count == 0) { return(result); } List <ElementId> ids = new List <ElementId>(); foreach (Reference reference in walls) { ids.Add(reference.ElementId); } if (!PartUtils.AreElementsValidForCreateParts( doc, ids)) { return(result); } transaction.Start("parts"); // Split walls into parts PartUtils.CreateParts(doc, ids); // Regenerate document to get the part geometry doc.Regenerate(); // Retrieve points from bottom faces of parts List <List <XYZ> > bottomFacesPts = new List <List <XYZ> >(); foreach (ElementId id in ids) { if (!PartUtils.HasAssociatedParts(doc, id)) { continue; } ICollection <ElementId> partIds = PartUtils.GetAssociatedParts( doc, id, true, true); foreach (ElementId partId in partIds) { Element part = doc.GetElement(partId); bottomFacesPts.Add( GetBottomFacePoints(part)); } } // Do not affect the original state of walls transaction.RollBack(); // Draw lines to show the bottom faces of parts transaction.Start(); ModelLineCreator model = new ModelLineCreator(doc); foreach (List <XYZ> bottomFacePts in bottomFacesPts) { for (int i = 1; i < bottomFacePts.Count; ++i) { model.CreateLine(bottomFacePts[i - 1], bottomFacePts[i], true); } if (bottomFacePts.Count > 3) { model.CreateLine(bottomFacePts[0], bottomFacePts[bottomFacePts.Count - 1], true); } } transaction.Commit(); result = Result.Succeeded; } catch (System.Exception e) { msg = e.Message; result = Result.Failed; } return(result); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { string input = Interaction.InputBox("Enter the panel width in millimeters", "CLT Creator", "250", -1, -1); double inputnum = Convert.ToDouble(input); /* * var hi = new TaskDialog("Hi") * { * MainContent = inputnum, * MainIcon = TaskDialogIcon.TaskDialogIconInformation, * CommonButtons = TaskDialogCommonButtons.Ok * }; * hi.Show(); */ try { if (null == commandData) { throw new ArgumentNullException("commandData"); } UIApplication uiapp = commandData.Application; Application app = uiapp.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Reference r = null; try { r = uidoc.Selection.PickObject( ObjectType.Element, new WallSelectionFilter(), "Select a wall to split into panels"); } catch (Autodesk.Revit.Exceptions .OperationCanceledException) { return(Result.Cancelled); } Wall wall = (r == null || r.ElementId == ElementId.InvalidElementId) ? null : doc.GetElement(r.ElementId) as Wall; if (wall == null) { message = "Unable to retrieve wall."; return(Result.Failed); } LocationCurve location = wall.Location as LocationCurve; if (null == location) { message = "Unable to retrieve wall location curve."; return(Result.Failed); } Line line = location.Curve as Line; if (null == location) { message = "Unable to retrieve wall location line."; return(Result.Failed); } using (Transaction transaction = new Transaction(doc)) { transaction.Start("Building panels"); IList <ElementId> wallList = new List <ElementId>(1); wallList.Add(r.ElementId); if (PartUtils.AreElementsValidForCreateParts( doc, wallList)) { PartUtils.CreateParts(doc, wallList); doc.Regenerate(); ICollection <ElementId> parts = PartUtils.GetAssociatedParts( doc, wall.Id, false, false); if (PartUtils.ArePartsValidForDivide( doc, parts)) { double divisions = line.Length / (inputnum / 25.4 / 12); XYZ origin = line.Origin; XYZ delta = line.Direction.Multiply( inputnum / 25.4 / -12); Transform shiftDelta = Transform.CreateTranslation(delta); // Construct a 90 degree rotation in the // XY plane around the line start point Transform rotation = Transform.CreateRotationAtPoint( XYZ.BasisZ, 0.5 * Math.PI, origin); // A vector perpendicular to the wall with // length equal to twice the wall witdh XYZ wallWidthVector = rotation.OfVector( line.Direction.Multiply(2 * wall.Width)); Curve intersectionLine = Line.CreateBound( // Line.CreateBound location.Curve.GetEndPoint(1) + wallWidthVector, location.Curve.GetEndPoint(1) - wallWidthVector); IList <Curve> curveArray = new List <Curve>(); //Jeremy's Modelline Code //XYZ v = 2*wallWidthVector; //double dxy = Math.Abs(v.X) + Math.Abs(v.Y); //XYZ w = (dxy > 1.0e-9)? XYZ.BasisZ: XYZ.BasisY; //XYZ norm = v.CrossProduct(w).Normalize(); //Plane plane = Plane.CreateByNormalAndOrigin(norm, origin + wallWidthVector); //SketchPlane sketchPlane = SketchPlane.Create(doc, plane); //Jeremy's code end for (int i = 1; i < divisions; ++i) { intersectionLine = intersectionLine.CreateTransformed(shiftDelta); //ModelCurve curve = doc.IsFamilyDocument ? doc.FamilyCreate.NewModelCurve(intersectionLine, sketchPlane) : doc.Create.NewModelCurve(intersectionLine, sketchPlane); curveArray.Add(intersectionLine); } SketchPlane divisionSketchPlane = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, origin)); // An empty list of intersecting ElementIds IList <ElementId> intersectionElementIds = new List <ElementId>(); PartUtils.DivideParts(doc, parts, intersectionElementIds, curveArray, divisionSketchPlane.Id); } doc.ActiveView.PartsVisibility = PartsVisibility.ShowPartsOnly; } transaction.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }