I don’t know your knowledge of C#, so I go back to the basics:
C# want you to define every variable.
For example, if I need a string a double or integer the variable is:
string helloWorld = "Hello World!";
double number = 1.0;
int inTeger = 1;
When you use the Revit Api you need to do the same.
You want TitleBlocks, if you look at the revit api docs, you can see there is no specific class for titleblocks.
In this case you need to use the Element class
Let go to your public, you try to get a specific titleblock (Element) by using the familyname and the type.
Lets create a public … in this case we want a public Element, because you need an element.
To get the titleblocks we need to use the document, I will use this for my filteredelement collector.
public Element GetTitleblockByName(Document doc, string familyName, string typeName)
{
}
I define every input that I need in my public, doc = Document, familyName is a string, typeName is a string as well.
To retieve the elements we will use the filteredelement collector.
When we look at the revit api docs we see that the collector give a IList back when we use the .ToElements() Method:
FilteredElementCollector Class (revitapidocs.com)
When I return my variable tBlocks the code has an error:
That is because the public is defined as an Element, not as a IList
Now we have all titleblocks, but you want a specific tBlock. So let me change the code a little bit.
When you snoop the titleblock and check the BuiltinParameter Family Name, you see the internalDefinition = SYMBOL_FAMILY_NAME_PARAM. and this will give the value back when you use the .AsString();
So I use the collector and use the FirstOrDefault() function, inside this function a use the Lambda function. x in this case is a variable of the lambda, when x => x.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString() == familyName
than I get this element, but in your case you want 2 names, first the familyname and that the type name.
So I change the code in
(x => x.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString() == familyName
&& x.Name == typeName);
I use the && for this.
And now you have the element:
public Element GetTitleblockByName(Document doc, string familyName, string typeName)
{
//FilteredElement Collector To Elements
IList<Element> tBlocks = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TitleBlocks).WhereElementIsElementType().ToElements();
//Now we want a specific element what has the familyName and the typeName, we use the lambda for that (=>)
Element tBlock = tBlocks.FirstOrDefault
(x => x.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString() == familyName
&& x.Name == typeName);
return tBlock;
}
Right now you can use this public inside your code:
I hope this makes sense