问题描述
我正在Revit家族中创建一个线型类别,设置它之后,它存在,但我只是在该家族中找不到它,但是我尝试重新创建它时,revit产生了一个已经存在的错误。我尝试使用再生,但这不起作用。
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();
}
解决方法
这是可以创建新线型的方式
类别cat = famDoc.OwnerFamily.FamilyCategory; 类别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();
}
}