public List <RevitParameter> Parameters(RevitObject familyName, string typeName) { if (IsValid()) { try { List <RevitParameter> parameters = _channel.GetParameters(familyName, typeName); return(parameters); } catch { List <RevitParameter> errors = new List <RevitParameter>(); RevitParameter rp = new RevitParameter("Error", "Error", "Error", false); errors.Add(rp); return(errors); } } return(null); }
public List <string> TypeNames(RevitObject familyName) { if (IsValid()) { try { List <string> typeNames = _channel.GetTypeNames(familyName); return(typeNames); } catch { List <string> errors = new List <string> { "Error" }; return(errors); } } return(null); }
private void familyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { RevitObject fam = familyComboBox.SelectedItem as RevitObject; if (fam != null) { familyName = fam.FamilyName; category = fam.Category; catNameLabel.Content = "[ " + category + " ]"; categoryId = fam.CategoryId; familyObj = fam; } // get the type names typeNames = new List<string>(); typeNames = channel.TypeNames(familyObj).ToList(); if (typeNames != null && typeNames.Count > 0) { typeComboBox.ItemsSource = typeNames; typeComboBox.SelectedIndex = 0; string type = parent.TypeName; if (!string.IsNullOrEmpty(type)) { for (int i = 0; i < typeNames.Count; i++) { string t = typeNames[i]; if (type == t) { typeComboBox.SelectedIndex = i; usedParameters = parent.InputParams; AddControls(); } } } } }
List<RevitObject> ILyrebirdService.GetFamilyNames() { familyNames.Add(new RevitObject("NULL", -1, "NULL")); lock (_locker) { try { UIApplication uiApp = RevitServerApp.UIApp; familyNames = new List<RevitObject>(); // Get all standard wall families FilteredElementCollector familyCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); familyCollector.OfClass(typeof(Family)); List<RevitObject> families = new List<RevitObject>(); foreach (Family f in familyCollector) { RevitObject ro = new RevitObject(f.FamilyCategory.Name, f.FamilyCategory.Id.IntegerValue, f.Name); families.Add(ro); } // Add System families FilteredElementCollector wallTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallTypeCollector.OfClass(typeof(WallType)); WallType wt = wallTypeCollector.FirstElement() as WallType; if (wt != null) { RevitObject wallObj = new RevitObject(wt.Category.Name, wt.Category.Id.IntegerValue, wt.Category.Name); families.Add(wallObj); } //RevitObject curtainObj = new RevitObject("Walls", "Curtain Wall"); //families.Add(curtainObj); //RevitObject stackedObj = new RevitObject("Walls", "Stacked Wall"); //families.Add(stackedObj); FilteredElementCollector floorTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); floorTypeCollector.OfClass(typeof(FloorType)); FloorType ft = floorTypeCollector.FirstElement() as FloorType; if (ft != null) { RevitObject floorObj = new RevitObject(ft.Category.Name, ft.Category.Id.IntegerValue, ft.Category.Name); families.Add(floorObj); } FilteredElementCollector roofTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); roofTypeCollector.OfClass(typeof(RoofType)); RoofType rt = roofTypeCollector.FirstElement() as RoofType; if (rt != null) { RevitObject roofObj = new RevitObject(rt.Category.Name, rt.Category.Id.IntegerValue, rt.Category.Name); families.Add(roofObj); } FilteredElementCollector levelTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); levelTypeCollector.OfClass(typeof(LevelType)); LevelType lt = levelTypeCollector.FirstElement() as LevelType; if (lt != null) { RevitObject levelObj = new RevitObject(lt.Category.Name, lt.Category.Id.IntegerValue, lt.Category.Name); families.Add(levelObj); } FilteredElementCollector gridTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); gridTypeCollector.OfClass(typeof(GridType)); GridType gt = gridTypeCollector.FirstElement() as GridType; if (gt != null) { RevitObject gridObj = new RevitObject(gt.Category.Name, gt.Category.Id.IntegerValue, gt.Category.Name); families.Add(gridObj); } FilteredElementCollector lineTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); lineTypeCollector.OfCategory(BuiltInCategory.OST_Lines); try { CurveElement ce = lineTypeCollector.FirstElement() as CurveElement; RevitObject modelLineObj = new RevitObject(ce.Category.Name, ce.Category.Id.IntegerValue, "Model Lines"); RevitObject detailLineObj = new RevitObject(ce.Category.Name, ce.Category.Id.IntegerValue, "Detail Lines"); families.Add(modelLineObj); families.Add(detailLineObj); } catch { RevitObject modelLineObj = new RevitObject("Lines", -2000051, "Model Lines"); RevitObject detailLineObj = new RevitObject("Lines", -2000051, "Detail Lines"); families.Add(modelLineObj); families.Add(detailLineObj); } families.Sort((x, y) => String.CompareOrdinal(x.FamilyName.ToUpper(), y.FamilyName.ToUpper())); familyNames = families; } catch (Exception exception) { Debug.WriteLine(exception.Message); } Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout); } return familyNames; }
List<RevitParameter> ILyrebirdService.GetParameters(RevitObject revitFamily, string typeName) { lock (_locker) { TaskContainer.Instance.EnqueueTask(uiApp => { var doc = uiApp.ActiveUIDocument.Document; parameters = new List<RevitParameter>(); if (revitFamily.CategoryId == -2000011) { // do stuff for walls FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallCollector.OfClass(typeof(WallType)); wallCollector.OfCategory(BuiltInCategory.OST_Walls); foreach (WallType wt in wallCollector) { if (wt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in wt.Parameters) { if(!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); Wall wall = null; try { Curve c = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); if (l != null) wall = Wall.Create(doc, c, l.Id, false); } catch (Exception exception) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(exception.Message); } if (wall != null) { foreach (Parameter p in wall.Parameters) { //if(!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000032) { // get parameters for floors FilteredElementCollector floorCollector = new FilteredElementCollector(doc); floorCollector.OfClass(typeof(FloorType)); floorCollector.OfCategory(BuiltInCategory.OST_Floors); foreach (FloorType ft in floorCollector) { if (ft.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in ft.Parameters) { if(!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); Floor floor = null; try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (floor != null) { foreach (Parameter p in floor.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000035) { // get parameters for a roof FilteredElementCollector roofCollector = new FilteredElementCollector(doc); roofCollector.OfClass(typeof(RoofType)); roofCollector.OfCategory(BuiltInCategory.OST_Roofs); foreach (RoofType rt in roofCollector) { if (rt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in rt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); FootPrintRoof roof = null; try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); ModelCurveArray curveArrayMapping = new ModelCurveArray(); roof = doc.Create.NewFootPrintRoof(profile, l, rt, out curveArrayMapping); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (roof != null) { foreach (Parameter p in roof.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000240) { // Level Families FilteredElementCollector levelCollector = new FilteredElementCollector(doc); levelCollector.OfClass(typeof(LevelType)); levelCollector.OfCategory(BuiltInCategory.OST_Levels); foreach (LevelType lt in levelCollector) { if (lt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in lt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp level")) { t.Start(); Level lvl = null; try { lvl = doc.Create.NewLevel(-1000.22); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (lvl != null) { foreach (Parameter p in lvl.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000220) { // Grid Families FilteredElementCollector gridCollector = new FilteredElementCollector(doc); gridCollector.OfClass(typeof(GridType)); gridCollector.OfCategory(BuiltInCategory.OST_Grids); foreach (GridType gt in gridCollector) { if (gt.Name == typeName) { // Get the type parameters List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in gt.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } // Get the instance parameters List<Parameter> instParameters = new List<Parameter>(); using (Transaction t = new Transaction(doc, "temp grid")) { t.Start(); Grid grid = null; try { Line ln = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 1, 0)); grid = doc.Create.NewGrid(ln); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (grid != null) { foreach (Parameter p in grid.Parameters) { if (!p.IsReadOnly) instParameters.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instParameters) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } break; } } } else if (revitFamily.CategoryId == -2000051) { // leave parameters empty } else { // Regular family. Proceed to get all parameters FilteredElementCollector familyCollector = new FilteredElementCollector(doc); familyCollector.OfClass(typeof(Family)); foreach (Family f in familyCollector) { if (f.Name == revitFamily.FamilyName) { ISet<ElementId> fsIds = f.GetFamilySymbolIds(); foreach (ElementId fsid in fsIds) { FamilySymbol fs = doc.GetElement(fsid) as FamilySymbol; if (fs.Name == typeName) { List<Parameter> typeParams = new List<Parameter>(); foreach (Parameter p in fs.Parameters) { if (!p.IsReadOnly) typeParams.Add(p); } List<Parameter> instanceParams = new List<Parameter>(); // temporary create an instance of the family to get instance parameters using (Transaction t = new Transaction(doc, "temp family")) { t.Start(); FamilyInstance fi = null; // Get the hosting type int hostType = f.get_Parameter(BuiltInParameter.FAMILY_HOSTING_BEHAVIOR).AsInteger(); if (hostType == 0) { // Typical } else if (hostType == 1) { // Wall hosted // Temporary wall Wall wall = null; Curve c = Line.CreateBound(new XYZ(-20, 0, 0), new XYZ(20, 0, 0)); FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { if (l != null) wall = Wall.Create(doc, c, l.Id, false); } catch (Exception ex) { // Failed to create the wall, no instance parameters will be found Debug.WriteLine(ex.Message); } if (wall != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, wall as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 2) { // Floor Hosted // temporary floor Floor floor = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the floor, no instance parameters will be found Debug.WriteLine(ex.Message); } if (floor != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, floor as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 3) { // Ceiling Hosted (might be difficult) // Try to find a ceiling FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); FilteredElementCollector ceilingCollector = new FilteredElementCollector(doc); Ceiling ceiling = ceilingCollector.OfClass(typeof(Ceiling)).ToElements().OfType<Ceiling>().FirstOrDefault(); if (ceiling != null) { // Find a point on the ceiling Options opt = new Options(); opt.ComputeReferences = true; GeometryElement ge = ceiling.get_Geometry(opt); List<List<XYZ>> verticePoints = new List<List<XYZ>>(); foreach (GeometryObject go in ge) { Solid solid = go as Solid; if (null == solid || 0 == solid.Faces.Size) { continue; } PlanarFace planarFace = null; double faceArea = 0; foreach (Face face in solid.Faces) { PlanarFace pf = null; try { pf = face as PlanarFace; } catch { } if (pf != null) { if (pf.Area > faceArea) { planarFace = pf; } } } if (planarFace != null) { Mesh mesh = planarFace.Triangulate(); int triCnt = mesh.NumTriangles; MeshTriangle bigTriangle = null; for (int tri = 0; tri < triCnt; tri++) { if (bigTriangle == null) { bigTriangle = mesh.get_Triangle(tri); } else { MeshTriangle mt = mesh.get_Triangle(tri); double area = Math.Abs(((mt.get_Vertex(0).X * (mt.get_Vertex(1).Y - mt.get_Vertex(2).Y)) + (mt.get_Vertex(1).X * (mt.get_Vertex(2).Y - mt.get_Vertex(0).Y)) + (mt.get_Vertex(2).X * (mt.get_Vertex(0).Y - mt.get_Vertex(1).Y))) / 2); double bigTriArea = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2); if (area > bigTriArea) { bigTriangle = mt; } } } if (bigTriangle != null) { double test = Math.Abs(((bigTriangle.get_Vertex(0).X * (bigTriangle.get_Vertex(1).Y - bigTriangle.get_Vertex(2).Y)) + (bigTriangle.get_Vertex(1).X * (bigTriangle.get_Vertex(2).Y - bigTriangle.get_Vertex(0).Y)) + (bigTriangle.get_Vertex(2).X * (bigTriangle.get_Vertex(0).Y - bigTriangle.get_Vertex(1).Y))) / 2); } try { List<XYZ> ptList = new List<XYZ>(); ptList.Add(bigTriangle.get_Vertex(0)); ptList.Add(bigTriangle.get_Vertex(1)); ptList.Add(bigTriangle.get_Vertex(2)); verticePoints.Add(ptList); } catch { } break; } } if (verticePoints.Count > 0) { List<XYZ> vertices = verticePoints[0]; XYZ midXYZ = vertices[1] + (0.5 * (vertices[2] - vertices[1])); XYZ centerPt = vertices[0] + (0.666667 * (midXYZ - vertices[0])); if (ceiling != null) { fi = doc.Create.NewFamilyInstance(centerPt, fs, ceiling as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } } else if (hostType == 4) { // Roof Hosted // Temporary roof FootPrintRoof roof = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); FilteredElementCollector roofTypeCollector = new FilteredElementCollector(doc); RoofType rt = roofTypeCollector.OfClass(typeof(RoofType)).ToElements().OfType<RoofType>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); ModelCurveArray roofProfile = new ModelCurveArray(); roof = doc.Create.NewFootPrintRoof(profile, l, rt, out roofProfile); } catch (Exception ex) { // Failed to create the roof, no instance parameters will be found Debug.WriteLine(ex.Message); } if (roof != null) { fi = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fs, roof as Element, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } else if (hostType == 5) { // temporary floor Floor floor = null; FilteredElementCollector lvlCollector = new FilteredElementCollector(doc); Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault(); try { Curve c1 = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(1, 1, 0)); Curve c3 = Line.CreateBound(new XYZ(1, 1, 0), new XYZ(0, 1, 0)); Curve c4 = Line.CreateBound(new XYZ(0, 1, 0), new XYZ(0, 0, 0)); CurveArray profile = new CurveArray(); profile.Append(c1); profile.Append(c2); profile.Append(c3); profile.Append(c4); floor = doc.Create.NewFloor(profile, false); } catch (Exception ex) { // Failed to create the floor, no instance parameters will be found Debug.WriteLine(ex.Message); } // Find a face on the floor to host to. Face face = FindFace(XYZ.Zero, XYZ.BasisZ, doc); if (face != null) { fi = doc.Create.NewFamilyInstance(face, XYZ.Zero, new XYZ(0, -1, 0), fs); } else { // regular creation. Some parameters will be missing fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } // Create a typical family instance try { fi = doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } catch (Exception ex) { Debug.WriteLine(ex.Message); } // TODO: Try creating other family instances like walls, sketch based, ... and getting the instance params if (fi != null) { foreach (Parameter p in fi.Parameters) { if (!p.IsReadOnly) instanceParams.Add(p); } } t.RollBack(); } typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); instanceParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name)); foreach (Parameter p in typeParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = true }; parameters.Add(rp); } foreach (Parameter p in instanceParams) { RevitParameter rp = new RevitParameter { ParameterName = p.Definition.Name, StorageType = p.StorageType.ToString(), IsType = false }; parameters.Add(rp); } } } break; } } } }); } return parameters; }
List<string> ILyrebirdService.GetTypeNames(RevitObject revitFamily) { typeNames.Add("NULL"); lock (_locker) { try { UIApplication uiApp = RevitServerApp.UIApp; var doc = uiApp.ActiveUIDocument.Document; typeNames = new List<string>(); List<string> types = new List<string>(); if (revitFamily.CategoryId == -2000011) { // get wall types FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallCollector.OfClass(typeof(WallType)); wallCollector.OfCategory(BuiltInCategory.OST_Walls); foreach (WallType wt in wallCollector) { types.Add(wt.Name); } } else if (revitFamily.CategoryId == -2000032) { // Get floor types FilteredElementCollector floorCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); floorCollector.OfClass(typeof(FloorType)); floorCollector.OfCategory(BuiltInCategory.OST_Floors); foreach (FloorType ft in floorCollector) { types.Add(ft.Name); } } else if (revitFamily.CategoryId == -2000035) { // Get roof types FilteredElementCollector roofCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); roofCollector.OfClass(typeof(RoofType)); roofCollector.OfCategory(BuiltInCategory.OST_Roofs); foreach (RoofType rt in roofCollector) { types.Add(rt.Name); } } else if (revitFamily.CategoryId == -2000240) { // Get Level Types FilteredElementCollector levelCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); levelCollector.OfClass(typeof(LevelType)); levelCollector.OfCategory(BuiltInCategory.OST_Levels); foreach (LevelType lt in levelCollector) { types.Add(lt.Name); } } else if (revitFamily.CategoryId == -2000220) { // Get Grid Types FilteredElementCollector gridCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); gridCollector.OfClass(typeof(GridType)); gridCollector.OfCategory(BuiltInCategory.OST_Grids); foreach (GridType gt in gridCollector) { types.Add(gt.Name); } } else if (revitFamily.CategoryId == -2000051) { Categories cats = doc.Settings.Categories; Category lineCat = null; foreach (Category cat in cats) { if (cat.Id.IntegerValue == -2000051) { lineCat = cat; break; } } if (lineCat != null) { foreach (Category subCat in lineCat.SubCategories) { if (revitFamily.FamilyName == "Model Lines") types.Add(subCat.Name); else if (revitFamily.FamilyName == "Detail Lines" && !subCat.Name.StartsWith("<") && !subCat.Name.EndsWith(">")) types.Add(subCat.Name); } } } else { // Get typical family types. FilteredElementCollector familyCollector = new FilteredElementCollector(doc); familyCollector.OfClass(typeof(Family)); foreach (Family f in familyCollector) { if (f.Name == revitFamily.FamilyName) { ISet<ElementId> fsIds = f.GetFamilySymbolIds(); foreach (ElementId fsid in fsIds) { FamilySymbol fs = doc.GetElement(fsid) as FamilySymbol; types.Add(fs.Name); } break; } } } types.Sort((x, y) => String.CompareOrdinal(x.ToUpper(), y.ToUpper())); typeNames = types; } catch (Exception exception) { Debug.WriteLine(exception.Message); } Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout); } return typeNames; }
protected override void SolveInstance(IGH_DataAccess DA) { bool runCommand = false; GH_Structure<GH_Point> origPoints = new GH_Structure<GH_Point>(); GH_Structure<GH_Point> adaptPoints = new GH_Structure<GH_Point>(); GH_Structure<GH_Curve> curves = new GH_Structure<GH_Curve>(); GH_Structure<GH_Vector> orientations = new GH_Structure<GH_Vector>(); GH_Structure<GH_Vector> faceOrientations = new GH_Structure<GH_Vector>(); DA.GetData(0, ref runCommand); DA.GetDataTree(1, out origPoints); DA.GetDataTree(2, out adaptPoints); DA.GetDataTree(3, out curves); DA.GetDataTree(4, out orientations); DA.GetDataTree(5, out faceOrientations); // Make sure the family and type is set before running the command. if (runCommand && (familyName == null || familyName == "Not Selected")) { message = "Please select a family/type by double-clicking on the component before running the command."; } else if (runCommand) { // Get the scale GHInfo ghi = new GHInfo(); GHScale scale = ghi.GetScale(Rhino.RhinoDoc.ActiveDoc); // Send to Revit LyrebirdChannel channel = new LyrebirdChannel(appVersion); channel.Create(); if (channel != null) { string documentName = channel.DocumentName(); if (documentName != null) { // Create RevitObjects List<RevitObject> obj = new List<RevitObject>(); #region OriginPoint Based if (origPoints != null && origPoints.Branches.Count > 0) { List<RevitObject> tempObjs = new List<RevitObject>(); // make sure the branches match the datacount if (origPoints.Branches.Count == origPoints.DataCount) { for (int i = 0; i < origPoints.Branches.Count; i++) { GH_Point ghpt = origPoints[i][0]; LyrebirdPoint point = new LyrebirdPoint { X = ghpt.Value.X, Y = ghpt.Value.Y, Z = ghpt.Value.Z }; RevitObject ro = new RevitObject { Origin = point, FamilyName = familyName, TypeName = typeName, Category = category, CategoryId = categoryId, GHPath = origPoints.Paths[i].ToString(), GHScaleFactor = scale.ScaleFactor, GHScaleName = scale.ScaleName }; tempObjs.Add(ro); } obj = tempObjs; } else { // Inform the user they need to graft their inputs. Only one point per branch System.Windows.Forms.MessageBox.Show("Warning:\n\nEach Branch represents an object, " + "so origin point based elements should be grafted so that each point is on it's own branch."); } } #endregion #region AdaptiveComponents else if (adaptPoints != null && adaptPoints.Branches.Count > 0) { // generate adaptive components List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < adaptPoints.Branches.Count; i++) { RevitObject ro = new RevitObject(); List<LyrebirdPoint> points = new List<LyrebirdPoint>(); for (int j = 0; j < adaptPoints.Branches[i].Count; j++) { LyrebirdPoint point = new LyrebirdPoint(adaptPoints.Branches[i][j].Value.X, adaptPoints.Branches[i][j].Value.Y, adaptPoints.Branches[i][j].Value.Z); points.Add(point); } ro.AdaptivePoints = points; ro.FamilyName = familyName; ro.TypeName = typeName; ro.Origin = null; ro.Category = category; ro.CategoryId = categoryId; ro.GHPath = adaptPoints.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; tempObjs.Add(ro); } obj = tempObjs; } #endregion #region Curve Based else if (curves != null && curves.Branches.Count > 0) { // Get curves for curve based components // Determine if we're profile or line based if (curves.Branches.Count == curves.DataCount) { // Determine if the curve is a closed planar curve Curve tempCrv = curves.Branches[0][0].Value; if (tempCrv.IsPlanar(0.00000001) && tempCrv.IsClosed) { // Closed planar curve List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < curves.Branches.Count; i++) { Curve crv = curves[i][0].Value; List<Curve> rCurves = new List<Curve>(); bool getCrvs = CurveSegments(rCurves, crv, true); if (rCurves.Count > 0) { RevitObject ro = new RevitObject(); List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>(); for (int j = 0; j < rCurves.Count; j++) { LyrebirdCurve lbc; lbc = GetLBCurve(rCurves[j]); lbCurves.Add(lbc); } ro.Curves = lbCurves; ro.FamilyName = familyName; ro.Category = category; ro.CategoryId = categoryId; ro.TypeName = typeName; ro.Origin = null; ro.GHPath = curves.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; tempObjs.Add(ro); } } obj = tempObjs; } else if (!tempCrv.IsClosed) { // Line based. Can only be arc or linear curves List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < curves.Branches.Count; i++) { Curve ghc = curves.Branches[i][0].Value; // Test that there is only one curve segment PolyCurve polycurve = ghc as PolyCurve; if (polycurve != null) { Curve[] segments = polycurve.Explode(); if (segments.Count() != 1) { break; } } if (ghc != null) { //List<LyrebirdPoint> points = new List<LyrebirdPoint>(); LyrebirdCurve lbc = GetLBCurve(ghc); List<LyrebirdCurve> lbcurves = new List<LyrebirdCurve> { lbc }; RevitObject ro = new RevitObject { Curves = lbcurves, FamilyName = familyName, Category = category, CategoryId = categoryId, TypeName = typeName, Origin = null, GHPath = curves.Paths[i].ToString(), GHScaleFactor = scale.ScaleFactor, GHScaleName = scale.ScaleName }; tempObjs.Add(ro); } } obj = tempObjs; } } else { // Make sure all of the curves in each branch are closed bool allClosed = true; DataTree<CurveCheck> crvTree = new DataTree<CurveCheck>(); for (int i = 0; i < curves.Branches.Count; i++) { List<GH_Curve> ghCrvs = curves.Branches[i]; List<CurveCheck> checkedcurves = new List<CurveCheck>(); GH_Path path = new GH_Path(i); for (int j = 0; j < ghCrvs.Count; j++) { Curve c = ghCrvs[j].Value; if (c.IsClosed) { AreaMassProperties amp = AreaMassProperties.Compute(c); if (amp != null) { double area = amp.Area; CurveCheck cc = new CurveCheck(c, area); checkedcurves.Add(cc); } } else { allClosed = false; } } if (allClosed) { // Sort the curves by area checkedcurves.Sort((x, y) => x.Area.CompareTo(y.Area)); checkedcurves.Reverse(); foreach (CurveCheck cc in checkedcurves) { crvTree.Add(cc, path); } } } if (allClosed) { // Determine if the smaller profiles are within the larger bool allInterior = true; List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < crvTree.Branches.Count; i++) { try { List<int> crvSegmentIds = new List<int>(); List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>(); List<CurveCheck> checkedCrvs = crvTree.Branches[i]; Curve outerProfile = checkedCrvs[0].Curve; double outerArea = checkedCrvs[0].Area; List<Curve> planarCurves = new List<Curve>(); planarCurves.Add(outerProfile); double innerArea = 0.0; for (int j = 1; j < checkedCrvs.Count; j++) { planarCurves.Add(checkedCrvs[j].Curve); innerArea += checkedCrvs[j].Area; } // Try to create a planar surface IEnumerable<Curve> surfCurves = planarCurves; Brep[] b = Brep.CreatePlanarBreps(surfCurves); if (b.Count() == 1) { // Test the areas double brepArea = b[0].GetArea(); double calcArea = outerArea - innerArea; double diff = (brepArea - calcArea) / calcArea; if (diff < 0.1) { // The profiles probably are all interior foreach (CurveCheck cc in checkedCrvs) { Curve c = cc.Curve; List<Curve> rCurves = new List<Curve>(); bool getCrvs = CurveSegments(rCurves, c, true); if (rCurves.Count > 0) { int crvSeg = rCurves.Count; crvSegmentIds.Add(crvSeg); foreach (Curve rc in rCurves) { LyrebirdCurve lbc; lbc = GetLBCurve(rc); lbCurves.Add(lbc); } } } RevitObject ro = new RevitObject(); ro.Curves = lbCurves; ro.FamilyName = familyName; ro.Category = category; ro.CategoryId = categoryId; ro.TypeName = typeName; ro.Origin = null; ro.GHPath = crvTree.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; ro.CurveIds = crvSegmentIds; tempObjs.Add(ro); } } else { allInterior = false; message = "Warning:\n\nEach Branch represents an object, " + "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " + "be interior to the largest, outer boundary."; } } catch { allInterior = false; // Inform the user they need to graft their inputs. Only one curve per branch message = "Warning:\n\nEach Branch represents an object, " + "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " + "be interior to the largest, outer boundary."; } } if (tempObjs.Count > 0) { obj = tempObjs; } } } } #endregion // Orientation if (orientations != null && orientations.Branches.Count > 0) { List<RevitObject> tempList = AssignOrientation(obj, orientations); obj = tempList; } // face orientation if (faceOrientations != null && faceOrientations.Branches.Count > 0) { List<RevitObject> tempList = AssignFaceOrientation(obj, faceOrientations); obj = tempList; } // Parameters... if (Params.Input.Count > 6) { List<RevitObject> currentObjs = obj; List<RevitObject> tempObjs = new List<RevitObject>(); for (int r = 0; r < currentObjs.Count; r++) { RevitObject ro = currentObjs[r]; List<RevitParameter> revitParams = new List<RevitParameter>(); for (int i = 6; i < Params.Input.Count; i++) { RevitParameter rp = new RevitParameter(); IGH_Param param = Params.Input[i]; string paramInfo = param.Description; string[] pi = paramInfo.Split(new[] { "\n", ":" }, StringSplitOptions.None); string paramName = null; try { paramName = pi[1].Substring(1); string paramStorageType = pi[5].Substring(1); rp.ParameterName = paramName; rp.StorageType = paramStorageType; } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (paramName != null) { GH_Structure<IGH_Goo> data = null; try { DA.GetDataTree(i, out data); } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (data != null) { string value = data[r][0].ToString(); rp.Value = value; revitParams.Add(rp); } } } ro.Parameters = revitParams; tempObjs.Add(ro); } obj = tempObjs; } // Send the data to Revit to create and/or modify family instances. if (obj != null && obj.Count > 0) { try { string docName = channel.DocumentName(); if (docName == null || docName == string.Empty) { message = "Could not contact the lyrebird server. Make sure it's running and try again."; } else { string nn = NickName; if (nn == null || nn.Length == 0) { nn = "LBOut"; } channel.CreateOrModify(obj, InstanceGuid, NickName); message = obj.Count.ToString() + " objects sent to the lyrebird server."; } } catch { message = "Could not contact the lyrebird server. Make sure it's running and try again."; } } channel.Dispose(); try { } catch (Exception ex) { Debug.WriteLine(ex.Message); } } else { message = "Error\n" + "The Lyrebird Service could not be found. Ensure Revit is running, the Lyrebird server plugin is installed, and the server is active."; } } } else { message = null; } // Check if the revit information is set if (familyName != null || (familyName != "Not Selected" && typeName != "Not Selected")) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Family: " + familyName); sb.AppendLine("Type: " + typeName); sb.AppendLine("Category: " + category); for (int i = 0; i < inputParameters.Count; i++) { RevitParameter rp = inputParameters[i]; string type = "Instance"; if (rp.IsType) { type = "Type"; } sb.AppendLine(string.Format("Parameter{0}: {1} / {2} / {3}", (i + 1).ToString(CultureInfo.InvariantCulture), rp.ParameterName, rp.StorageType, type)); } objMessage = sb.ToString(); } else { objMessage = "No data type set. Double-click to set data type"; } DA.SetData(0, objMessage); DA.SetData(1, message); }
public List<string> GetTypeNames(RevitObject revitFamily) { typeNames.Add("NULL"); lock (_locker) { try { UIApplication uiApp = RevitServerApp.UIApp; var doc = uiApp.ActiveUIDocument.Document; typeNames = new List<string>(); List<string> types = new List<string>(); if (revitFamily.CategoryId == -2000011) { // get wall types FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallCollector.OfClass(typeof(WallType)); wallCollector.OfCategory(BuiltInCategory.OST_Walls); foreach (WallType wt in wallCollector) { types.Add(wt.Name); } } else if (revitFamily.CategoryId == -2000032) { // Get floor types FilteredElementCollector floorCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); floorCollector.OfClass(typeof(FloorType)); floorCollector.OfCategory(BuiltInCategory.OST_Floors); foreach (FloorType ft in floorCollector) { types.Add(ft.Name); } } else if (revitFamily.CategoryId == -2000035) { // Get roof types FilteredElementCollector roofCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); roofCollector.OfClass(typeof(RoofType)); roofCollector.OfCategory(BuiltInCategory.OST_Roofs); foreach (RoofType rt in roofCollector) { types.Add(rt.Name); } } else { // Get typical family types. FilteredElementCollector familyCollector = new FilteredElementCollector(doc); familyCollector.OfClass(typeof(Family)); foreach (Family f in familyCollector) { if (f.Name == revitFamily.FamilyName) { FamilySymbolSet fss = f.Symbols; foreach (FamilySymbol fs in fss) { types.Add(fs.Name); } break; } } } types.Sort((x, y) => String.CompareOrdinal(x.ToUpper(), y.ToUpper())); typeNames = types; } catch (Exception exception) { Debug.WriteLine(exception.Message); } Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout); } return typeNames; }
public List<RevitObject> GetFamilyNames() { familyNames.Add(new RevitObject("NULL", -1, "NULL")); lock (_locker) { try { UIApplication uiApp = RevitServerApp.UIApp; familyNames = new List<RevitObject>(); // Get all standard wall families FilteredElementCollector familyCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); familyCollector.OfClass(typeof(Family)); List<RevitObject> families = new List<RevitObject>(); foreach (Family f in familyCollector) { RevitObject ro = new RevitObject(f.FamilyCategory.Name, f.FamilyCategory.Id.IntegerValue, f.Name); families.Add(ro); } // Add System families FilteredElementCollector wallTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); wallTypeCollector.OfClass(typeof(WallType)); WallType wt = wallTypeCollector.FirstElement() as WallType; if (wt != null) { RevitObject wallObj = new RevitObject(wt.Category.Name, wt.Category.Id.IntegerValue, wt.Category.Name); families.Add(wallObj); } //RevitObject curtainObj = new RevitObject("Walls", "Curtain Wall"); //families.Add(curtainObj); //RevitObject stackedObj = new RevitObject("Walls", "Stacked Wall"); //families.Add(stackedObj); FilteredElementCollector floorTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); floorTypeCollector.OfClass(typeof(FloorType)); FloorType ft = floorTypeCollector.FirstElement() as FloorType; if (ft != null) { RevitObject floorObj = new RevitObject(ft.Category.Name, ft.Category.Id.IntegerValue, ft.Category.Name); families.Add(floorObj); } FilteredElementCollector roofTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document); roofTypeCollector.OfClass(typeof(RoofType)); RoofType rt = roofTypeCollector.FirstElement() as RoofType; if (rt != null) { RevitObject roofObj = new RevitObject(rt.Category.Name, rt.Category.Id.IntegerValue, rt.Category.Name); families.Add(roofObj); } families.Sort((x, y) => String.CompareOrdinal(x.FamilyName.ToUpper(), y.FamilyName.ToUpper())); familyNames = families; } catch (Exception exception) { Debug.WriteLine(exception.Message); } Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout); } return familyNames; }
public List<string> TypeNames(RevitObject familyName) { if (IsValid()) { try { List<string> typeNames = _channel.GetTypeNames(familyName); return typeNames; } catch { List<string> errors = new List<string> {"Error"}; return errors; } } return null; }
public List<RevitParameter> Parameters(RevitObject familyName, string typeName) { if (IsValid()) { try { List<RevitParameter> parameters = _channel.GetParameters(familyName, typeName); return parameters; } catch { List<RevitParameter> errors = new List<RevitParameter>(); RevitParameter rp = new RevitParameter("Error", "Error", "Error", false); errors.Add(rp); return errors; } } return null; }