Help.Outer shell

I myself don’t know of a way to make DC start a code, and moreover, in a way that happens when you explode it so that it is not anymore a DC.
Well, actually there is a methods to attach observers to model/instance to listen if its exploded or not, but much easer to write a code to do explositon like the native one.

So, I will give you a code, which supply you a context menu (similar than the native “Explode”), but this will be “Explode to Solid”, so if the selected component(s) contains nested solid groups/components what can be merged (weld, outer_shell-et), then it will be merged, than the DC will exploded.
Stay tuned…

1 Like

This is an unsigned TEST plugin, does not properly made to call as Extension. But you can install it like an extension. If you don’t know how to do it, better to not to do it.
Dezmo_explode_to_solid.rbz (786 Bytes)

You need to right click on the component (or group) and chose “Explode to Solid”.
You can also select more components/groups or everything, the code will examine if there is a component/group which contains at least two solid components or groups and merge them using outer_shell method, then explode.
The name of the resulting solid group will be the instance name of original component/group (the outer one.) If there is no instance name, then the definition name will be used.
You can undo it, all at once.
Explode to Solid

No Warranty. Use at your own risk!
Tested only very-very limited time, in Windows 11, using SU2022.
Warning! During my test when I undo-ed the “Explode to Solid”, once I get a bug-splat. It may not related, but maybe yes. Be careful! Make a backup, before you use this plugin.
Don’t say I didn’t told you!

The code, for reference:

module Dezmo
module ExplodeToSolid
  extend self
  @@loaded = false unless defined?(@@loaded)
 
  def instance?(ent)
    ent.is_a?(Sketchup::Group) || ent.is_a?(Sketchup::ComponentInstance)
  end
 
  def solids(ents)
    ents.select{|ent| instance?(ent) && ent.manifold?}
  end
 
  def parent_instances(model = Sketchup.active_model)
    sel = model.selection
    sel.select{|ent| instance?(ent)}
  end
 
  def new_name(instance)
    case instance
    when Sketchup::ComponentInstance
      if instance.name == ""
        instance.definition.name
      else
        instance.name
      end
    when Sketchup::Group
      instance.name
    else
      ""
    end
  end
 
  def explode_to_solid
    model = Sketchup.active_model
    done = 0
    model.start_operation("Explode to Solid", true)
    parent_instances(model).each{|instance|
      ents = solids( instance.definition.entities )
      solid_count = ents.size
      next if solid_count < 2
      group_name = new_name(instance)
      instance = instance.make_unique
      ents = solids( instance.definition.entities.to_a )
      e0 = ents[0]
      group = nil
      solid_count.times{|i|
        next if i == 0
        group = e0.outer_shell(ents[i])
        group.name = group_name
        e0 = group
      }
      instance.explode
      done += 1
    }
    model.commit_operation
    UI.messagebox("#{done} solid(s) created.")
  end
 
  unless @@loaded
    @@loaded = true
    cmd1 = UI::Command.new("Explode to Solid"){
      explode_to_solid()
    }
    UI.add_context_menu_handler do |menu|
      if !(parent_instances.empty?)
        menu.add_item( cmd1 )
      end
    end
   
  end
end
end

Finally, I’ll move this topic to the Ruby API category, as this is more about talking about code.

5 Likes

thanks bro, but maybe i was wrong to ask about ruby. because i happened to have a dynamic component, and it works without Extension,maybe i need to do a little more research

test cong 1.skp (51.2 KB)

  1. My name is Dezmo, not bro.
  2. The model you given secondly, test cong 1.skp- is totally different structure than the first one.
  3. I have no idea what you want to show with your video,
  4. The Dynamic Component have no function to explode.
  5. The Dynamic Component have no function to make outer shell.
  6. You must do it manually, using native tools or Extensions.
  7. At the end of the video you are using an Extension. (Unknown for me).
  8. I assume, this extension does the explosion, and deleting the attributes of DC
  9. The model in the video is different than you gave above.

Good luck!

2 Likes

Hello @NewbieVN,

As @renton555 said before, if the DC’s subparts are groups, OpenCutList can handle them as a whole part.

Demo :

But as ABF working with group only I’m not sure it can manage it correctly. Ask to ABF author, no ?

2 Likes

He uses ABF.

1 Like

I am going to try one more time bro. Why do you NEED it to outershell? What are you doing with the component after it is made into an outershell, that CAN NOT be done with the 3 part component?

What you showed in the video is done on the ABF extension side (ruby). It is an observer that responds to certain actions and attributes in a dynamic component.