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

About Jeff Rhodes
Jeff Rhodes is the Branch Chief, Program Office Support at the U.S. Office of Personnel Management (OPM). Prior to that, he was the Academic Chief Technical Officer at the United States Air Force Academy and previously a Senior IT Specialist in charge of SharePoint and other key systems at the Academy. Jeff was the founder and Chief Technical Officer of Platte Canyon Multimedia Software Corporation, a leader in developing commercial e-learning software. 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 Master’s degree in Economics from the London School of Economics, which he attended under a British Marshall Scholarship. He is the author of Creating Business Applications with Office 365: Techniques in SharePoint, PowerApps, Power BI, and More, Programming for e-Learning Developers: ToolBook, Flash, JavaScript, and Silverlight, VBTrain.Net: Creating Computer and Web Based Training with Visual Basic .NET and The ToolBook Companion. He lives in Colorado Springs with his wife Sue and is the proud father of his 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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: