bool Add ( DB.Document doc, DB.Document familyDoc, Rhino.Geometry.Brep brep, DeleteElementEnumerator <DB.GenericForm> forms ) { forms.MoveNext(); if (brep.ToSolid() is DB.Solid solid) { if (forms.Current is DB.FreeFormElement freeForm) { freeForm.UpdateSolidGeometry(solid); forms.DeleteCurrent = false; } else { freeForm = DB.FreeFormElement.Create(familyDoc, solid); } brep.TryGetUserString(DB.BuiltInParameter.ELEMENT_IS_CUTTING.ToString(), out bool cutting, false); freeForm.get_Parameter(DB.BuiltInParameter.ELEMENT_IS_CUTTING).Set(cutting ? 1 : 0); if (!cutting) { DB.Category familySubCategory = null; if ( brep.TryGetUserString(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY.ToString(), out DB.ElementId subCategoryId) && DB.Category.GetCategory(doc, subCategoryId) is DB.Category subCategory ) { if (subCategory.Parent.Id == familyDoc.OwnerFamily.FamilyCategory.Id) { familySubCategory = MapCategory(doc, familyDoc, subCategoryId, true); } else { if (subCategory.Parent is null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Parent.Name} : {subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } } } if (familySubCategory is null) { freeForm.get_Parameter(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY).Set(DB.ElementId.InvalidElementId); } else { freeForm.Subcategory = familySubCategory; } brep.TryGetUserString(DB.BuiltInParameter.IS_VISIBLE_PARAM.ToString(), out var visible, true); freeForm.get_Parameter(DB.BuiltInParameter.IS_VISIBLE_PARAM).Set(visible ? 1 : 0); brep.TryGetUserString(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM.ToString(), out var visibility, 57406); freeForm.get_Parameter(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Set(visibility); brep.TryGetUserString(DB.BuiltInParameter.MATERIAL_ID_PARAM.ToString(), out DB.ElementId materialId); var familyMaterialId = MapMaterial(doc, familyDoc, materialId, true); freeForm.get_Parameter(DB.BuiltInParameter.MATERIAL_ID_PARAM).Set(familyMaterialId); } return(cutting); } return(false); }
void Add ( DB.Document doc, DB.Document familyDoc, Rhino.Geometry.Curve curve, List <KeyValuePair <double[], DB.SketchPlane> > planesSet, DeleteElementEnumerator <DB.CurveElement> curves ) { if (curve.TryGetPlane(out var plane)) { var abcd = plane.GetPlaneEquation(); int index = planesSet.BinarySearch(new KeyValuePair <double[], DB.SketchPlane>(abcd, null), PlaneComparer.Instance); if (index < 0) { var entry = new KeyValuePair <double[], DB.SketchPlane>(abcd, DB.SketchPlane.Create(familyDoc, plane.ToPlane())); index = ~index; planesSet.Insert(index, entry); } var sketchPlane = planesSet[index].Value; DB.GraphicsStyle familyGraphicsStyle = null; { DB.Category familySubCategory = null; if ( curve.TryGetUserString(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY.ToString(), out DB.ElementId subCategoryId) && DB.Category.GetCategory(doc, subCategoryId) is DB.Category subCategory ) { if (subCategoryId == familyDoc.OwnerFamily.FamilyCategory.Id) { familySubCategory = MapCategory(doc, familyDoc, subCategoryId, true); } else if (subCategory?.Parent?.Id == familyDoc.OwnerFamily.FamilyCategory.Id) { familySubCategory = MapCategory(doc, familyDoc, subCategoryId, true); } else { if (subCategory.Parent is null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Parent.Name} : {subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } } } curve.TryGetUserString(DB.BuiltInParameter.FAMILY_CURVE_GSTYLE_PLUS_INVISIBLE.ToString(), out var graphicsStyleType, DB.GraphicsStyleType.Projection); familyGraphicsStyle = familySubCategory?.GetGraphicsStyle(graphicsStyleType); } curve.TryGetUserString(DB.BuiltInParameter.MODEL_OR_SYMBOLIC.ToString(), out bool symbolic, false); curve.TryGetUserString(DB.BuiltInParameter.IS_VISIBLE_PARAM.ToString(), out var visible, true); curve.TryGetUserString(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM.ToString(), out var visibility, 57406); foreach (var c in curve.ToCurveMany()) { curves.MoveNext(); if (symbolic) { if (curves.Current is DB.SymbolicCurve symbolicCurve && symbolicCurve.GeometryCurve.IsSameKindAs(c)) { symbolicCurve.SetSketchPlaneAndCurve(sketchPlane, c); curves.DeleteCurrent = false; } else { symbolicCurve = familyDoc.FamilyCreate.NewSymbolicCurve(c, sketchPlane); } symbolicCurve.get_Parameter(DB.BuiltInParameter.IS_VISIBLE_PARAM).Set(visible ? 1 : 0); symbolicCurve.get_Parameter(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Set(visibility); if (familyGraphicsStyle is object) { symbolicCurve.Subcategory = familyGraphicsStyle; } } else { if (curves.Current is DB.ModelCurve modelCurve && modelCurve.GeometryCurve.IsSameKindAs(c)) { modelCurve.SetSketchPlaneAndCurve(sketchPlane, c); curves.DeleteCurrent = false; }
bool Add ( DB.Document doc, DB.Document familyDoc, Rhino.Geometry.Brep brep, DeleteElementEnumerator <DB.GenericForm> forms ) { bool isCutting = brep.SolidOrientation == Rhino.Geometry.BrepSolidOrientation.Inward; if (isCutting) { brep.Flip(); } forms.MoveNext(); if (brep.ToHost() is DB.Solid solid) { if (forms.Current is DB.FreeFormElement freeForm) { freeForm.UpdateSolidGeometry(solid); forms.DeleteCurrent = false; } else { freeForm = DB.FreeFormElement.Create(familyDoc, solid); } if (isCutting) { freeForm.get_Parameter(DB.BuiltInParameter.ELEMENT_IS_CUTTING).Set(1); return(true); } else { DB.Category familySubCategory = null; if ( brep.GetUserElementId(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY.ToString(), out var subCategoryId) && DB.Category.GetCategory(doc, subCategoryId) is DB.Category subCategory ) { if (subCategory.Parent.Id == familyDoc.OwnerFamily.FamilyCategory.Id) { familySubCategory = MapCategory(doc, familyDoc, subCategoryId, true); } else { if (subCategory.Parent is null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'{subCategory.Parent.Name} : {subCategory.Name}' is not subcategory of '{familyDoc.OwnerFamily.FamilyCategory.Name}'"); } } } if (familySubCategory is object) { freeForm.Subcategory = familySubCategory; } if (brep.GetUserBoolean(DB.BuiltInParameter.IS_VISIBLE_PARAM.ToString(), out var visible)) { freeForm.get_Parameter(DB.BuiltInParameter.IS_VISIBLE_PARAM).Set(visible ? 1 : 0); } if (brep.GetUserInteger(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM.ToString(), out var visibility)) { freeForm.get_Parameter(DB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Set(visibility); } if ( brep.GetUserElementId(DB.BuiltInParameter.MATERIAL_ID_PARAM.ToString(), out var materialId) && MapMaterial(doc, familyDoc, materialId, true) is var familyMaterialId ) { freeForm.get_Parameter(DB.BuiltInParameter.MATERIAL_ID_PARAM).Set(familyMaterialId); } } } return(false); }