I'm defining a titleblock family programmatically and I'm trying to make invisible the edges of the sheet included in the titleblock family templates. I want the edges to stay invisible when the sheet is exported to DWG format.
I've found that I can achieve this by editing the titleblock family manually and assigning the category <Invisible lines>
to the edges of the sheet, but I can't manage to do this programmatically.
I'm creating a Document object from a titleblock family template and retrieving its first ViewSheet object as follows:
Document = Application.uiApplication.Application.NewFamilyDocument(TITLEBLOCK_FAMILY_TEMPLATE);
ViewSheet = new FilteredElementCollector(tbFamilyDoc)
.OfClass(typeof(ViewSheet))
.Cast<ViewSheet>()
.First();
I think I need to set the 'LineStyle' property of the relevant lines, I intend to do it with the following code, but it requires a GraphicsStyle object that I can't manage to obtain.
var lines = new FilteredElementCollector(Document, ViewSheet.Id)
.WhereElementIsNotElementType()
.OfClass(typeof(CurveElement))
.Cast<CurveElement>()
.ToList()
.ForEach(line => line.LineStyle = graphicsStyleInvisibleLines)
I think this object is supposed to be retrieved using the method "GetGraphicsStyle" of the class Category. I've used the addin "RevitLookup" to view the data of the corresponding category, which appears to also be called <Invisible lines>
and to have the Id -2000064.
The collection BuiltInCategory contains the value "OST_InvisibleLines" which has an integer value equal to the ID above, but when I run the following, it returns null.
Category invisibleLinesCat = Document.Settings.Categories.get_Item(BuiltInCategory.OST_InvisibleLines);
RevitLookup also showed me that the parent category has the name "Internal Object Styles" and has the ID -2000059. I found again a BuiltInCategory value with a matching name and integer value: "OST_IOS". I've tried fetching this parent category to then navigate to the desired subcategory with the line below, but it also returns null.
Category internalCat = Document.Settings.Categories.get_Item(BuiltInCategory.OST_IOS);
Does somebody know a way to obtain a reference to this category or to its GraphicsStyle object?
Thank you in advance for your time.
You should be able to query those line styles the same you query for the line. The following worked for me:
var graphicsStyles = new FilteredElementCollector(Document)
.WhereElementIsNotElementType()
.OfClass(typeof(GraphicsStyle))
.Cast<GraphicsStyle>()
.ToList();
var lineStyle = graphicsStyles.FirstOrDefault(x => x.Name == "<Invisible lines>");
if (lineStyle != null)
{
using (var t = new Transaction(Document, "update line type"))
{
t.Start();
lines.ForEach(line => line.LineStyle = lineStyle);
t.Commit();
}
}