Monday, December 4, 2023
Home3D ModelingChange materials - Ruby API

Change materials – Ruby API


Howdy.
I’ve this piece of code.


      mannequin.start_operation("Materials change", true)
      component_definition.set_attribute("dynamic_attributes", "materials","crimson")
      component_definition.materials = "crimson"
      mannequin.commit_operation("Materials change")
      mannequin.active_view.invalidate
      mannequin.active_view.refresh

After operating the code, I don’t see any modifications to the fabric.
But when I press Ctrl+S, the modifications turn out to be seen.

You need to have extra code than the one you write.
mannequin and component_definition are usually not declared as variables.

def selector(my_guid)
  mannequin = Sketchup.active_model
  view = mannequin.active_view
  component_definition = mannequin.definitions.discover   e.guid == my_guid 

  if component_definition
      mannequin.start_operation("Materials change", true)
      component_definition.set_attribute("dynamic_attributes", "materials","crimson")
      component_definition.materials = "crimson"
      mannequin.commit_operation

      mannequin.active_view.invalidate
      mannequin.active_view.refresh
  finish
finish

What’s your essential objective? Do you need to change the colour of 1 chosen element?

Can this code enable you to?

Sketchup.active_model.choice.every do |e| 
  e.materials = "crimson" if e.respond_to?(:materials)
  e.back_material = "crimson" if e.respond_to?(:back_material)
finish

Thanks, however your code didn’t assist. (
I feel my downside is that the View is just not refreshing.
Though I’m making an attempt to do that manually in my code.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments