Some question with adding subcategories to family

Some question with adding subcategories to family

Zhz_1666
Participant Participant
369 Views
2 Replies
Message 1 of 3

Some question with adding subcategories to family

Zhz_1666
Participant
Participant

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}:当前族无法编辑,请结束后在执行");
                    }
                }
            }

 

 

0 Likes
370 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor

You are editing the family from the project so the sub-category always already exists in the project and you can therefore edit the properties of the subcategory directly in the project.

 

You can still add your line and set it's graphics style in family but edit the subcategory in the project. Regarding subcategories the project settings always govern anyway so even if you edited it in the family and loaded it back in the subcategory in the project would remain unchanged.

 

 

0 Likes
Message 3 of 3

Zhz_1666
Participant
Participant
I know that the properties of the subcategory are ultimately edited in the project, but the problem I am encountering now is: when the subcategory exists in the project document, then I cannot add the subcategory to the family, nor can I set the line in it's graphics style.
Thank you for your reply;
0 Likes