I want to get a viewsheet's title block 's ElementID.Please give me a sample to do this.
Solved! Go to Solution.
Solved by DavidIntVeld. Go to Solution.
What I once did long time ago was the following:
1 to collect all objects in the view:
private IList<Element> m_alltitleblocks = new List<Element>();
private IList<Element> ElementsOnSheet = new List<Element>();
private FamilySymbol MyTitleBlock;
foreach (Element e in new FilteredElementCollector(doc).OwnedByView(vs.Id)) { ElementsOnSheet.Add(e); }
2. then Get all the titleblocks in the document
public void GetAllTitleBlocks(Document doc) { //get all titleblocks FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(FamilySymbol)); collector.OfCategory(BuiltInCategory.OST_TitleBlocks); m_alltitleblocks = collector.ToElements(); }
3. Then I simply went through the elements on view untill i found the title sheet:
private void GetTitleSheet(IList<Element> ElementsOnSheet) { foreach (Element el in ElementsOnSheet) { foreach (FamilySymbol Fs in m_alltitleblocks) { if (el.GetTypeId().IntegerValue == Fs.Id.IntegerValue) { MyTitleBlock = Fs; } } } }
This gets the ID of the FamilySymbol on the sheet,
if you need the ID of the acctual sheet you can get the el.Id value i suppose
Hope this helps....
This can be simplified to:
var titleBlockId = new FilteredElementCollector(doc, viewSheetId).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElementId();
Since they weren't asking for the family symbol. If family symbol/type is desired then:
var titleBlockTypeId = ElementId.InvalidElementId;
var titleBlockFamInst = new FilteredElementCollector(doc, viewSheetId).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElement() as FamilyInstance;
if (titleBlockFamInst != null)
titleBlockTypeId = titleBlockFamInst.GetTypeId();