For ages I have been parsing the definition’s attribute dictionaries to get classifications, but, there must be an API method now, or not? What am I missing?
… and it was implemented at the same time that the other methods were.
In the Ruby API docs, above the class list in the left nav column, there are 3 links …
Classes | Methods | Files
If you click the Methods link you can then filter the method index list.
So typing "get_" in the Search: box (no quotes, BTW) you’ll see the method you sought is 5th in the list.
I need a way to get IfcBuildingStorey as that is the classification type assigned to the definition. I would’ve thought there was an API method, since we can add and delete classification types.
For now I stick with definition.get_attribute("AppliedSchemaTypes", "IFC 2x3")
But as far as I can see, there is no appropriate method to get the assigned type for a given scheme.
I would expect there to be a get_classification(scheme_name). Why is there a method that lets you remove a type if there is no method to know what type is assigned?
Specific types have specific attributes that are part of the classification, that is where get_classification_value and get_classification_value are for.
defs.each{|d|
next if d.image?
next if d.group?
d.instances.each{|i|
i.explode if i.name =~ /IfcProject / or i.name =~ /IfcSite / or i.name =~ /IfcBuilding /
}}
the ’ Type ’ is the first part of the instance name on import…
undeniably, there is lots missing from the API in general…
I haven’t ever looked deeply into the Classifications class as the name was all I needed for grouping to Layers, ‘fixing’ origins and reducing component counts…
Oh yes, I know what you mean now. (needed a cup of coffee first)
Yes I remember this being discussed in the past. (see links below)
REF:
… has several code snippets for walking the classification attribute dictionary “trees”.
You could use a refinement module if you like …
module Author
module AppliedTypeForIFCDefinitions
refine Sketchup::ComponentDefinition do
def applied_IFC_type
self.get_attribute("AppliedSchemaTypes", "IFC 2x3")
end
end
end
using AppliedTypeForIFCDefinitions
# Code that makes calls like the following on instances ...
if obj.defintion.applied_IFC_type == "IFCBuildingStory"
# do something
end
end
The API authors are “minimalists”. If there is a simple alternative or workaround they don’t create a dedicated method(s). Ie, more work, more maintenance, etc. (Arguing for “robustness” doesn’t work, as I’ve tried it. They’ll just quote various “golden rules of APIs” and cite bibliographic references with subjective opinions that support minimalism.)