Here’s a working example:
model = Sketchup.active_model
entities = model.entities
@dictionary_name = "dynamic_attributes"
for entity in entities
attribute = entity.definition.get_attribute(@dictionary_name, 'lenx').to_f
UI.messagebox(attribute.to_cm)
end
Source: Attribute Reporting