Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an...
-
date post
20-Dec-2015 -
Category
Documents
-
view
248 -
download
1
Transcript of Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an...
![Page 1: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/1.jpg)
Programming in Sketchup
![Page 2: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/2.jpg)
Programming in Sketchup
• We can add programmed behaviour to Sketchup
• The language used is Ruby, an object-oriented programming language
• There are several ways of adding Ruby programs to Sketchup
• We will focus on plugins
![Page 3: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/3.jpg)
Programming in Sketchup• Look at the Sketchup menu bar below• It contains the following items
Sketchup File Edit View Camera Draw Tools Window Help
• This will change when we add certain types of plugin to Sketchup
![Page 4: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/4.jpg)
Programming in Sketchup• To write Ruby programs, we need a plain-text editor• We will use TextEdit, which is in the Applications folder
![Page 5: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/5.jpg)
Programming in Sketchup• By default, TextEdit creates Rich Text files• We must change this in the TextEdit preferences
![Page 6: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/6.jpg)
Programming in Sketchup• Below, we see the default situation
![Page 7: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/7.jpg)
Programming in Sketchup• Below, we have changed this to plain text
![Page 8: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/8.jpg)
Programming in Sketchup• A simple one-line Ruby program:
UI.messagebox('Hello World!')
![Page 9: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/9.jpg)
Programming in Sketchup• We save the program in a filled called helloWorld.rb in this folder:
/Library/Application Support/Google SketchUp [n]/plugins • Now, when we restart Sketchup, ...
![Page 10: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/10.jpg)
Programming in Sketchup• ... a message box pops up, containing the string we specified
![Page 11: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/11.jpg)
A program which adds a menu item
module Say_Hello
def Say_Hello.main
UI.messagebox("Hello world!")
end
end
UI.menu("Plugins").add_item("Greet the world") { Say_Hello.main }
![Page 12: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/12.jpg)
Programming in Sketchup• Let's overwrite the previous program with this new one
![Page 13: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/13.jpg)
Programming in Sketchup• When we re-start Sketchup, we do not see the greeting we saw
before
![Page 14: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/14.jpg)
Programming in Sketchup• But notice that there is a new item in the Sketchup menu bar• It now contains the following items
Sketchup File Edit View Camera Draw Tools Window Plugins Hello
![Page 15: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/15.jpg)
Programming in Sketchup• When we click on the Plugins menu item, we see the option Greet the world
![Page 16: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/16.jpg)
Programming in Sketchup• If we choose the option Greet the world, ...
![Page 17: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/17.jpg)
Programming in Sketchup• ... we receive the Hello World greeting
![Page 18: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/18.jpg)
Programming in Sketchup• If we click OK on the message box, we can start drawing
![Page 19: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/19.jpg)
Programming in Sketchup• Let's create a box
![Page 20: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/20.jpg)
Programming in Sketchup• We can then use the Greet the World option again and ...
![Page 21: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/21.jpg)
Programming in Sketchup• ... we receive the greeting again
![Page 22: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/22.jpg)
A program which draws geometry
module Draw_triangle
def Draw_triangle.main
point1 = [0,0,0]
point2 = [20,20,20]
point3 = [20,20,0]
Sketchup.active_model,entities.add_face point1,point2,point3
end
end
UI.menu("Plugins").add_item("Draw triangle") { Draw_triangle.main }
![Page 23: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/23.jpg)
Programming in Sketchup• Saving the program in the plugins folder in a file called draw_triangle.rb
![Page 24: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/24.jpg)
Programming in Sketchup• Re-starting Sketchup
![Page 25: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/25.jpg)
Programming in Sketchup• Now, we have two of our own plugins
![Page 26: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/26.jpg)
Programming in Sketchup• Let's choose the new one
![Page 27: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/27.jpg)
Programming in Sketchup• A triangle is created
![Page 28: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/28.jpg)
Programming in Sketchup• If we remove Sang, we can see the triangle more clearly
![Page 29: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/29.jpg)
Programming in Sketchup• Let's move the triangle and ...
![Page 30: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/30.jpg)
Programming in Sketchup• ... use the plugin again
![Page 31: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/31.jpg)
Programming in Sketchup• As expected, we get another triangle
![Page 32: Programming in Sketchup. We can add programmed behaviour to Sketchup The language used is Ruby, an object- oriented programming language There are several.](https://reader035.fdocuments.net/reader035/viewer/2022062308/56649d4a5503460f94a2767e/html5/thumbnails/32.jpg)
Exercise
• Tackle Exercise 34