Definition classifications. Where is get_classification?

So we have #add_classification(schema_name, schema_type) ⇒ Boolean and #remove_classification(schema_name, schema_type) ⇒ Boolean, but, where is get_classification(schema_name) ?

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?

perhaps #get_classification_value

I misunderstood question (disregard) ...

… 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.

#get_classification_value and #set_classification_value are for getting and setting a value, not for getting a classification.

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")

This lets you list schemas, keys etc… in the model.
The get_/set_/remove methods relate to definitions… etc.
Your working get_ method finds the Schema associated with the definition by name…

The example in the docs let me set a type for a given scheme:

For example: say that a definition is a door:

definition = Sketchup.active_model.definitions.first
success = definition.add_classification("IFC 2x3", "IfcDoor")

it also lets me remove the associated type:

definition = Sketchup.active_model.definitions.first
success = definition.remove_classification("IFC 2x3", "IfcDoor")

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.

it’s all in the name…

this is out of one of mine…

            next if d.image?
            next if
            i.explode  if =~ /IfcProject / or =~ /IfcSite / or =~ /IfcBuilding /

the ’ Type ’ is the first part of the instance name on import…


Hi john,

Yes, or you could look at the assigned attribute value:

definition.get_attribute(“AppliedSchemaTypes”, “IFC 2x3”)

But again… isn’t this something that is missing in the api? One can assign and delete, but not retrieve?

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…


1 Like

Oh yes, I know what you mean now. (needed a cup of coffee first) :coffee:
Yes I remember this being discussed in the past. (see links below)


… 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")

  using AppliedTypeForIFCDefinitions
  # Code that makes calls like the following on instances ...
  if obj.defintion.applied_IFC_type == "IFCBuildingStory"
    # do something

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.)

@kengey, I suggest opening a documentation issue at the GitHub API tracker to add your snippet above, as a coding tip, to the Sketchup::ComponentDefinition#add_classification method’s YARD docstring.


Will do


Have you filed this FR yet? (I don’t find it.)

1 Like

Shoot, I believe not. Got busy on some projects last 2 months.

1 Like

For reference, the logged issue is found here:

1 Like