sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Create Layers From Component Names

    Scheduled Pinned Locked Moved Plugins
    4 Posts 2 Posters 117 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rossthompson
      last edited by

      Hi,

      I am working on a model that has a very large number of imported components.

      What I would like to do is run a script that creates a layer for each component. Ideally the layer name would be identical to the component name, and each component would be placed on the corresponding layer.

      Has anybody come across something similar to this?

      I hope this is clear.

      Ross

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Copy/paste this one-liner into the Ruby Console + <enter>, it's one step undoable.

        m=Sketchup.active_model;m.start_operation('c');m.definitions.each{|d|next if d.group? || d.image?;n=d.name;l=m.layers.add(n);d.instances.each{|i|i.layer=l}};m.commit_operation
        

        All instances of every component-definition are placed on a layer named after the definition-name...

        TIG

        1 Reply Last reply Reply Quote 0
        • R Offline
          rossthompson
          last edited by

          TIG - thanks so much for that.

          Would it be possible to revise the code to ignore any nested components? I guess this could be done with a simple change to the definition?

          Also could the layer colour be fixed to black?

          Thanks so much for your help

          Ross

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @rossthompson said:

            TIG - thanks so much for that.

            Would it be possible to revise the code to ignore any nested components? I guess this could be done with a simple change to the definition?

            Also could the layer colour be fixed to black?

            Thanks so much for your help

            Ross
            When you say 'nested' I assume you mean you want to re-layer only instances within the 'model.entities'... This new version does that - but actually it re-layers all instances in the 'active_entities' context, so if you run it whilst editing a group etc only instances inside that group are affected, to affect only instances in the model.entities ensure that you are in the model.entities context before running it - this allows you the fullest flexibility, with the opportunity to edit certain nested instances separately, if so desired...

            m=Sketchup.active_model;m.start_operation('c');m.active_entities.each{|e|next unless e.is_a?(Sketchup;;ComponentInstance);n=e.definition.name;l=m.layers.add(n);e.layer=l};m.commit_operation
            

            Layer colors cannot currently be accessed/changed by the API, you'll have to do that change to 'black' manually. There are some convoluted workarounds [e.g. make layer.color= developers' method hack], but it'll be just as fast to do it manually in the Layer Browser...

            TIG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement