this is my command by it’s giving error
Sketchup.active_model.selection.entities.materials.map{|x| x.name}
but this command is giving materials of all the models
Sketchup.active_model.materials.map{|x| x.name}
this is my command by it’s giving error
Sketchup.active_model.selection.entities.materials.map{|x| x.name}
but this command is giving materials of all the models
Sketchup.active_model.materials.map{|x| x.name}
What error does it give you? The error usually tells you what is wrong, or at least a hint.
NoMethodError: undefined method `entities' for #<Sketchup::Selection:0x00000014a787f8>
That means the return value of the method selection does not have a method entities.
Sketchup::Selectionentities.to_a and see the result.methods:Sketchup.active_model.selection.methodsmaterials is a method either of the whole model or of an individual drawing element. That means you need to iterate over entities and call material on each individual entity.map on the selection and material on each drawing element. You notice some drawing elements have no material (nil), so you apply name only when the material is not nil.compact you can remove nil from an array.map(&:method_name) is a shortcut for map{|x| x.method_name() } for methods without arguments.Sketchup.active_model.selection.map(&:material).compact.map(&:name)