Access Stamp UV mesh through scripting

Discussions concerning programming of SOFTIMAGE©
User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Access Stamp UV mesh through scripting

Post by Pete » 06 Feb 2012, 03:11

Hi all!,

Does anyone know if theres a way to access Stamp UV through scripting? I'd really love to be able to script it so i could make it fit my workflow a little better.

Thanks
Pete

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

Re: Access Stamp UV mesh through scripting

Post by origin » 06 Feb 2012, 10:46

not possible afaik

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 06 Feb 2012, 11:49

Damn! I really hate the stamp uv workflow and I was really hoping I could make it into more of a one click type affair...

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Access Stamp UV mesh through scripting

Post by Hirazi Blue » 06 Feb 2012, 11:56

Just found this post by Stefan Kubicek on the Mailing List:
Kim Aldis once sent me a Python plugin for Softimage that would export a UV set as an EPS file for import into Photoshop. The nice thing is that the EPS will import into Pshop as lines and is thus resolution independant.
(Quoted from here, where you can find the plugin as an attachment)
Stay safe, sane & healthy!

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

Re: Access Stamp UV mesh through scripting

Post by origin » 06 Feb 2012, 12:24

Thanks Hirazi
Would love to see some kind of chrome-like addon marketplace, so many gems are scattered all over the web

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Access Stamp UV mesh through scripting

Post by Hirazi Blue » 06 Feb 2012, 15:04

rray.de seems a good start...
Stay safe, sane & healthy!

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 07 Feb 2012, 06:53

Wow, thanks Hirazi, that sounds seriously cool!
(oh and of course Kim Aldis & Stefan Kubicek :) )
Would love to see some kind of chrome-like addon marketplace, so many gems are scattered all over the web
Dude, that would be awesome. It's such a shame things are scattered so much.
It's a bummer AD killed the softimage site they were starting back in early ice days, the Area just plain sucks.

rray is pretty much the go to spot for me now.

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Access Stamp UV mesh through scripting

Post by Hirazi Blue » 07 Feb 2012, 16:50

Before anyone else mentions it: the aforementioned Kim Aldis plugin
was already available on rray.de as well,
if only I had looked there first...
;)
Stay safe, sane & healthy!

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Access Stamp UV mesh through scripting

Post by myara » 15 Feb 2012, 09:12

Kim Aldis EPSexport never worked for me.

I may be wrong but it seems like it was written to export Camera image to EPS, not UVs.
But I can't even do that, it just doesn't write anything here.

I don't know how useful can this be to you but you can "type" through WSH.
Meaning you can activate a shortcut with your script.
Therefore, you can activate the Stamp UV Mesh through scripting.

Not very elegant, and obviously it won't work in a different PC with different shortcuts.

I was experimenting with this a while ago, but never actually done anything elaborated.

Let's asume you have a polygon selected, and this polygon has an UV.

Code: Select all

//JScript
var WshShell = new ActiveXObject("WScript.shell")

// If the Texture Editor is already opened, close it!
// I don't know how to make it work with an already opened Texture Editor so I decided to close it.
var views = Application.Desktop.ActiveLayout.Views
for (var i=0, a=views.count; i< a; i++){
	if (views(i).name == "Texture Editor"){
		views(i).state = siClosed;
	}
}

Sleep(0.00001) // it usually works with 0 too, but just in case
// Open the Texture Editor
OpenView ("Texture Editor")

Sleep(0.00001)

// Now type some keys!
// "+s"  = Shift S
WshShell.SendKeys ("+s")

//------------

function Sleep(seconds){
    // Creating the VBS Sleep File in C:\
    var FSO  = new ActiveXObject("Scripting.FilesystemObject"); 
    var VBSleep = FSO.CreateTextFile("C:\\vbsleep.vbs", true);
    VBSleep.WriteLine("dim mult : mult = wscript.Arguments.Item(0)"); 
    VBSleep.WriteLine("wscript.sleep 1000 * mult"); 
    VBSleep.Close(); 

    // Calling VBS Sleep
    var WshShell =  new ActiveXObject("WScript.Shell");
    WshShell.run("C:\\vbsleep.vbs " + seconds, 2, 1)
    FSO.DeleteFile("C:\\vbsleep.vbs")
}
As you can see, this script will write a temporal file in C:\ so you will need to have write permissions.

Anyway, if your short key for Stamp UV is Shift + S, you'll get a save image (stampUV) dialog with this script.

You can check here the WshShell SendKeys Codes:
http://www.devguru.com/technologies/wsh/quickref/wshshell_SendKeys.html

If you want to experiment with this, remember:

- The mouse cursor position affects the keyboard input.
- The normal keyboard input may get mixed with the script input.
Ex: Activate the script with CTRL + Click and if the release timing is not perfect, the CTRL key may get mixed with the scripted keyboard input (in this case it would become CTRL+Shift+S).
- You need to give the windows and actions some time to operate, that's why I added an improvised JScript Sleep.

The problem is that if the mouse is not over the Texture Editor when the Stamp UV command runs, it won't work.
I mean, the Shift+S input will work but outside the Texture Editor so you may be opening Camera Visibility.
I don't know how to force XSI to focus on the recently opened Window and ignore the mouse position so a workaround I'm applying here is to create a VBS file in C:\ to Sleep a little between commands and it seems to work.

I tried with a JScript "while date" sleep method without good results, so maybe the key is not the time delay, I don't know.

Python Time.Sleep results are worst, it just delay the whole process, but it may be because of my limited Python knowledge.
Last edited by myara on 15 Feb 2012, 11:36, edited 2 times in total.
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 15 Feb 2012, 11:02

Hey myara!
Yeah I unfortunately spoke too soon with the EPS script, I had the same probs so it didn't work out for me.

