Materials without Shader Node

Discussions concerning programming of SOFTIMAGE©
Post Reply
Falam

Materials without Shader Node

Post by Falam » 14 Jul 2013, 19:10

Code: Select all

Application.ActiveSceneRoot
function withoutMat() {
if (j=0 j<=ActiveScene j"")
oFind = FindObjects (Corridor)
oRoot.LogMessage("")
}
What is wrong with the above syntax (parts of the code are intentionally left broken), I want to search within a model for all materials that don't contain a specific connected shader node ?

The FindObjects syntax wants the ClassID, how do I find the ClassID for selected Materials in a Model that don't contain a specific shader node. I can't put together, arghhh.

Ahmidou
Posts: 106
Joined: 04 Jan 2010, 14:00

Re: Materials without Shader Node

Post by Ahmidou » 15 Jul 2013, 03:34

Falam, you're regulary asking for things that are just under you nose, it's clearly explained in the FindObjects documentation how to get
the ClassID on an object.
Anyway here's a trick for you, you can access any object inforamtions in the SDK explorer.

Cheers
A.

Moderator edit: Please use screen names, not real names - HB

Falam

Re: Materials without Shader Node

Post by Falam » 15 Jul 2013, 04:48

Ahmidou wrote:Falam, you're regulary asking for things that are just under you nose, it's clearly explained in the FindObjects documentation how to get
the ClassID on an object.
Anyway here's a trick for you, you can access any object inforamtions in the SDK explorer.

Cheers
A.

Moderator edit: Please use screen names, not real names - HB
I bet it probably is easy, the "a-ah" moment hasn't come for me, I am trying, searching in the SDK, searching in SDK explorer, looking up syntax commands, until I have to stop because it's just not working. If I don't post any code, I'm looked at as though I want it done for me, when I post code it's not correct, I can't win, either way someone is going to find fault or there is fault if it's from my direction.

Ahmidou
Posts: 106
Joined: 04 Jan 2010, 14:00

Re: Materials without Shader Node

Post by Ahmidou » 15 Jul 2013, 06:47

Well search harder, it is in the SDK explorer in the advance tab...

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 11:02
Location: Montreal Canada
Contact:

Re: Materials without Shader Node

Post by xsisupport » 15 Jul 2013, 13:28

There's maybe seven things wrong with that snippet. I suggest you take a step back and take some time to learn some basics. You could try something like codeacademy.

PS My name is in my sig, so feel free to use it. Or not.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

Falam

Re: Materials without Shader Node

Post by Falam » 15 Jul 2013, 15:36

xsisupport wrote:There's maybe seven things wrong with that snippet. I suggest you take a step back and take some time to learn some basics. You could try something like codeacademy.

PS My name is in my sig, so feel free to use it. Or not.
At present, I'm learning JS, it's the order of how it is suppose to work, that is frustrating me. Some of you could probably code it in five, ten minutes and proceed forward. I've put time delays on a project due to this script, arghh.

Falam

Re: Materials without Shader Node

Post by Falam » 23 Jul 2013, 15:53

Argghh. If there are twenty unconnected nodes in a material, trying to tell softimage to search if any of those one are connected to the actual material is frustrating.

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

Re: Materials without Shader Node

Post by myara » 30 Jul 2013, 12:40

The problem is that people here can help you with hints, or show you how to get some specific things, but we can't teach you how to script from scratch. It's like trying to teach you how to write a poem when you can't write a sentence.

Learning scripting without programming knowledge isn't something you can do it in a day.

Your code is completely broken and you are mixing things. it doesn't matter what language you learn, but first learn a few basic things like if, else, for loop, etc. and stick with them until you feel familiar with the language. You can do a lot of things with only that. The next step is learn the sdk, try to understand the OM structure, and keep improving your scripting skills with functions and other fancy things.

Specific shaders don't have a ClassID. I mean, the class is shaders so you can't filter "lambert" with that. I would use ProgID.

Code: Select all

//JScript
var exception = "phong"		//specify unwanted shader
var obj = selection(0)		//get selected object
var mats = obj.materials	//get all mats from your selected object

//create a recipient for your result
var oColl = XSIFactory.CreateObject( "XSI.Collection" );

//loop your mats
for (var i=0; i<mats.count ; i++){
	// loop your mats' shaders
	var shaders = mats(i).GetAllShaders()
	for (var j=0; j<shaders.count ; j ++){
		// compare your shaders with your unwanted shader name
		if (shaders(j).progid.indexOf(exception) == -1) oColl.Add(mats(i))
	}
}

