sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Start_operation/commit_operation with sandboxTools

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 508 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.
    • S Offline
      sonjachr
      last edited by

      I Need to use the sandbox Tools to generate a Terrain from Contour lines, which have to be selected Prior to the Operation. It is a requirement of the Sketchucation warehouse , that the user Action has to be undone in one go. So, for the example code below, it should be just the undo Terrain1.
      However when I run the below code (in the Ruby Code Editor), I get two undos: **Sandbox Utilites and Terrain1

      What is wrong with below Code?
      I have attached a simple skp File, with a contour layer**
      [pre:1rxq2znq]` model = Sketchup.active_model # Open model
      layers = model.layers
      model.start_operation("Terrain1",false,false,false)

      new_layer = layers.add "Terrain"
      
      activelayer = model.active_layer = layers["Terrain"]
      

      model.commit_operation
      model.start_operation("Terrain2",false,false,true)
      begin
      if (Sketchup.version.to_f <14.0)
      tr=model.select_tool FromContoursTool.new
      else
      tr=model.select_tool Sketchup::SandboxTools::FromContoursTool.new
      end
      model.commit_operation
      rescue

      	model.abort_operation
      	return
      	
      end 
      
      begin
      

      model.start_operation("Terrain3",false,false,true)
      layers.each do |la|

      	  if la.name == "Contour"
      	  	 la.visible=false
      	  end
      	end	 
      

      model.commit_operation
      rescue
      model.abort_operation
      end`[/pre:1rxq2znq]

      Thanks in advance for your help


      simple skp with contour layer

      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        You get two operations because Sandbox Tools create it's own operation - will will not become transparent to yours. It was never made to be called by third party extensions.

        First of all, such things are very fragile. Any change in Sandbox Tools might break your extension - as you already noticed since you need to branch off for various SketchUp versions.

        Secondly, Sandbox Tools might not be enabled by your users. Most will probably have it enabled, but some disable or even remove it. Making this even more fragile.

        Actually, by default it's disabled for Make users. So out of the box for Make users this will not fly.

        Might we step back a little bit here and query to what you are trying to make here?

        1 Reply Last reply Reply Quote 0
        • S Offline
          sonjachr
          last edited by

          Thanks for the quick reply.
          the code shown in my question ist just an extract. In the original code I have an errorhandling, telling the user to switch on the Sandbox Tools.

          I am working on a plugin where the user may use Google Earth to import a Google Earth Terrain, extracting contour lines on a certain layer, selecting all the contour lines and building a Terrain on a certain layer using the Sandbox Tools, grouping it and setting some attributes to the group, and finally making the contour lines invisible. The layers and the attributes are needed for further processing.
          Besides the Import of the Google Earth Terrain, everything is done in a module without user interaction and therefore should be undone in one go.
          I don't have any idea how to get this done without using the Sandbox Tools.

          Can you help me please.

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by

            Does it it has to be a Sandbox Tool mesh?

            For instance, would it be an option to use a different way to create the terrain mesh? If so, maybe you could work out an arrangement with Fredo using some of his terrain code? http://sketchucation.com/forums/viewtopic.php?f=323%26amp;t=52039#p470701

            To use Sandbox Tools I don't have an immediate answer right now. I'd have to dig into how it works. Though I would feel much better about this if we could find a solution for you where you didn't have to rely on such a fragile connection to Sandbox Tools.

            1 Reply Last reply Reply Quote 0
            • S Offline
              sonjachr
              last edited by

              Thanks again for your reply.
              I looked into the source code of Fredos Lib and TopoShaper Plugin. Even if Fredo would allow me to use some of his source code it would be much too complicated for me to pick the right code to generate the Terrain. It seems to be a very complicated and powerful tool.
              Do you know, whether the source code of the sandbox FromContoursTool is available?

              I feel a little helpless, as I am not a ruby expert. Any further ideas? Otherwise I have to ask the user to create the Terrain manually using the Sandbox Tools.

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @sonjachr said:

                Do you know, whether the source code of the sandbox FromContoursTool is available?

                It isn't I'm afraid.

                @sonjachr said:

                Even if Fredo would allow me to use some of his source code it would be much too complicated for me to pick the right code to generate the Terrain.

                I'd recommend reaching out and ask him. If he's on board with this he might be able to provide you with the exact code you need to include and then describe how to call it.
                Then you'd have something that work reliably and isn't dependent on third party extension that might be disabled or suddenly change. (We have been talking about cleaning up our extensions so it's not unlikely Sandbox Tools would suddenly stop working for your purpose.)

                It would have been nice if we had an API for Sandbox Tools (or even seeing it open source IMO), but as it is right now it's not - so I don't have a good immediate solution for that.

                I don't even know if I'm allowed to find and disclose a way to use the internals of Sandbox Tools.

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  I see that TIG also has a script to generate a mesh from points. You might try to reach out to him too.

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    sonjachr
                    last edited by

                    Thanks Tom for your advice to contact Fredo.
                    I have contacted him and he told me that he could provide an API, which could solve my problem, hopefully.

                    1 Reply Last reply Reply Quote 0
                    • tt_suT Offline
                      tt_su
                      last edited by

                      @sonjachr said:

                      I have contacted him and he told me that he could provide an API, which could solve my problem, hopefully.

                      That's excellent! IMO - his extension produce cleaner terrain than Sandbox Tools so that will be a win-win for you.

                      1 Reply Last reply Reply Quote 0
                      • fredo6F Offline
                        fredo6
                        last edited by

                        Just published the API in the main TopoShaper thread.

                        Documentation is attached in the main post.

                        Fredo

                        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