Definition classifications. Where is get_classification?

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)

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

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

2 Likes