Created
August 8, 2014 18:46
-
-
Save samthetechie/c80d6a26515b76c98618 to your computer and use it in GitHub Desktop.
Scrapes myFolia crowdsourced data in order to generate and import a geometrically representative cylinder of a mature plant, perhaps a vegetable or fruit into a google sketchup 3d stage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # fn plant_gen(x, y, z, height, width, name,[latin name] ) | |
| # scrapes myFolia crowdsourced data in order to generate and import a geometrically representative cylinder of a mature plant, perhaps a vegetable or fruit into a google sketchup 3d stage. | |
| # defaults: | |
| # height (cm or inches) | |
| # width (cm or inches) | |
| # name (title case) | |
| # Output: creates cylinders to represent the envelope of a vegetable or fruit plant in google sketchup | |
| # diameter of the cylinder is == width, height | |
| # | |
| # {x, y, z} is the position in model space for the base of the cylinder. | |
| # {r, h} are the radius and the height in ?? (probably inches) | |
| # Ideas: | |
| # Thinking about: optimisation of placement / like routing in PCB wizard / iterative solving / laying out | |
| # take inspiration from routing algorithms for circuit boards | |
| # take inpiration from rat's nest / components waiting to be placed. | |
| # notes for scraping | |
| # name: /html/body/div[2]/div[2]/div/div[2]/h1 i.e. <h1> | |
| # latin name: /html/body/div[2]/div[2]/div/div[2]/h2/em i.e. <h2> | |
| # height: /html/body/div[2]/div[2]/div/div[3]/div[5]/div/form/ul/li[4]/label/span called "Mature Height" | |
| # width: /html/body/div[2]/div[2]/div/div[3]/div[5]/div/form/ul/li[4]/label[2]/span called "Mature Spread" | |
| ''' | |
| coordinates = [10, 10, 10] | |
| model = Sketchup.active_model | |
| entities = model.entities | |
| point = Geom::Point3d.new coordinates | |
| text = entities.add_text "This is a Test", point | |
| ''' | |
| def cylinder(x, y, z, d, h, common_name, latin_name): | |
| p = Point3d(x, y, z) | |
| v = Vector3d(0, 0, 1) | |
| r = d / 2.0 | |
| model = Sketchup.active_model() | |
| entities = model.entities() | |
| model.start_operation("Cylinder") | |
| edges = entities.add_circle(p, v, r) | |
| face = entities.add_face(edges) | |
| if not face: | |
| print "No face created, maybe it already exists?" | |
| return | |
| face.pushpull(-h, False) | |
| face.reverse() | |
| color = "orange" #http://www.sketchup.com/intl/en/developer/docs/ourdoc/color.php accepts RGB | |
| coordinates = [x, y, z+h] #target to place the label at the top of the cylinder i.e. offset x,y,z (centered on x,y,z middle of circle and offset by the height of the cylinder. | |
| point = Geom::Point3d.new coordinates | |
| text = entities.add_text common_name, point | |
| ''' face.material = Sketchup::Color.new(255, 0, 0) | |
| face.material = 255 | |
| face.material = 0xff | |
| face.material = "red" | |
| face.material = "#ff0000" | |
| face.material = [1.0, 0.0, 0.0] | |
| face.material = [255, 0, 0] | |
| ''' | |
| face.material = color | |
| for face2 in face.all_connected(): | |
| face2.material = color | |
| model.commit_operation() | |
| # | |
| # Example of usage from Ruby Console: | |
| # | |
| # Py.example.cylinder(0, 0, 0, 10, 30) | |
| # | |
| # | |
| # Adding menu items | |
| # | |
| def plant_gen(): | |
| cylinder(0, 0, 0, 2.5, 15, "Carrot", "Daucus carota subsp. sativus") #15cm height, 2.5cm spread #cylinder(x, y, z, d, h, common_name, latin_name): | |
| import menus | |
| plugins_menu = menus.get_menu("Plugins") | |
| example_submenu = plugins_menu.add_submenu("pyFolia Plant Generator") | |
| example_submenu.add_item("PlantGen", plant_gen) | |
| # debian: wine + sketchup + python 2.5 + suPY | |
| #installation: http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/doc/installation_and_usage.html#mozTocId757691 | |
| #http://www.python.org/download/releases/2.5/ | |
Author
Author
I would now recommend a windows XP VM / vagrant with tinyXP vis. http://www.slideshare.net/damiensaunders/guide-to-virtualbox-and-tiny-xp-for-mac-os
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
debian: wine + sketchup + python 2.5 + suPY
installation: http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/doc/installation_and_usage.html#mozTocId757691
http://www.python.org/download/releases/2.5/