Download presentation
Presentation is loading. Please wait.
1
Programming in Sketchup
2
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
3
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
4
Programming in Sketchup To write Ruby programs, we need a plain-text editor We will use TextEdit, which is in the Applications folder
5
Programming in Sketchup By default, TextEdit creates Rich Text files We must change this in the TextEdit preferences
6
Programming in Sketchup Below, we see the default situation
7
Programming in Sketchup Below, we have changed this to plain text
8
Programming in Sketchup A simple one-line Ruby program: UI.messagebox('Hello World!')
9
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,...
10
Programming in Sketchup... a message box pops up, containing the string we specified
11
A program which adds a menu item module Say_Hello def Say_Hello.main UI.messagebox("Hello world!") end UI.menu("Plugins").add_item("Greet the world") { Say_Hello.main }
12
Programming in Sketchup Let's overwrite the previous program with this new one
13
Programming in Sketchup When we re-start Sketchup, we do not see the greeting we saw before
14
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
15
Programming in Sketchup When we click on the Plugins menu item, we see the option Greet the world
16
Programming in Sketchup If we choose the option Greet the world,...
17
Programming in Sketchup... we receive the Hello World greeting
18
Programming in Sketchup If we click OK on the message box, we can start drawing
19
Programming in Sketchup Let's create a box
20
Programming in Sketchup We can then use the Greet the World option again and...
21
Programming in Sketchup... we receive the greeting again
22
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 UI.menu("Plugins").add_item("Draw triangle") { Draw_triangle.main }
23
Programming in Sketchup Saving the program in the plugins folder in a file called draw_triangle.rb
24
Programming in Sketchup Re-starting Sketchup
25
Programming in Sketchup Now, we have two of our own plugins
26
Programming in Sketchup Let's choose the new one
27
Programming in Sketchup A triangle is created
28
Programming in Sketchup If we remove Sang, we can see the triangle more clearly
29
Programming in Sketchup Let's move the triangle and...
30
Programming in Sketchup... use the plugin again
31
Programming in Sketchup As expected, we get another triangle
32
Exercise Tackle Exercise 34
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.