Your script worked though so thanks heaps!!
I tried to add to the script to hopefully get it to put in a filename with this -

Code: Select all

// Now type some keys!
// "+s"  = Shift S
WshShell.SendKeys ("+s");

Sleep(.1);
WshShell.SendKeys ("stamp.png");
But that just seemed to make the whole thing stop. Any ideas?

Thanks again for the help, glad im not the only one that finds it annoying :)
Pete.

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Access Stamp UV mesh through scripting

Post by myara » 15 Feb 2012, 11:55

It seems that StampUV doesn't like my vbsSleep :D

But it works without it, try this:

Code: Select all

//JScript

var WshShell = new ActiveXObject("WScript.shell")

// If the Texture Editor is already opened, close it!
// I don't know how to make it work with an already opened Texture Editor so I decided to close it.
var views = Application.Desktop.ActiveLayout.Views
for (var i=0, a=views.count; i< a; i++){
   if (views(i).name == "Texture Editor"){
      views(i).state = siClosed;
   }
}

CreateSleep(0) // Create vbsSleep

Sleep(0.01)

// Open the Texture Editor
OpenView ("Texture Editor")

Sleep(0.1)

// Now type some keys!
// "+s"  = Shift S
WshShell.SendKeys ("+s");
WshShell.SendKeys ("stamp");  // specify your file name
WshShell.SendKeys ("{TAB}");  // tab to change focus to the extension drop menu
WshShell.SendKeys ("png"); // your file extension
WshShell.SendKeys ("{ENTER}"); // Enter

CreateSleep(1) // Delete vbsSleep

//------------
function CreateSleep(option){
	var FSO  = new ActiveXObject("Scripting.FilesystemObject"); 
	if(option==0){
		// Creating the VBS Sleep File in C:\
		var VBSleep = FSO.CreateTextFile("C:\\vbsleep.vbs", true);
		VBSleep.WriteLine("dim mult : mult = wscript.Arguments.Item(0)"); 
		VBSleep.WriteLine("wscript.sleep 1000 * mult"); 
		VBSleep.Close(); 
	}
	else if (option==1){
		    FSO.DeleteFile("C:\\vbsleep.vbs")
	}
}
function Sleep(seconds){
    // Calling VBS Sleep
    var WshShell =  new ActiveXObject("WScript.Shell");
    WshShell.run("C:\\vbsleep.vbs " + seconds, 2, 1)
}
I'm starting to get XSI Crashes when the Sleeps are too short, so I incremented them to 0.01 and 0.1 seconds.

You will have to manually click on "OK" to confirm overwriting, specify compression, etc.
I still haven't found a solution to this, but now I really got to get back to work :D

Good Luck
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 17 Feb 2012, 05:43

Hey Myara,

I grabbed your already hacky code and made it into some kind of crazy hack monster!
Sure, it could use some serious ironing out but it works for me!

Here's a few notes -
So you select an object and run the script
You then get these options
Image
Then it (hopefully) pops out an image file based on those options. (into your project/pictures directory)

Here's the script -
WARNING - this script is really hacky, maybe save your scene before using it
http://www.naffupdate.com/forumfiles/QuickStamp.js

Maybe have a look if you are feeling brave :)
Last edited by Pete on 17 Feb 2012, 09:53, edited 1 time in total.

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Access Stamp UV mesh through scripting

Post by myara » 17 Feb 2012, 09:21

lol that's a hacky wacky monster code! kinda dangerous but I loved it :D

You may need to add some check routines like selection check, check if the Script folder exists, use OM instead of names like "DefaultLib" because the Current Lib may be different, but it seems to do the job done. Most of the time at least.

Since you are using a lot of commands you may want to disable the log to improve performance a little.

Code: Select all

var prefs = Application.Preferences;
prefs.SetPreferenceValue( "scripting.cmdlog", false );
note : You don't need to change this value back

Oh, and a warning save scene now! option would be good too :))
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 17 Feb 2012, 09:49

Oh, and a warning save scene now! option would be good too
Haha, yeah!
It's kinda embarrassingly dodgy but funny at the same time and it gets the job done for me so i thought i should put it up here :)

Thanks for the help, i updated the script.

Pete

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Access Stamp UV mesh through scripting

Post by myara » 18 Feb 2012, 07:28

Since the code leaves an object and 2 materials, how about this workaround:

Code: Select all

var quickobj = ActiveSceneRoot.FindChild("QuickStampObj")
if(quickobj){
	DeleteObj(quickobj)
	var oMatLibs = ActiveProject.ActiveScene.MaterialLibraries
	for ( var i=0, a = oMatLibs.Count; i < a; i++ ) {
		var oMats = oMatLibs(i).items
		for ( var j=0, b = oMats.Count; j < b; j++ ) {
			if (oMats(j).name.substr(0,14) =="QuickStampTemp"){
				DeleteObj(oMats(j))
			}
		}
	}
}
else{
// quick stamp code here
}
If QuickStamp garbage is found, it will delete them and stop the script.
If no garbage is found, start QuickStamp.

So it would be a 2 step, 2 click process, but better than do it manually I guess.
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 09:28

Re: Access Stamp UV mesh through scripting

Post by Pete » 22 Feb 2012, 02:17

Hey thanks Myra,

I updated the script, this time the parameters are created on the QuickStamp object, So if you have to run the script again it re-uses the your last QuickStamp prefs.
I haven't added the material stuff yet (I'm scared :-s ) The whole material/clip section was so finicky that I think i'll break something if I try to tweak it.

Hey I wasn't too sure what you meant earlier when you said
use OM instead of names like "DefaultLib"
what's OM?

Thanks
Pete

Post Reply

Who is online

Users browsing this forum: No registered users and 62 guests