/// <summary> /// Recursively retrieve entire linked document /// hierarchy and return the resulting TreeNode /// structure. /// </summary> void GetChildren( Document mainDoc, ICollection<ElementId> ids, TreeNode parentNode ) { int level = parentNode.Level; foreach( ElementId id in ids ) { // Get the child information. RevitLinkType type = mainDoc.GetElement( id ) as RevitLinkType; string label = LinkLabel( type, level ); TreeNode subNode = new TreeNode( label ); Debug.Print( "{0}{1}", Indent( 2 * level ), label ); parentNode.Nodes.Add( subNode ); // Go to the next level. GetChildren( mainDoc, type.GetChildIds(), subNode ); } }
ElementId(string label, Autodesk.Revit.DB.ElementId val, Document doc) : base(label) { m_val = val; try { if (val != Autodesk.Revit.DB.ElementId.InvalidElementId) m_elem = doc.GetElement(val); // TBD: strange signature! } catch (System.Exception) { m_elem = null; } }
//user picks the viewport to move in the sheet public static Viewport pickView(Document doc, UIDocument uidoc) { Viewport viewport = null; ElementId id = uidoc.Selection.PickObject(ObjectType.Element, "PICK VIEWPORT").ElementId; Element elem = doc.GetElement(id); var type = elem.Category.Name; //compare the name of the category to the a string Viewports to make sure the user has selected a viewport. if (type == "Viewports") { Viewport vp = elem as Viewport; viewport = vp; return viewport; } //if the user has selected a element that isn't a viewport they should get this warning. else { MessageBox.Show("Warning", "Selection is not a viewport or not on a sheet."); } return viewport; }
List<string> GetParameters( Document doc, Element element ) { List<string> _parameters = new List<string>(); foreach( Parameter param in element.Parameters ) { if( param == null ) continue; string _name = param.Definition.Name; switch( param.StorageType ) { case Autodesk.Revit.Parameters.StorageType.Double: _parameters.Add( _name + " : " + param.AsDouble().ToString() ); break; case Autodesk.Revit.Parameters.StorageType.Integer: if( param.Definition.ParameterType == ParameterType.YesNo ) { if( param.AsInteger() == 0 ) _parameters.Add( _name + " : " + "false" ); else _parameters.Add( _name + " : " + "true" ); } else { _parameters.Add( _name + " : " + param.AsInteger().ToString() ); } break; case Autodesk.Revit.Parameters.StorageType.String: _parameters.Add( _name + " : " + param.AsString() ); break; case Autodesk.Revit.Parameters.StorageType.ElementId: ElementId id = param.AsElementId(); if( id.Value >= 0 ) _parameters.Add( _name + " : " + doc.GetElement( ref id ).Name ); else _parameters.Add( _name + " : " + id.Value.ToString() ); break; case Autodesk.Revit.Parameters.StorageType.None: _parameters.Add( _name + " : " + "none" ); break; } } return _parameters; }
PlaceColumn( Autodesk.Revit.ApplicationServices.Application rvtApp, Document rvtDoc, Autodesk.Revit.DB.XYZ point2, double angle, FamilySymbol columnType, ElementId baseLevelId, ElementId topLevelId ) { Autodesk.Revit.DB.XYZ point = point2; // Note: Must use level-hosted NewFamilyInstance! Level instLevel = (Level) rvtDoc.GetElement( baseLevelId ); Autodesk.Revit.DB.FamilyInstance column = rvtDoc.Create.NewFamilyInstance( point, columnType, instLevel, StructuralType.Column ); if( column == null ) { MessageBox.Show( "failed to create an instance of a column." ); return; } Autodesk.Revit.DB.XYZ zVec = new Autodesk.Revit.DB.XYZ( 0, 0, 1 ); Autodesk.Revit.DB.Line axis = Line.CreateUnbound( point, zVec ); column.Location.Rotate( axis, angle ); // Set the level Ids Parameter baseLevelParameter = column.get_Parameter( Autodesk.Revit.DB.BuiltInParameter.FAMILY_BASE_LEVEL_PARAM ); Parameter topLevelParameter = column.get_Parameter( Autodesk.Revit.DB.BuiltInParameter.FAMILY_TOP_LEVEL_PARAM ); ; baseLevelParameter.Set( baseLevelId ); topLevelParameter.Set( topLevelId ); }
/// <summary> /// Helper to return parameter value as string, with additional /// support for element id to display the element type referred to. /// </summary> public static string GetParameterValue2( Parameter param, Document doc ) { string s; if( StorageType.ElementId == param.StorageType && null != doc ) { ElementId id = param.AsElementId(); int i = id.IntegerValue; if( 0 > i ) { s = i.ToString() + BuiltInCategoryString( i ); } else { Element e = doc.GetElement( id ); s = ElementDescription( e, true ); } } else { s = GetParameterValue( param ); } return s; }
bool ChangeDiffuserSize( Document doc ) { // // iterate over all air terminal families and determine // the min and max flow assigned to each type. // // for each family, create a list of all its symbols // with their respective min and max flows. collect // these lists in a map keyed by family name: // Dictionary<string, List<SymbMinMax>> dictFamilyToSymbols = new Dictionary<string, List<SymbMinMax>>(); { WaitCursor waitCursor = new WaitCursor(); //Category categoryAirTerminal = doc.Settings.Categories.get_Item( BuiltInCategory.OST_DuctTerminal ); //ElementId categoryId = categoryAirTerminal.Id; //ElementIterator it = doc.get_Elements( typeof( Family ) ); FilteredElementCollector collector = new FilteredElementCollector( doc ) .OfClass( typeof( Family ) ); foreach( Family family in collector ) { ISet<ElementId> symbolIds = family.GetFamilySymbolIds(); // Family category is not implemented, // so check the symbols instead: bool categoryMatches = false; foreach( ElementId id in symbolIds ) { Element symbol = doc.GetElement( id ); // in 2008 and even 2009 beta 1, // you could compare categories directly: //categoryMatches = ( null != symbol.Category // && symbol.Category.Equals( categoryAirTerminal ) ); // in 2009, check the category id instead: categoryMatches = ( null != symbol.Category && symbol.Category.Id.IntegerValue.Equals( (int) BuiltInCategory.OST_DuctTerminal ) ); break; // we only need to check the first one } if( categoryMatches ) { List<SymbMinMax> familySymbols = new List<SymbMinMax>(); foreach( ElementId id in symbolIds ) { FamilySymbol symbol = doc.GetElement( id ) as FamilySymbol; SymbMinMax a = new SymbMinMax(); a.Symbol = symbol; a.Min = Util.GetParameterValueFromName( symbol, ParameterName.MinFlow ); a.Max = Util.GetParameterValueFromName( symbol, ParameterName.MaxFlow ); familySymbols.Add( a ); } dictFamilyToSymbols.Add( family.Name, familySymbols ); } } } // // prompt user to select which families to process: // //List<string> familyNames = new List<string>( dictFamilyToSymbols.Count ); //foreach( string s in dictFamilyToSymbols.Keys ) //{ // familyNames.Add( string.Format( "{0}({1})", s, dictFamilyToSymbols[s].Count ) ); //} List<string> familyNames = new List<string>( dictFamilyToSymbols.Keys ); familyNames.Sort(); FamilySelector fs = new FamilySelector( familyNames ); if( W.DialogResult.OK == fs.ShowDialog() ) { WaitCursor waitCursor = new WaitCursor(); FilteredElementCollector collector = Util.GetSupplyAirTerminals( doc ); IList<Element> terminals = collector.ToElements(); int n = terminals.Count; string s = "{0} of " + n.ToString() + " terminals processed..."; string caption = "Change Diffuser Size"; using( ProgressForm pf = new ProgressForm( caption, s, n ) ) { foreach( FamilyInstance terminal in terminals ) { string familyName = terminal.Symbol.Family.Name; if( fs.IsChecked( familyName ) ) { bool found = false; List<SymbMinMax> familySymbols = dictFamilyToSymbols[familyName]; double flow = Util.GetTerminalFlowParameter( terminal ).AsDouble(); foreach( SymbMinMax a in familySymbols ) { // // pick the first symbol found which matches our flow; // todo: this could be improved: // 1. we could sort the symbols by flow, and that would speed up the search // 2. we could report an error if multiple possible assignments are availabe // 3. we could improve the handling of borderline cases ... tend towards the smaller or bigger? // 4. we could build in a check after building each familySymbols ArrayList to ensure // that there is no ovelap in the flows and that the entire required flow spectrum is covered // if( a.Min <= flow && flow <= a.Max ) { terminal.Symbol = a.Symbol; found = true; break; } } if( !found ) { double flowInCfm = flow * Const.SecondsPerMinute; Util.ErrorMsg( string.Format( "No matching flow found for {0} with flow {1}.", Util.ElementDescription( terminal ), flowInCfm ) ); } } pf.Increment(); } } } return true; }
private static int getCalculationElemSet(Document doc, string strDomain, ElementSet caculationOnElems, ElementSet elems) { if (doc == null) return 0; int nTotalCount = 0; foreach (Element elem in elems) { MEPSystem mepSys = elem as MEPSystem; if (mepSys == null) continue; Category category = mepSys.Category; BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue; if ( (strDomain == ReportResource.pipeDomain && enumCategory == BuiltInCategory.OST_PipingSystem) || (strDomain == ReportResource.ductDomain && enumCategory == BuiltInCategory.OST_DuctSystem)) { ++nTotalCount; MEPSystemType sysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType; if (sysType != null && sysType.CalculationLevel == SystemCalculationLevel.All) { caculationOnElems.Insert(mepSys); } } } return nTotalCount; }
/// <summary> /// Extract the parameter information. /// By Dan Tartaglia. /// </summary> public string GetParameterInformation( Parameter para, Document doc) { string defName = ""; // Use different method to get parameter // data according to the storage type switch( para.StorageType ) { // Determine the parameter type case StorageType.Double: // Convert the number into Metric defName = para.AsValueString(); break; case StorageType.ElementId: // Find out the name of the element Autodesk.Revit.DB.ElementId id = para.AsElementId(); defName = ( id.IntegerValue >= 0 ) ? doc.GetElement( id ).Name : id.IntegerValue.ToString(); break; case StorageType.Integer: if( ParameterType.YesNo == para.Definition.ParameterType ) { if( para.AsInteger() == 0 ) { defName = "False"; } else { defName = "True"; } } else { defName = para.AsInteger().ToString(); } break; case StorageType.String: defName = para.AsString(); break; default: defName = "Unexposed parameter"; break; } return defName; }
private bool isCalculationOn(Document doc, Autodesk.Revit.DB.MEPSystem mepSys) { if (mepSys == null) return false; MEPSystemType sysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType; if (sysType == null) return false; return sysType.CalculationLevel == Autodesk.Revit.DB.Mechanical.SystemCalculationLevel.All; }
public Objects( Document doc, ICollection<ElementId> ids ) { InitializeComponent(); ICollection<Element> elemSet = new List<Element>( ids.Select<ElementId, Element>( id => doc.GetElement( id ) ) ); CommonInit( elemSet ); }
/// <summary> /// Get triangles in a solid with transform. /// </summary> /// <param name="solid">The solid contains triangulars</param> /// <param name="transform">The transformation.</param> private void GetTriangular(Document document, Solid solid, Transform transform) { // a solid has many faces FaceArray faces = solid.Faces; bool hasTransform = (null != transform); if (0 == faces.Size) { return; } foreach (Face face in faces) { if (face.Visibility != Visibility.Visible) { continue; } Mesh mesh = face.Triangulate(); if (null == mesh) { continue; } m_TriangularNumber += mesh.NumTriangles; PlanarFace planarFace = face as PlanarFace; // write face to stl file // a face has a mesh, all meshes are made of triangles for (int ii = 0; ii < mesh.NumTriangles; ii++) { MeshTriangle triangular = mesh.get_Triangle(ii); double[] xyz = new double[9]; Autodesk.Revit.DB.XYZ normal = new Autodesk.Revit.DB.XYZ(); try { Autodesk.Revit.DB.XYZ[] triPnts = new Autodesk.Revit.DB.XYZ[3]; for (int n = 0; n < 3; ++n) { double x, y, z; Autodesk.Revit.DB.XYZ point = triangular.get_Vertex(n); if (hasTransform) { point = transform.OfPoint(point); } if (m_Settings.ExportSharedCoordinates) { ProjectPosition ps = document.ActiveProjectLocation.get_ProjectPosition(point); x = ps.EastWest; y = ps.NorthSouth; z = ps.Elevation; } else { x = point.X; y = point.Y; z = point.Z; } if (m_Settings.Units != DisplayUnitType.DUT_UNDEFINED) { xyz[3 * n] = UnitUtils.ConvertFromInternalUnits(x, m_Settings.Units); xyz[3 * n + 1] = UnitUtils.ConvertFromInternalUnits(y, m_Settings.Units); xyz[3 * n + 2] = UnitUtils.ConvertFromInternalUnits(z, m_Settings.Units); } else { xyz[3 * n] = x; xyz[3 * n + 1] = y; xyz[3 * n + 2] = z; } triPnts[n] = point; } Autodesk.Revit.DB.XYZ pnt1 = triPnts[1] - triPnts[0]; normal = pnt1.CrossProduct(triPnts[2] - triPnts[1]); } catch (Exception ex) { m_TriangularNumber--; STLDialogManager.ShowDebug(ex.Message); continue; } if (m_Writer is SaveDataAsBinary && m_Settings.ExportColor) { Material material = document.GetElement(face.MaterialElementId) as Material; if(material!=null) ((SaveDataAsBinary)m_Writer).Color = material.Color; } m_Writer.WriteSection(normal, xyz); } } }
/// <summary> /// Export a non-empty solid. /// </summary> bool ExportSolid( IJtFaceEmitter emitter, Document doc, Solid solid, Color color, int transparency ) { Material m; Color c; int t; foreach( Face face in solid.Faces ) { m = doc.GetElement( face.MaterialElementId ) as Material; c = ( null == m ) ? color : m.Color; t = ( null == m ) ? transparency : m.Transparency; emitter.EmitFace( face, (null == c) ? DefaultColor : c, t ); } return true; }
/// <summary> /// Remove Openings from wall baseline /// </summary> /// <param name="breaks">List of Interruptions</param> /// <param name="wall">Wall</param> /// <param name="doc">Document</param> public void removeOpenings(ref List<Interruption> breaks, Wall wall, Document doc) { LocationCurve c = (LocationCurve)wall.Location; foreach (ElementId elemId in wall.FindInserts(true, false, false, false)) { Element insertedElement = doc.GetElement(elemId); if (insertedElement.GetType() == typeof(FamilyInstance)) { FamilyInstance o = (FamilyInstance)insertedElement; if (o.Location.GetType() == typeof(LocationPoint)) { LocationPoint lp = (LocationPoint)o.Location; c.Curve.GetEndPoint(0).DistanceTo(lp.Point); double width = o.Symbol.LookupParameter("Width").AsDouble(); breaks.Add(new Interruption(c.Curve, lp.Point, width)); } } } }
/// <summary> /// Get the Insulation Layer from a wall /// </summary> public Tuple<Curve, Curve> getInsulationLayer(Document doc, Wall wall) { double offset = 0; LocationCurve c = (LocationCurve)wall.Location; CompoundStructure cs = wall.WallType.GetCompoundStructure(); foreach (CompoundStructureLayer layer in cs.GetLayers()) { if (layer.MaterialId != null && layer.MaterialId != ElementId.InvalidElementId) { Material mat = doc.GetElement(layer.MaterialId) as Material; if (mat.Name.ToLower().Contains("soft insulation")) { double ypos = (wall.Width / 2) - offset; double rotationangle = -1.57079633; double layeroffset = ypos - layer.Width; if (ypos - layer.Width < 0) { rotationangle *= -1; ypos = (wall.Width / 2) * -1 + offset; layeroffset = ypos + layer.Width; } if (wall.Flipped) rotationangle *= -1; Transform tra = Transform.CreateRotationAtPoint(XYZ.BasisZ, rotationangle, c.Curve.GetEndPoint(0)); Curve rotated = c.Curve.CreateTransformed(tra); XYZ LowerStartPoint = rotated.Evaluate(((layeroffset) / rotated.Length), true); XYZ UpperStartPoint = null; if (ypos < 0) { Curve rotatedHelper = c.Curve.CreateTransformed(Transform.CreateRotationAtPoint(XYZ.BasisZ, rotationangle * -1, c.Curve.GetEndPoint(0))); UpperStartPoint = rotatedHelper.Evaluate((ypos * -1 / rotatedHelper.Length), true); } else UpperStartPoint = rotated.Evaluate((ypos / rotated.Length), true); XYZ v = c.Curve.GetEndPoint(0) - LowerStartPoint; XYZ u = c.Curve.GetEndPoint(0) - UpperStartPoint; Curve locationCurvelower = c.Curve.CreateTransformed(Transform.CreateTranslation(v)); Curve locationCurveupper = c.Curve.CreateTransformed(Transform.CreateTranslation(u)); return new Tuple<Curve, Curve>(locationCurveupper, locationCurvelower); } } offset += layer.Width; } return null; }