How can I use a picksession's selections within a script ?

Discussions concerning programming of SOFTIMAGE©
SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 00:30

How can I use a picksession's selections within a script ?

Post by SpookyMunky » 10 Dec 2012, 19:54

I've never been very good at all with scripting so sorry if this is completely obvious.. I have been playing around with using softimage to make a skyrim character out of boredom, and through just copying and pasting in script editor for the most part made a simple vbs script to constrain the skyrim biped rig to the rig generated by gear's biped guide.

http://pastebin.com/3BHh6d8K is what I have so far, and surprisingly (for me) works, but I'd like to make it less scene dependant, so at the start it'd have a PickElement session like say - "Select the model containing the skyrim rig" , then "Select the model containing the gear rig" and use that data so lines like

Code: Select all

ApplyCns "Pose", "SkyrimModel.NPC_L_UpperArm__LUar_", "Gear-Rig.arm_L0_0_shd", True
would be more like

Code: Select all

ApplyCns "Pose", "PickSession1.NPC_L_UpperArm__LUar_", "PickSession2.arm_L0_0_shd", True
I cant seem to figure out a way to store and retrieve the pick data to use it in this way though, feel so dim :)

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

Re: How can I use a picksession's selections within a script ?

Post by csaez » 10 Dec 2012, 23:08

Hi,
Look in the SDK help for PickObject command.
PickObject( LeftMessage, MiddleMessage, [PickedElement], [ButtonPressed], [ModifierPressed] );
So...

Code: Select all

PickObject "Skyrim model", "Skyrim model", PickSession1
PickObject "Gear rig", "Gear rig", PickSession2
ApplyCns "Pose", PickSession1 + ".NPC_L_UpperArm__LUar_", PickSession2 + ".arm_L0_0_shd", True

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 00:30

Re: How can I use a picksession's selections within a script ?

Post by SpookyMunky » 10 Dec 2012, 23:37

Thank you so much for your reply :) , I had been trying something like that but hadn't thought to add the + between the picks and the "joints", knew I was being dim !

With a little search and replace I have gotten it working for the most part, though parts like

Code: Select all

ParentObj "B:PickSession2", "Cons_Right_Knee"
Aren't working, not a huge deal and am probably being dim still

Thanks again :)

Edit: I just had to remover the "B: " part and it works, rock on :)

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 00:30

Re: How can I use a picksession's selections within a script ?

Post by SpookyMunky » 11 Dec 2012, 00:28

hmm, I can't seem to figure out the group parts..

Code: Select all

CreateGroup "JointConst", PickSession2 + ".Cons_Left_Elbow", PickSession2 + ".Cons_Left_Knee", PickSession2 + ".Cons_Right_Elbow", PickSession2 + ".Cons_Right_Knee"
Is there a special way of wrapping that so creategroup will understand it ?, If I put it all in " ", I get an Expected end of statement error, if I use [] it strangely half works for that line, creates a group called jointconst with .Cons_Left_Knee as its only member, other lines it doesnt work atall... hmm, for that group there is a work around, but the one that hides the toes I can't think of one... I could just leave it out I guess :P

User avatar
gustavoeb
Moderator
Posts: 587
Joined: 20 Jul 2010, 22:33
Skype: gustavoboehs

Re: How can I use a picksession's selections within a script ?

Post by gustavoeb » 11 Dec 2012, 02:33

here is how you could do it

Code: Select all

create a variable for the object that will be picked
create a variable for all the objects that have been picked

while the object is not None
  pick a new object
  if it is valid, add it to the list

add each object in the list to your selection

create a group
here is how it would look in python:

Code: Select all

	oObj = ""
	oList = []
	
	while oObj != None:
		rtn = Application.PickElement("", pickMessage, pickMessage)
		oObj = rtn.Value("PickedElement")
		if oObj != None: oList.append(str(oObj))
	
	for i in range(len(oList)):
		Application.AddToSelection(oList[i], "", True)
	
	Application.CreateGroup("", "", "")
maybe there are smarter ways to do it, but I had this code laying around, so...
Gustavo Eggert Boehs
Blog: http://www.gustavoeb.com.br/

SpookyMunky
Posts: 102
Joined: 14 Jun 2012, 00:30

Re: How can I use a picksession's selections within a script ?

Post by SpookyMunky » 11 Dec 2012, 02:53

Thanks, I just managed to get it working in my script by splitting the command up into seperate addtogroup parts, instead of using one line with all the parts in it -

Code: Select all

AddToGroup "HideTheToes", PickSession2 + ".toe_L2_fk0_ctl"
I had to do the same for my "undo" script -

Code: Select all

RemoveAllCns PickSession1 + ".NPC_COM__COM__", 1 
etc, instead of having one RemoveAllCns to do every object

I think that is me pretty much finished for now :)