/// <summary> /// /// </summary> /// <param name="family"></param> /// <param name="famInst"></param> /// <param name="famSymbolString"></param> private void UpdateFamilySymbol(Family family, FamilyInstance famInst, string familySymbolString) { FamilySymbolSet famSymSet = family.Symbols; FamilySymbolSetIterator famSymSetIter = famSymSet.ForwardIterator(); while (famSymSetIter.MoveNext()) { FamilySymbol famSymbol = famSymSetIter.Current as FamilySymbol; if (famSymbol.Name == familySymbolString) { famInst.Symbol = famSymbol; break; } } }
GetTitleBlocks(Document doc) { m_allTitleBlocks = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast <FamilySymbol>() as FamilySymbolSet; if (0 == m_allTitleBlocks.Size) { throw new Exception("There is no title block to generate sheet."); } foreach (FamilySymbol f in m_allTitleBlocks) { m_titleBlockNames.Add(f.Name); if (null == m_titleBlock) { m_titleBlock = f; } } }
/// <summary> /// Retrieve all available title blocks in the currently active document. /// </summary> /// <param name="doc">the currently active document</param> private void GetTitleBlocks(Document doc) { m_allTitleBlocks = doc.TitleBlocks; if (0 == m_allTitleBlocks.Size) { throw new InvalidOperationException("There is no title block to generate sheet."); } foreach (FamilySymbol f in m_allTitleBlocks) { AllTitleBlocksNames.Add(f.Name); if (null == m_titleBlock) { m_titleBlock = f; } } }
public Result Execute( ExternalCommandData commandData, ref String message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; FilteredElementCollector a; Parameter p; int n; #region Using the obsolete TitleBlocks property #if BEFORE_REVIT_2015 // The TitleBlocks property was declared deprecated // in the Revit 2014 API, and removed in Revit 2015. // Using the obsolete deprecated TitleBlocks property FamilySymbolSet titleBlocks = doc.TitleBlocks; n = titleBlocks.Size; Debug.Print( "{0} title block element type{1} listed " + "in doc.TitleBlocks collection{2}", n, (1 == n ? "" : "s"), (0 == n ? "." : ":")); string s; foreach (FamilySymbol tb in titleBlocks) { // these are the family symbols, // i.e. the title block element types, // i.e. not instances, i.e. not sheets, // and they obviously do not have any sheet // number, width or height, so 's' ends up empty: s = GetParameterValueString(tb, BuiltInParameter.SHEET_NUMBER) + GetParameterValueString(tb, BuiltInParameter.SHEET_WIDTH) + GetParameterValueString(tb, BuiltInParameter.SHEET_HEIGHT); Debug.Print( "Title block element type {0} {1}" + s, tb.Name, tb.Id.IntegerValue); } #endif // BEFORE_REVIT_2015 #endregion // Using the obsolete TitleBlocks property // Using this filter returns the same elements // as the doc.TitleBlocks collection: a = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_TitleBlocks) .OfClass(typeof(FamilySymbol)); n = a.ToElementIds().Count; Debug.Print("{0} title block element type{1} " + "retrieved by filtered element collector{2}", n, (1 == n ? "" : "s"), (0 == n ? "." : ":")); foreach (FamilySymbol symbol in a) { Debug.Print( "Title block element type {0} {1}", symbol.Name, symbol.Id.IntegerValue); } // Retrieve the title block instances: a = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_TitleBlocks) .OfClass(typeof(FamilyInstance)); Debug.Print("Title block instances:"); foreach (FamilyInstance e in a) { p = e.get_Parameter( BuiltInParameter.SHEET_NUMBER); Debug.Assert(null != p, "expected valid sheet number"); string sheet_number = p.AsString(); p = e.get_Parameter( BuiltInParameter.SHEET_WIDTH); Debug.Assert(null != p, "expected valid sheet width"); string swidth = p.AsValueString(); double width = p.AsDouble(); p = e.get_Parameter( BuiltInParameter.SHEET_HEIGHT); Debug.Assert(null != p, "expected valid sheet height"); string sheight = p.AsValueString(); double height = p.AsDouble(); ElementId typeId = e.GetTypeId(); Element type = doc.GetElement(typeId); Debug.Print( "Sheet number {0} size is {1} x {2} " + "({3} x {4}), id {5}, type {6} {7}", sheet_number, swidth, sheight, Util.RealString(width), Util.RealString(height), e.Id.IntegerValue, type.Name, typeId.IntegerValue); } // Retrieve the view sheet instances: a = new FilteredElementCollector(doc) .OfClass(typeof(ViewSheet)); Debug.Print("View sheet instances:"); foreach (ViewSheet vs in a) { string number = vs.SheetNumber; Debug.Print( "View sheet name {0} number {1} id {2}", vs.Name, vs.SheetNumber, vs.Id.IntegerValue); } return(Result.Succeeded); }
/// <summary> /// Retrieve all available title blocks in the currently active document. /// </summary> /// <param name="doc">the currently active document</param> private void GetTitleBlocks(Document doc) { m_allTitleBlocks = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_TitleBlocks).Cast<FamilySymbol>() as FamilySymbolSet; if (0 == m_allTitleBlocks.Size) { throw new Exception("There is no title block to generate sheet."); } foreach (FamilySymbol f in m_allTitleBlocks) { m_titleBlockNames.Add(f.Name); if (null == m_titleBlock) { m_titleBlock = f; } } }