Message 1 of 3
Some question with adding subcategories to family
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to add a subcategory in the family document and then load it into the project, but I have a problem: if the project document already has a subcategory then I can not add a subcategory in the family document, prompting "the name "Z-AT" is already in use.Paremeter name: name" I am very confused, because manual operation will not be so, have a friend can answer my question thanks
//The list is from the project docement
foreach (var fam in GetFamilyList())
{
Document famDoc = doc.EditFamily(fam);
if (fam.IsEditable)
{
if (famDoc.IsFamilyDocument)
{
using (Transaction tran = new Transaction(famDoc, "AddSubcategory"))
{
tran.Start();
Category cat = fam.FamilyCategory;
try
{
Category ATSub = famDoc.Settings.Categories.NewSubcategory(cat, "Z-AT");
ATSub.LineColor = new Color(0, 0, 255);
Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
SketchPlane sp = SketchPlane.Create(famDoc, plane);
var cur1 = famDoc.FamilyCreate.NewModelCurve(Line.CreateBound(XYZ.Zero, new XYZ(0, 0.01, 0)), sp);
cur1.LineStyle = ATSub.GetGraphicsStyle(GraphicsStyleType.Projection);
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
tran.Commit();
}
famDoc.LoadFamily(doc, new ProjectFamLoadOption());
}
else
{
MessageBox.Show($"{fam.Name}:当前族无法编辑,请结束后在执行");
}
}
}