Patrick Winkler Posted April 15, 2016 Share Posted April 15, 2016 (edited) 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 April 15, 2016 by Patrick Winkler Quote Link to comment
Marionette Maven Marissa Farrell Posted April 15, 2016 Marionette Maven Share Posted April 15, 2016 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. Quote Link to comment
Marionette Maven Marissa Farrell Posted April 15, 2016 Marionette Maven Share Posted April 15, 2016 (edited) 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 April 15, 2016 by MarissaF Quote Link to comment
JBenghiat Posted April 15, 2016 Share Posted April 15, 2016 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 Quote Link to comment
Patrick Winkler Posted April 18, 2016 Author Share Posted April 18, 2016 thanks, it seems to be no real exception, the error get's printed to the console anyway and the Result is always True. Quote Link to comment
Patrick Winkler Posted June 7, 2016 Author Share Posted June 7, 2016 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.