Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get a Viewsheet's title block

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
beckhans
6249 Views, 3 Replies

How to get a Viewsheet's title block

 I want to get a viewsheet's title block 's ElementID.Please give me a sample to do this.

 

3 REPLIES 3
Message 2 of 4
DavidIntVeld
in reply to: beckhans

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....

 

 

 

Message 3 of 4
FlorisvdG
in reply to: DavidIntVeld

.

Message 4 of 4
michael-coffey
in reply to: beckhans

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();

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community