Find if object exists

Discussions concerning programming of SOFTIMAGE©
Post Reply
ionside
Posts: 16
Joined: 22 Dec 2011, 06:13
Location: Australia

Find if object exists

Post by ionside » 15 Sep 2012, 09:48

Sorry for such a simple problem, but it's a problem I can't figure out.
I need to check if a group exists and if not create it.

I've tried:

Code: Select all

wGroup = oRoot.FindChild('WeaponParts')
if (wGroup != ""):
	si.SelectObj(wGroup)
        log("group exists")
else:
	si.CreateGroup('WeaponParts')
Which just selects nothing and the the group exists, when I know very well it doesn't. And:

Code: Select all

wGroup = oRoot.FindChild("WeaponParts")
if (wGroup) == "WeaponParts":
	si.SelectObj(wGroup)
	log("group exists")
else:
	si.CreateGroup("WeaponParts")
Which just keeps creating new ones even when one exists.

I'm very confident I'm doing it completely wrong.

User avatar
origin
Posts: 619
Joined: 09 Jun 2009, 11:59
Location: warsaw

Re: Find if object exists

Post by origin » 15 Sep 2012, 10:09

findchild searchs for x3dobjects only

Code: Select all

a = Application
g = a.ActiveSceneRoot.Groups("Group")
if g:
	a.LogMessage("found")
else:
	a.LogMessage("not found")

ionside
Posts: 16
Joined: 22 Dec 2011, 06:13
Location: Australia

Re: Find if object exists

Post by ionside » 15 Sep 2012, 10:25

Thank you so much!

User avatar
probiner
Posts: 127
Joined: 17 Apr 2013, 11:52

Re: Find if object exists

Post by probiner » 29 Dec 2013, 10:04

sorry for necro-posting but it's totally related:

Code: Select all

#Sense Model name
app = Application
a = app.Selection(0).FullName
b = a.index('.')
Placement = a[0:b]

#Sense group existence
check = app.ActiveSceneRoot.Groups(Placement + "." + "BigGroup")

if check:
    app.LogMessage("found")
    app.AddToGroup(Placement + "." + "BigGroup", "")
else:
    app.LogMessage("not found")
    app.CreateGroup("BigGroup", "", Placement)
Trying to sense if a group exists inside of a model (which will be always be parented to the scene root)
My issue is the *check* variable. It never finds the group inside of the model and keeps adding up: Model.BigGroup1, Model.BigGroup2, Model.BigGroup3. If BigGroup exists in the Scene Root then check returns "True" and now all the time objects are added to Model.BigGroup.
How do I check for the existence of a Group inside a Model?

Cheers

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Find if object exists

Post by csaez » 29 Dec 2013, 17:07

Code: Select all

if not model.Groups(group_name):
    model.AddGroup(None, group_name)
:)

User avatar
probiner
Posts: 127
Joined: 17 Apr 2013, 11:52

Re: Find if object exists

Post by probiner » 07 Jan 2014, 01:37

Thanks :)

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests