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

    Export image by layer

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 280 Views 3 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.
    • W Offline
      walzo
      last edited by

      Hi there,

      I'm looking to write a script that will run an export image (or Podium render) command with one layer visible at a time. Any hints? I imagine it needs to be some kind of 'for each layer' loop:

      -Make current layer visible
      -Hide others
      -Render image
      -Move on to the next layer

      I know the export image commands pretty well, but the rest I'm still working out.
      I understand basic coding ideas, though I'm not too well versed in Ruby.

      Any help would be appreciated.

      Thanks,

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Hi walzo, welcome to the forum.

        You can call Podium from your plugin starting with Podium V2. You can also export an image, or create a Scene for each Layer. However you want to do it, the core code will be similar.

        
        # Set all Layers not visible
        for layer in Sketchup.active_model.layers
          layer.visible = false
        end
        
        # Iterate Layers, show next Layer, then
        # either create a Scene, or export and image.
        
        for layer in Sketchup.active_model.layers
          layer.visible = true
          #    1. call Podium;
          # Podium;;render
          # or 2. add a Scene;
          # Sketchup.active_model.pages.add_page(...)
          # or 3. write an image;
          # Sketchup.active_model.active_view.write_image(...)
          layer.visible = false
        end
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • W Offline
          walzo
          last edited by

          Thank you so much Jim! Much appreciated.

          I threw that code in a script file, along with a menu item definition, but for some reason it's not executing anything. The menu item shows up, but it doesn't run anything. Here's the whole .rb file:

          require 'sketchup.rb'
          
          def RenderbyLayer
          
          	# Set all Layers not visible
          
          	for layer in Sketchup.active_model.layers
          		layer.visible = false
          	end
          
          	# Iterate Layers, show next Layer, then
          	# either create a Scene, or export and image.
          
          	for layer in Sketchup.active_model.layers
          		layer.visible = true
          		Podium;;render
          		layer.visible = false
          	end
          
          end
          
          unless file_loaded?("renderbylayer.rb")
          	file_loaded("renderbylayer.rb")
          	add_separator_to_menu("File")
          	UI.menu("File").add_item("Render by Layer using Podium") { RenderbyLayer }
          end
          

          I have Podium v2 loaded, and I've used the Podium::render command successfully before, but not this time round. Any more suggestions? If you have a moment...

          Thanks, O

          1 Reply Last reply Reply Quote 0
          • W Offline
            walzo
            last edited by

            Update: Seems as though the name of the action 'RenderbyLayer' was the problem. I switched it and it worked fine! I wonder why.

            A tip for anyone else trying to script Podium renders:
            The Podium Rendering Manager gives an error 'File not found' if it receives more than one request per second. This seems to result from its naming convention, which uses a time code. I inserted a the command 'sleep(1)' into the script for each layer, pausing it for one second and preventing the error. Maybe there's a better way to do this, but it worked!

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @walzo said:

              Update: Seems as though the name of the action 'RenderbyLayer' was the problem. I switched it and it worked fine! I wonder why.

              Because your script is not wrapped in a module namespace, your method name may have conflicted with some one else's.

              It's OK to run a script like that for testing (gettin' it workin',) but it should be module wrapped. How about module Walzo ??

              @walzo said:

              I inserted the command ' sleep(1)' into the script for each layer, pausing it for one second and preventing the error. Maybe there's a better way to do this, but it worked!

              If it works it's OK... Kernel.sleep() may not have worked well in earlier Ruby versions.

              The Sketchup API also has a timed execution block called UI.start_timer(secs,repeat) { .. your code here ..} SU 8.x allows the secs arg to be fractional, 7.x and earlier rounds the number up to the next integer second. So it should work for this script just fine.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                BTW... the script should make a temp hash with layer names as the keys and visibility as the values. This should store the visible state of layers before rendering starts.

                .. do your thing ...

                .. then restore the visibilty state for all layers at the end.

                I'm not here much anymore.

                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