Hello,
I'm try to set a classification for a list of objects with .net. I'va found some discussions regarding changing and iterating classification trees, but none setting the classification for entites, similar to selecting a classification in ui.
Has anyone done this yet? Maybe I haven't found the discussion 😉
Thanks,
Tim
This is how i set the "MvPart Type" classification for a MvPart in Autocad MEP. It is a highly specialized method that only sets the "MvPart Type" for multi-view parts. You could modify it to pass the style of the object you are setting the classification on as well as add the classification value as a parameter instead of hard coding it. I am also using a global transaction which could be localized if you prefer.
private static void SetMultiViewPartStyleClassification(MultiViewPartStyle multiViewPartStyle, string multiViewPartClassification) { var dictionaryClassificationDefinition = new DictionaryClassificationDefinition(_database); ObjectId owningSystemId = dictionaryClassificationDefinition.GetAt("MvPart Type"); var classificationDefinition = _transaction.GetObject(owningSystemId, OpenMode.ForRead) as ClassificationDefinition; if (classificationDefinition != null) { ClassificationTree classificationTree = classificationDefinition.ClassificationTree; if (classificationTree != null) { ImpTreeCollection treeCollection = classificationTree.Children; if (treeCollection != null) { int maximum = treeCollection.Count; for (int i = 0; i < maximum; i++) { ObjectId classificationId = classificationTree.GetIdAt(i); var classification = _transaction.GetObject(classificationId, OpenMode.ForRead) as Classification; if (classification != null) { if (classification.Name == multiViewPartClassification) { ClassificationCollection classificationIds = multiViewPartStyle.Classifications; classificationIds.Add(classificationId); break; } } } } } } }
Hope this helps.