I am creating a category in a Revit family that is a linestyle and after i set it, it exists but i just cant find it in the family and yet i f try to recreate it revit creates an error that it already exists. i tried using regeneration and this doesnt work.
ElementId solidLineId = LinePatternElement.GetSolidPatternId();
// The new linestyle will be a subcategory of the Lines category
Categories categories = doc.Settings.Categories;
Category lineCat = categories.get_Item(BuiltInCategory.OST_Lines);
using (Transaction t = new Transaction(doc, "Create LineStyle"))
{
t.Start();
Category newLineStyleCat = categories.NewSubcategory(lineCat, "Black-01-Solid");
newLineStyleCat.SetLineWeight(1, GraphicsStyleType.Projection);
newLineStyleCat.LineColor = new Color(28,28, 28);
newLineStyleCat.SetLinePatternId(solidLineId, GraphicsStyleType.Projection);
t.Commit();
}
This is how new linestyles can be created
Category cat = famDoc.OwnerFamily.FamilyCategory; Category newSubCat = null;
if (!cat.SubCategories.Contains(subCatToAdd))
{
using (Transaction t = new Transaction(famDoc, "Add new or find existing subcategory"))
{
t.Start();
newSubCat = famDoc.Settings.Categories.NewSubcategory(cat, subCatToAdd);
GraphicsStyleType gst = GraphicsStyleType.Projection;
GraphicsStyle gs = newSubCat.GetGraphicsStyle(gst);
newSubCat.SetLineWeight(lineWeight, gst);
t.Commit();
}
}