//select your filtered mats collection
selectobj (oColl)
Its looping inside a loop so it may not be very fast (although I doubt you have millions of shaders and materials), but it works and i wrote it using, for loop, if and indexOf.

So first, learn the basic stuff, read until you understand it before trying to do complex things. Step by step.

if you can't make a simple logmessage work, then you are not ready to walk through your material shaders.
M.Yara
Character Modeler | Softimage Generalist (sort of)

Falam

Re: Materials without Shader Node

Post by Falam » 30 Jul 2013, 15:50

myara wrote:The problem is that people here can help you with hints, or show you how to get some specific things, but we can't teach you how to script from scratch. It's like trying to teach you how to write a poem when you can't write a sentence.

Learning scripting without programming knowledge isn't something you can do it in a day.

Your code is completely broken and you are mixing things. it doesn't matter what language you learn, but first learn a few basic things like if, else, for loop, etc. and stick with them until you feel familiar with the language. You can do a lot of things with only that. The next step is learn the sdk, try to understand the OM structure, and keep improving your scripting skills with functions and other fancy things.

Specific shaders don't have a ClassID. I mean, the class is shaders so you can't filter "lambert" with that. I would use ProgID.

Code: Select all

//JScript
var exception = "phong"		//specify unwanted shader
var obj = selection(0)		//get selected object
var mats = obj.materials	//get all mats from your selected object

//create a recipient for your result
var oColl = XSIFactory.CreateObject( "XSI.Collection" );

//loop your mats
for (var i=0; i<mats.count ; i++){
	// loop your mats' shaders
	var shaders = mats(i).GetAllShaders()
	for (var j=0; j<shaders.count ; j ++){
		// compare your shaders with your unwanted shader name
		if (shaders(j).progid.indexOf(exception) == -1) oColl.Add(mats(i))
	}
}

//select your filtered mats collection
selectobj (oColl)
Its looping inside a loop so it may not be very fast (although I doubt you have millions of shaders and materials), but it works and i wrote it using, for loop, if and indexOf.

So first, learn the basic stuff, read until you understand it before trying to do complex things. Step by step.

if you can't make a simple logmessage work, then you are not ready to walk through your material shaders.
I change the shader name in the variable "exception" to the ProgID of the shader I want to search for. I select the model which contains all the objects and their materials that I want to look for the ProgID of the shader, and check if each of the objects, materials within the model contain the ProgID that I put in the variable "exception" then tell me whether the shader is connected to the material, not connected to the material, or needs to be connected. When I run the script, the scripts log is; SelectObj("", null, null);. Not the information I want.

I can make a logMessage work, I can create a Implicit and MeshSurface, I think there is another thing. I can create a function that creates a loop, that would create a MeshSurface that would log what type of MeshSurface was created ! :) I still fight with the SDK :(

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

Re: Materials without Shader Node

Post by myara » 30 Jul 2013, 15:57

Read the code. I took the work to write some comments too, so read them.

If you read the code you'll know it doesn't look for any children objs inside a Model, you'll know that it only works with the current selected object. If your current selection isn't an object with materials assigned, then obviously, it won't work.

If you want to make it search for children inside your model, well, it's your homework.
The easiest way is to use, FindChildren() and then loop through them.
M.Yara
Character Modeler | Softimage Generalist (sort of)

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

Re: Materials without Shader Node

Post by csaez » 30 Jul 2013, 20:24

@Falam:
Please don't quote large posts unless you want to reference a specific sentence, a simple @username works perfectly and keeps the forum readable.
Thank you

Falam

Re: Materials without Shader Node

Post by Falam » 31 Jul 2013, 04:00

I scratched up the basic of the script, modifying what myara posted.

Code: Select all

//JScript
var exception = "Softimage.BA_color_switcher.1.0"      //specify unwanted shader
var obj = selection(0)      //get selected object
var model = PickElement("model","select a model");
var findobjects = FindObjects(model, // I didn't close the command, how do search all objects materials within a model ? 
var selectshadernode = PickElement ("shader"); //Select the Shader node I want to find 
LogMessage (""); // Which objects within the model have the shader connected from the variable "selectshadernode".



//create a recipient for your result
var oColl = XSIFactory.CreateObject( "XSI.Collection" );

//loop your mats
for (var i=0; i<mats.count ; i++){
   // loop your mats' shaders
   var shaders = mats(i).GetAllShaders()
   for (var j=0; j<shaders.count ; j ++){
      // compare your shaders with your unwanted shader name
      if (shaders(j).progid.indexOf(exception) == -1) oColl.Add(mats(i))
   }
}

//select your filtered mats collection
selectobj (oColl)

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests