Need help with Ruby Plugin - Mac
-
Hi everyone,
This is my first post here. I was hoping for some help regarding a script a former co-worker had developed. Basically it is a batch rendering ruby for sketchup, it allows for quick animations by exporting a path of one surface. We use this in our firm to get simulations of water level changes for storm water control stuff.
When I try to use the plug-in it does not appear in the plug-in drop down (I'm on a Mac) even though I've installed it in Library>Application Support>Google Sketchup 8>Sketchup>Plugins. He no longer works with us so he transferred the ruby to me, but we're not sure why it is not working for me (We both have the same computer and version of Sketchup). His friend actually created the script for the ruby and he's too busy to help at the moment. We have a deadline for Monday so if anyone has any ideas please let me know. I'll attach the plugin. Thanks!
Dave
-
This file looks to be part of a larger set of files.
It will auto-load and fire straight away as it has no module wrapper, and no menu creation code.
It also needs an html file called, "batch_exporter_gui.html" inside a subfolder called "../Plugins/Batch_Exporter/" ?? That html file may well have related css, js, images files etc that it uses too...
Also the 'output' always goes into: "/Users/ryankahen/Desktop/geosyntec/Exports"
does this folder exist? or at least the../geosyntecfolder ??
You might want to fix that folder path to something more sensible ???To get this Ruby to have a chance to work can I suggest you do the following adjustments - edit the file with a plain text editor [not a wordprocessor!]...
Add this code to the very start of the script:require('sketchup.rb') module Carls unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Carl's Batch Exporter"){self.batchExporter()} end file_loaded(__FILE__) def self.batchExporter()THE MAIN CODE GOES HERE...
Then at the very end add this:
end#def end#moduleThe Plugins menu item should now run
Carls.batchExporter- provided of course that the needed html etc is in place... At least now there'll be error messages in the Ruby Console etc if it doesn't work...Considering the mess '
Carl' has left you might also want to think about changing the 'name' to something less personal and company specific... -
Thanks for the quick response. I did as you advised and added in that part of the script and changed ryan's directory to mine but now I get this message:
"Error Loading File batch_exporter.rb
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/batch_exporter.rb:103: parse error, unexpected kEND, expecting $
end#module
^"This is the "updated script" I've never used this before so I'm not sure I input in everything correctly
# Batch Exporter Driver File # Author; Carl Anderson # Email; cwanderson33@gmail.com # start of our edits require('sketchup.rb') module Carls unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Carl's Batch Exporter"){self.batchExporter()} end file_loaded(__FILE__) def self.batchExporter() # end of our edits # Instantiate WebDialog input_dialog = UI;;WebDialog.new("Carl's Batch Exporter", false, "Batch Exporter", 300, 270, 200, 150, true) # Add callback for sending sending data from Javascript/HTML back to ruby script input_dialog.add_action_callback("do_batch") {|dialog, params| # split the arguments on commas array_params = params.to_s.split(",") increment = array_params[0] height = array_params[1] axis = array_params[2] filetype = array_params[3] fileprefix = array_params[4] # convert strings to floats for math operations increment1 = increment.to_f height1 = height.to_f # get model model = Sketchup.active_model # get selected face #face = Sketchup.active_model.selection.first # get entities instead of first entity (for mac) face = Sketchup.active_model.selection # initialize loop variable i = 0 loop_count = height1 / increment1 # if export directory doesn't exist, create it # directory created in folder containing your project file #my_export_path = Dir.getwd + "/export" my_export_path = "/Users/giancarlid/Desktop/geosyntec/Exports" Dir.mkdir(my_export_path) unless File.exists?(my_export_path) # do a loop while i < loop_count # Create transformation to move the selection if axis == "0" transformation = Geom;;Transformation.new([increment1,0,0]) elsif axis == "1" transformation = Geom;;Transformation.new([0,increment1,0]) elsif axis == "2" transformation = Geom;;Transformation.new([0,0,increment1]) else UI.messagebox("Fatal Error... code should not have gotten here.") end # perform transformation (do the move on the object) Sketchup.active_model.entities.transform_entities(transformation, face) # create full filename and pathname full_filename = my_export_path + "/" + fileprefix + "_" + i.to_s + "." + filetype # export to file status = model.export full_filename # increment loop counter i = i + 1 end # alert user that export has completed UI.beep UI.messagebox("Exporting Complete!") } # Set HTML file to display in window #input_dialog.set_file "mypage.html" # Find and show our html file html_path = Sketchup.find_support_file "batch_exporter_gui.html" ,"Plugins/Batch_Exporter/" input_dialog.set_file(html_path) input_dialog.show() # start of our edits end if( not file_loaded?("batch_exporter.rb") ) ###UI.menu("Plugins").add_separator UI.menu("Plugins").add_item("Batch Exporter") { export_batch } end ### file_loaded("batch_exporter.rb") # end of our edits end#def end#module # Batch Exporter Driver File # Author; Carl Anderson # Email; cwanderson33@gmail.com # start of our edits require('sketchup.rb') module Carls unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("Carl's Batch Exporter"){self.batchExporter()} end file_loaded(__FILE__) def self.batchExporter() # end of our edits # Instantiate WebDialog input_dialog = UI;;WebDialog.new("Carl's Batch Exporter", false, "Batch Exporter", 300, 270, 200, 150, true) # Add callback for sending sending data from Javascript/HTML back to ruby script input_dialog.add_action_callback("do_batch") {|dialog, params| # split the arguments on commas array_params = params.to_s.split(",") increment = array_params[0] height = array_params[1] axis = array_params[2] filetype = array_params[3] fileprefix = array_params[4] # convert strings to floats for math operations increment1 = increment.to_f height1 = height.to_f # get model model = Sketchup.active_model # get selected face #face = Sketchup.active_model.selection.first # get entities instead of first entity (for mac) face = Sketchup.active_model.selection # initialize loop variable i = 0 loop_count = height1 / increment1 # if export directory doesn't exist, create it # directory created in folder containing your project file #my_export_path = Dir.getwd + "/export" my_export_path = "/Users/giancarlid/Desktop/geosyntec/Exports" Dir.mkdir(my_export_path) unless File.exists?(my_export_path) # do a loop while i < loop_count # Create transformation to move the selection if axis == "0" transformation = Geom;;Transformation.new([increment1,0,0]) elsif axis == "1" transformation = Geom;;Transformation.new([0,increment1,0]) elsif axis == "2" transformation = Geom;;Transformation.new([0,0,increment1]) else UI.messagebox("Fatal Error... code should not have gotten here.") end # perform transformation (do the move on the object) Sketchup.active_model.entities.transform_entities(transformation, face) # create full filename and pathname full_filename = my_export_path + "/" + fileprefix + "_" + i.to_s + "." + filetype # export to file status = model.export full_filename # increment loop counter i = i + 1 end # alert user that export has completed UI.beep UI.messagebox("Exporting Complete!") } # Set HTML file to display in window #input_dialog.set_file "mypage.html" # Find and show our html file html_path = Sketchup.find_support_file "batch_exporter_gui.html" ,"Plugins/Batch_Exporter/" input_dialog.set_file(html_path) input_dialog.show() end end#def end#moduleThanks for the help!
Dave -
I've put that into a 'code' block for you...
` endend#def
end#moduleremove the first '**end**' I don't know where it came from... your typo ??end#def
end#module` -
Although the "Carl's Exporter" is now shown in the plugins, it doesn't seem to do anything. Ryan (the former employee) said
"They way I used it was I select the top plane of the water( or which ever plan you are moving. You can select the direction it moves) and then run the plugin"
Simple as that. Although it doesn't seem to be doing anything. Maybe it is missing a file or something. Has anyone had any better luck.
Basically the idea is that you click the surface, run the plugin, select the direction you want the plan to go and it'll push/pull the surface in that direction to the point you want (making it look as those the literal box of water is getting bigger or smaller). It'll export all the those files to a batch rendered so they can be processed. I'm still a bit confused about it myself but Ryan is unreachable and there's still a lot of work do be done for the presentation Monday.
I really appreciate the help. I've never posted here before but I utilize the forum for tips and fixes all the time.
Dave
-
Without the .html file and everything else I can't see how it all works...

-
Moved topic to the Developer section.
-
Is the path correct? Your using html_path = Sketchup.find_support_file "batch_exporter_gui.html" ,"Plugins/Batch_Exporter/"
Maybe something like this is safer?
html_path=File.join(File.dirname(FILE), "Batch_Exporter/batch_exporter_gui.html")For what I know Sketchup.find_support_file should be avoided since not every ones computerdisks looks the same.
-
@jolran said:
For what I know Sketchup.find_support_file should be avoided since not every ones computerdisks looks the same.
Not because the disks are different. But because Sketchup.find_support_file will look up a file in SketchUp's Plugins folder - and people might install their plugins elsewhere. Like I do, I install to my Dropbox folder so I sync plugins between versions and computers.
More info: http://www.thomthom.net/thoughts/2012/09/sketchup-plugins-can-be-installed-anywhere/ -
Ah yeah, thats correct. At least I got a part of it right.
Nice link BTW. Good reading.
Advertisement