How to convert layers to components in order to import them into twinmotion

I´m trying to convert layers(groups assigned to a layer) into components in order to import them in twinmotion(as it only imports components, not layers or scenes)

Right click on that ‘layer’ (which is in fact a group, not a layer) and choose Make Component.

Twinmotion imports both groups and components without problems.

Thanks for the quick answer but there i more than one group assigned to the layer and i´m trying to do it less manual as i have a lot of layers& groups

I´m trying to find out some ruby code that makes: “Convert groups assigned to each layer to components with the same layer names”
or something that converts scenes(skp) into phases™

Group names are not imported, just component names

Group names imported
SketchUp

Twinmotion

But if you still need to transform groups to components, if you search Extension Warehouse you’ll find Group to Components extension, and also other related extensions.

This one have “all kind of selection” possibilities as well as a Group to Components converter…
https://extensions.sketchup.com/extension/c9266b2c-0b55-4d21-a0a4-72e23b8a0fb4/selection-toys

Thanks fot the plugin, i´m just trying it but it doesnt name the components as the groups names

Thanks for the reply, i´ll check this plugin but i´m trying to find some “bulk” way to do as i have a lot of groups, subgroups and layers. Doing it manually is what i´ve been doing and its very time consuming(i´m sure there is a way to automate it)

Can you please explain this more, perhaps with example…(Are you using SU2020? or the latest 2022?)

Sure, in my model i have group A (with sub-group B inside) assigned to layer 1 and showed in scene 01. I now do the following: selecting the group, creating a new component and copy/pasting layer name into component name

If I understood right your groups are already associated to the correct Tag/Layer, each of it individually…(Otherwise make no sense to give a same definition neme for new component.)
You still did not told me what version of Sketchup you are using, but it should work on most of it more or less okay…

So, here are a quick an dirty snippets, does not tested extensively… I guess it will be okay, but:
NO WARRANTIES! Use your own risk! Backup your model before you try it!

  1. Select your groups and/or component instances containing the groups you want to convert, rename (Or select all - CTRL+A)
  2. Copy and paste the snippets below to Ruby console and Hit Return (Enter)

It will Convert all groups to component and set definition name to its Tag name recursively
You will see in a Ruby Console how many groups are converted, renamed
You can Undo it at once.
If you hiding group object per scenes, then it will not be kept. If you are using Tag/Layer to do visibilities then, I guess, you should be okay…

module Dezmo
module GroupRenamerTagName
  extend self
  
  def rename_group(ents)
    ents.each{ |e|
      if e.is_a?( Sketchup::Group )
        @num += 1
        e.make_unique
        e.name = e.layer.name
        e = e.to_component
        e.definition.name = e.layer.name
        rename_group( e.definition.entities )
      elsif e.is_a?( Sketchup::ComponentInstance )
        if (!@defs.include?(e.definition))
          rename_group( e.definition.entities )
          @defs<<e.definition
        end
      else
        next
      end
    }
  end

  def grouprename
    model = Sketchup.active_model
    sel = model.selection
    return UI.messagebox("Please select at least one group or componet first!") if sel.empty?
    @defs = []
    @num = 0
    model.start_operation("Convert groups to component and name definition name to its Tag name", true)
    rename_group(sel.to_a)
    model.commit_operation
    "#{@num} Groups converted, renamed"
  end
  
end
end
Dezmo::GroupRenamerTagName.grouprename

Thanks a lot for your time! It´s only working for small files, when it comes to a lot of subgroups and layers it gets stucked, any chance you know why?

Because it goes through every single drawing element one by one (not optimized) and check if it is a group or component instance, and going deep down until everything is cheeked to change or not … so it takes time. Just let it finish until you see the result in a Ruby console.

I´ll do! Thank you very much! You´re the best :clap: :clap: :clap:

1 Like

Rev A Same rules… :innocent:
NO WARRANTIES! Use your own risk! Backup your model before you try it!

You can test this version if it goes faster and/or better?
It does not need a selection will process all groups in model…

module Dezmo
module GroupRenamerTagNameA
  def self.convert_rename
    model = Sketchup.active_model
    definitions = model.definitions
    gdefs = definitions.select{|g| g.group?}
    @num = 0
    model.start_operation("Convert groups to component and name definition name to its Tag name (rev A)", true)
    gdefs.each{|d|
      d.instances.each{|i|
        i.make_unique
        i = i.to_component
        i.definition.name = i.layer.name
        @num += 1
      }
    }
    model.commit_operation
    "#{@num} Groups converted, renamed"
  end
end
end
Dezmo::GroupRenamerTagNameA.convert_rename

I´ll try it! I´m selecting a few groups layered instead of the whole model.I think it takes a long time because i have groups with a lot of subgroups inside and some of them contains components. But it works very well mate!

1 Like

I would suggest using the udatasmith export and preserving heirachy rather than just dropping the SKP in

I´m using datasmith but i doesnt import layer names, just component names in the outliner