SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Pages class

The Pages class contains methods for manipulating a collection of Pages (scenes) in a model.

Parent: Entity 

Methods: add_frame_change_observer, remove_frame_change_observer, [], add_observer,add, count, each, parent, remove_observer, selected_page, show_frame_at , size, slideshow_time

Example Code: pagestests.rb

Class Methods


add_frame_change_observer 

The add_frame_change_observer method is used to add a new frame change observer for animations

Syntax

pages.add_frame_change_observer object 
 

Arguments

object - an object that implements the frameChange method

Comments

The argument is an object that implements a method frameChange with the following form:

def frameChange(fromPage, toPage, parameter)
... 
 end

This method is called during a slide show or creation of an animation after the camera has been set up, but before the frame is displayed. It give you a chance to perform your own actions during the animation. The arguments for frameChange method are the Page that you transition from (fromPage), the Page that you transition to (toPage), and a parameter between 0 and 1 that tell you the percentage of the way between the two pages.

The method returns an integer that can be used to remove the observer

Example

number = Sketchup::Pages.add_frame_change_observer 
 FrameChangeObserver.new
class FrameChangeObserver
def frameChange(fromPage, toPage, parameter)
# Just show the information
#s1 = fromPage ? fromPage.name : "NULL"
#s2 = toPage ? toPage.name : "NULL"
#puts "#{s1} to #{s2} at #{parameter}"
if( parameter < 1.0e-3 )
get_entities_to_move(toPage)
else
move_entities parameter
end
end

 

 


remove_frame_change_observer

The remove_frame_change_observer method is used to remove a frame change observer

Syntax

pages.remove_frame_change_observer(observer_num)

Comments

The argument is the number returned from the call to add_frame_change_observer.

Example

number = Sketchup::Pages.remove_frame_change_observer

Instance Methods


[] 

The [] method retrieves a page by either name or index.

Syntax

page = pages[index] 
page = pages["name"] 

Arguments

index - the index for a specific page

name - the name of the specific page

Return Value

page - a Page object if successful

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
page = pages "Page 2"
if (page)
UI.messagebox page
else
UI.messagebox "Failure"
end

 

 


add_observer

The add_observer method is used to add an observer to the current object.

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


add

The add method is used to add a empty Page object

Syntax

page = pages.add 
page = pages.add name 
page = pages.add name, flags 

Arguments

name - the name of the specific page

flags -

Comments

If no name is given, then a new name is generated using the default name for new Pages.

If a name is given, then a new Page with that name is added.

If flags is given, it controls which properties are saved with the new Page. See Page.update for a description of the flags that can be set.

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end

 

 


count 

The count method is an alias for size. See also Page.size

Syntax

num_pages = pages.count 

Return Value

num_pages - the number of pages if successful

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
num = pages.count

 

 


each 

The each method is used to iterate through pages.

Syntax

pages.each {| page |...} 

Arguments

page – variables that will hold each page as it is found.

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
pages.each {|page| UI.messagebox page}

 

 


parent 

The parent method is used to determine the model for the pages.

Syntax

model = pages.parent 

Return Value

model - the model that contains the pages if successful

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
model = pages.parent

 

 



remove_observer

The remove_observer method is used to remove an observer from the current object.

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


selected_page 

The selected_page method is used to retrieve the currently selected page.

Syntax

page = pages.selected_page 

Return Value

page - the currently selected Page object if successful

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
page = pages.selected_page

 

 


show_frame_at 

The show_frame_at method is used to show a frame in animation (of the slide show) at a given time in seconds.

Syntax

pages.show_frame_at time_in_seconds 

Arguments

time_in_seconds - the time in seconds

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
status = pages.show_frame_at 10

 

 


size 

The size method is used to retrieve the number of pages.

Syntax

num_pages = pages.size 

Return Value

num_pages - the number of pages

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
size = pages.size

 

 


slideshow_time 

The slideshow_time method is used to retrieve the amount of time that a slideshow of all of the pages will take.

Syntax

time = pages.slideshow_time 

Return Value

time - the amount of time that a slide show will take if successful

Comments

This takes into account the transition time for each Page and the amount of time that each Page is displayed.

Example

model = Sketchup.active_model
pages = model.pages
status = pages.add "Page 1"
status = pages.add "Page 2"
status = pages.show_frame_at 10
time = pages.slideshow_time

 

SketchUp  Ruby API Reference: Pages

© Google Inc. 2007 sketchup.google.com