programming in sketchup. we can add programmed behaviour to sketchup the language used is ruby, an...

32
Programming in Sketchup

Post on 20-Dec-2015

245 views

Category:

Documents


1 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Exercise

• Tackle Exercise 34