public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if ((uidoc.ActiveView as View3D) == null) { message = "Por favor, rode este comando em uma vista 3d"; return(Result.Failed); } ISelectionFilter ridgeSelectionFilter = new RoofClasses.SelectionFilters.StraightLinesAndFacesRidgeSelectionFilter(doc); Reference currentReference = uidoc.Selection.PickObject(ObjectType.Edge, ridgeSelectionFilter); FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference) as FootPrintRoof; Edge edge = Support.GetEdgeFromReference(currentReference, currentFootPrintRoof); IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof) , currentFootPrintRoof, out pfaces); IList <RoofClasses.EdgeInfo> currentEdgeInfoList = Support.GetRoofEdgeInfoList(currentFootPrintRoof, false); Curve currentCurve = Support.GetMostSimilarCurve(edge.AsCurve(), currentEdgeInfoList); RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, currentCurve, pfaces); TaskDialog.Show("fac", currentInfo.RoofLineType.ToString()); Element tTypeElement = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(fsy => fsy is TrussType).ToList().FirstOrDefault(); if (tTypeElement == null) { message = "Nenhum tipo de treliça foi encontrada no projeto, por favor, carregue um tipo e rode este comando novamente"; return(Result.Failed); } TrussType tType = tTypeElement as TrussType; Managers.TrussRidgeManager currentTrussManager = new Managers.TrussRidgeManager(); IList <RoofClasses.TrussInfo> currentTrussInfoList = currentTrussManager.CreateTrussesFromRidgeInfo(currentInfo, tType); TaskDialog tDialog = new TaskDialog("Trusses"); tDialog.MainInstruction = currentTrussInfoList.Count.ToString(); tDialog.Show(); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if ((uidoc.ActiveView as View3D) == null) { message = "Por favor, rode este comando em uma vista 3d"; return(Result.Failed); } Reference currentReference = uidoc.Selection.PickObject(ObjectType.Edge); FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference.ElementId) as FootPrintRoof; Edge edge = currentFootPrintRoof.GetGeometryObjectFromReference(currentReference) as Edge; IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof).Union(HostObjectUtils.GetTopFaces(currentFootPrintRoof)).ToList() , currentFootPrintRoof, out pfaces); RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, edge.AsCurve(), pfaces); using (Transaction t = new Transaction(doc, "Test")) { t.Start(); FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol; fs.Activate(); doc.Create.NewFamilyInstance((currentInfo.Curve as Line).Direction, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(-90), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(45), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); t.Commit(); } return(Result.Succeeded); }