Determining if an Object is Within a Group

I’m putting some recent (2010 and later) segments from The EnterPage Newsletter into my blog. That is what is behind this flurry of activity:).

Question: I want to find out through OpenScript whether an object is part of a certain group.

Answer: Since objects and groups can be within other groups, I think the easiest way is to loop through the parents of the object as in the code below. If you know that there is only a single group, though, a quicker solution would be to use the objectContainer function like this:

groupId = objectContainer(button "button 1", "group") 
if groupId = group "group 2"
	request "IsInGroup = true"
else
	request "IsInGroup = false"
end if

Here is a more general solution that will work with groups inside groups.

to handle buttonClick
	local logical isInGroup

	isInGroup = findIfInGroup(button "button 1", group "group 2")
	request "isInGroup = " & isInGroup
end buttonClick

to get findIfInGroup object startingObject, object groupObject
	local logical inGroup
	local object parentId
	local string parentType

	parentId = startingObject
	parentType = object of startingObject

	inGroup = FALSE
	while (inGroup = FALSE AND (parentType <> "page" AND parentType <> "background"))
		parentId = parent of parentId
		if parentId is groupObject
			inGroup = TRUE
		else
			parentType = object of parentId
		end if
	end while

	return inGroup
end findIfInGroup
Advertisements

About Jeff Rhodes
Jeff Rhodes is the Chief Technical Officer and owner of Platte Canyon Multimedia Software Corporation, a leader in developing commercial software that Improves the Lives of Training Developers. He graduated at the top of his class at the Air Force Academy, where he earned a Bachelor of Science in Electrical Engineering. Jeff received a Masters degree in Economics from the London School of Economics, which he attended under a British Marshall Scholarship. Jeff is the author of "Programming for e-Learning Developers: ToolBook, Flash, JavaScript, & Silverlight" and "VBTrain.Net: Creating Computer and Web Based Training with Visual Basic .NET." He also co-wrote "The ToolBook Companion." He has had numerous articles on training development published and is a frequent presenter at conferences both in the U.S. and Europe. Jeff lives in Colorado Springs with his wife Sue and sons Derek and Michael.

One Response to Determining if an Object is Within a Group

  1. robert petrosky says:

    dear jeff I am a long time user of toolbook 3.0 &4.0 I do this at home just for me because I like the program I cant afford the new toolbook $000.00 it is out of my range but I mite be able to afford
    toolbook 10 but I cant find it anywhere do you have any ideas for me I am 60 years old and going strong thanks jeff.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: