Jump to content
Sign in to follow this  
Patrick Winkler

Check if Object is a Container

Recommended Posts

Hello,

I need to check if a object conatins other objects.

Therefore I wrote this function:

def isContainerObj (obj):
   return vs.FInGroup(obj) != vs.Handle (0) 

It works but vs.FInGroup will return a error Message to the console when the objects is no container.

Has someone a more elegant solution for this.

thanks

Edited by Patrick Winkler

Share this post


Link to post

What if you check the type of the object you're querying to see if it's a group or a symbol or another object type that could qualify as a container? That should let you know if it will have any "children".

Still a little clunky, but I'm sure there aren't many other object types that would qualify as a container.

Share this post


Link to post

In addition, if it IS a group/symbol/container object, you may also want to call GetParent on it to see if it's a child of ANOTHER group/symbol/container. (If it returns a Layer, then you're at the outermost container object)

Edited by MarissaF

Share this post


Link to post

You should be able to use the error to your advantage:

def isContainerObj (obj):
   try:
	h = vs.FInGroup(obj)
   except:
	return false
   else:
	return true

-Josh

Share this post


Link to post

I'm not sure about it but checking the type for vs.HandleContainer () should work accurate.


def isContainerObj (h):
t = type (h)

print (t)

return not type (h) == type (vs.Handle(0)) 



h = vs.FSActLayer ()
print ( isContainerObj (h) )


Maybe some one can confirm this.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×