Transform CalculateTransform(RevilationPad masterPad) { this.translationVector = this.CenterPoint - masterPad.CenterPoint; var translationTransform = Transform.CreateTranslation(this.translationVector); this.rotation = 0.0; var rotationTransform = Transform.CreateRotation(XYZ.BasisZ, this.rotation); return(translationTransform.Multiply(rotationTransform)); }
FamilyInstance CreateDetailObject(FamilyInstance elem, FamilySymbol symbol, RevilationPad masterPad, RevilationPad pad, View viewToPlaceOn) { var doc = elem.Document; var placement = ((elem.Location is LocationPoint) ? (elem.Location as LocationPoint).Point : (elem.Location as LocationCurve).Curve.Evaluate(0.5, true)); var remappedPoint = pad.CalculatePlacementLocation(placement, masterPad); if (!symbol.IsActive) { symbol.Activate(); } return(doc.Create.NewFamilyInstance(remappedPoint, symbol, viewToPlaceOn)); }
FamilyInstance CreateCopyElement(FamilyInstance elem, RevilationPad masterPad, RevilationPad pad) { var doc = elem.Document; var placement = ((elem.Location is LocationPoint) ? (elem.Location as LocationPoint).Point : (elem.Location as LocationCurve).Curve.Evaluate(0.5, true)); var remappedPoint = pad.CalculatePlacementLocation(placement, masterPad); if (!elem.Symbol.IsActive) { elem.Symbol.Activate(); } return(doc.Create.NewFamilyInstance(remappedPoint, elem.Symbol, StructuralType.NonStructural)); //return elem.Document.GetElement(ElementTransformUtils.CopyElement(elem.Document, elem.Id, pad.Translation).FirstOrDefault()) as FamilyInstance; }
void SetElementDatas(FamilyInstance elem, FamilyInstance parentElement, RevilationPad pad) { //set the pad id elem.LookupParameter("RevilationsPadId").Set(pad.RevitElement.Id.IntegerValue.ToString()); //set the parent ids var parentIdsParam = elem.LookupParameter("RevilationsParents"); var parentIdsString = parentIdsParam.AsString(); var parentIdString = (parentIdsString == null || parentIdsString.Equals(string.Empty)) ? $"{parentElement.Id.IntegerValue}" : $"{parentIdsString};{parentElement.Id.IntegerValue}"; parentIdsParam.Set(parentIdString); //set the child ids var childrenIdsParam = parentElement.LookupParameter("RevilationsChildren"); var childrenIdsString = childrenIdsParam.AsString(); var childrenIdString = (childrenIdsString == null || childrenIdsString.Equals(string.Empty)) ? $"{elem.Id.IntegerValue}" : $"{childrenIdsString};{elem.Id.IntegerValue}"; childrenIdsParam.Set(childrenIdString); }
public XYZ CalculatePlacementLocation(XYZ referPt, RevilationPad referPad) { var referPadbb = referPad.RevitElement.get_BoundingBox(null); var refPadRemapX = Remap(referPt.X, referPadbb.Min.X, referPadbb.Max.X, 0.0, 0.1); var refPadRemapY = Remap(referPt.Y, referPadbb.Min.Y, referPadbb.Max.Y, 0.0, 0.1); var refPadRemapZ = Remap(referPt.Z, referPadbb.Min.Z, referPadbb.Max.Z, 0.0, 0.1); //TaskDialog.Show("Revilation", $"{refPadRemapX}-{refPadRemapY}-{refPadRemapZ}"); var thisbb = this.revitElement.get_BoundingBox(null); var thisPadRemapX = Remap(refPadRemapX, 0.0, 0.1, thisbb.Min.X, thisbb.Max.X); var thisPadRemapY = Remap(refPadRemapY, 0.0, 0.1, thisbb.Min.Y, thisbb.Max.Y); var thisPadRemapZ = Remap(refPadRemapZ, 0.0, 0.1, thisbb.Min.Z, thisbb.Max.Z); //TaskDialog.Show("Revilation", $"{thisPadRemapX}-{thisPadRemapY}-{thisPadRemapZ}"); return(new XYZ(thisPadRemapX, thisPadRemapY, referPt.Z)); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { var uidoc = commandData.Application.ActiveUIDocument; var allViews = CollectAllViews(uidoc.Document); var allDetailComponents = CollectAllDetailComponents(uidoc.Document); var control = new RevilationsInputControl(allViews, allDetailComponents); while (true) { control.ShowDialog(); if (control.SelectElements) { control.SetElements(uidoc.Selection.PickObjects(ObjectType.Element).Select(e => e.ElementId)); control.SelectElements = false; } else if (control.SelectPads) { control.SetPads(uidoc.Selection.PickObjects(ObjectType.Element).Select(e => e.ElementId)); control.SelectPads = false; } else { break; } } if (control.RunOnClose) { var masterElements = control.SelectedElements; var masterPad = new RevilationPad(masterElements.FirstOrDefault(e => e.Item1.Name.Equals(Revilations.PadFamilySymbolName)).Item1, null); var selectedPads = control.SelectedPads.Select(e => new RevilationPad(e, masterPad)); var viewToAddComponentsTo = control.SelectedView; using (var trans = new Transaction(uidoc.Document)) { trans.Start("Revilations"); foreach (var masterElement in masterElements) { if (masterElement.Item1.Id.IntegerValue != masterPad.RevitElement.Id.IntegerValue) { var createdElemIds = ""; foreach (var pad in selectedPads) { var createdElem = (masterElement.Item2 == null) ? this.CreateCopyElement(masterElement.Item1, masterPad, pad) : this.CreateDetailObject(masterElement.Item1, masterElement.Item2, masterPad, pad, viewToAddComponentsTo); createdElem.LookupParameter("RevilationsParents").Set(masterElement.Item1.Id.IntegerValue.ToString()); createdElem.LookupParameter("RevilationsPadId").Set(pad.RevitElement.Id.IntegerValue.ToString()); createdElemIds = $"{createdElemIds};{createdElem.Id.IntegerValue}"; } var placementPt = ((masterElement.Item1.Location is LocationPoint) ? (masterElement.Item1.Location as LocationPoint).Point : (masterElement.Item1.Location as LocationCurve).Curve.Evaluate(0.5, true)); masterElement.Item1.LookupParameter("RevilationsChildren").Set(createdElemIds); masterElement.Item1.LookupParameter("RevilationsX").Set($"{placementPt.X}"); masterElement.Item1.LookupParameter("RevilationsY").Set($"{placementPt.Y}"); masterElement.Item1.LookupParameter("RevilationsZ").Set($"{placementPt.Z}"); } } trans.Commit(); } return(Result.Succeeded); } else { return(Result.Cancelled); } } catch (Exception x) { TaskDialog.Show("Revilations", $"{x.Message}\n{x.StackTrace}"); return(Result.Failed); } }
public RevilationPad(FamilyInstance revitElement, RevilationPad masterPad) { this.revitElement = revitElement; this.isMaster = masterPad == null || this.revitElement == masterPad.RevitElement; this.transform = (this.isMaster) ? Transform.Identity : this.CalculateTransform(masterPad); }