Start_operation/commit_operation with sandboxTools
-
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 Terrain1What 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
rescuemodel.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
-
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?
-
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.
-
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.
-
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.
-
@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.
-
I see that TIG also has a script to generate a mesh from points. You might try to reach out to him too.
-
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. -
@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.
-
Just published the API in the main TopoShaper thread.
Documentation is attached in the main post.
Fredo
Advertisement