easily adaptable script to select a list of surface materials
following a special request
for users that are not afraid to open a script in notepad.
the script shown here
change the list of material names to suit your needs
save this script under a name like
"AikoHeadScalpMatSelect.dsa"
then select Aiko, run the script, bam, the listed materials are selected
the same code in DSA format can be downloaded here
https://sites.google.com/site/mcasualsdazscripts5/mcjselectthesemats
var matNames = [ "SkinHead", "SkinScalp" ];var DSVersion = new Number( App.versionString );var skel = Scene.getPrimarySelection();//we'll detect users attempting to apply this script to the wrong figurevar bFoundSomeMatches = false; if( skel ){ if( skel.inherits( "DzBone" ) ) { skel = skel.getSkeleton(); } if( skel.inherits( "DzSkeleton" ) ) { var nodelist; if( DSVersion >= 4.0 ) { //with D|S version 4 and up, //the skeleton owns the DzObject //the DzObject owns the shape //the shape owns all the figure's materials nodelist = [skel]; } else { //with D|S version 1, 2, 3 //each bone owns a DzObject //each DzObject owns a shape //each shape owns some or all the figure's materials nodelist = skel.getAllBones() } var nNodes = nodelist.length; for( var i = 0; i < nNodes; i++ ) { var obj = nodelist[ i ].getObject(); var shp = obj.getCurrentShape(); var nMats = shp.getNumMaterials(); for( var j = 0; j < nMats; j++ ) { var mat = shp.getMaterial( j ); if( matNames.find( mat.name ) >= 0 ) { bFoundSomeMatches = true; mat.select( true ); } } } if( !bFoundSomeMatches ) { MessageBox.information( "This script was designed\n" +" for a different figure than\n" +" the one you selected.", "Problem", "&OK;" );} } else { MessageBox.information( "Please select a figure.", "Problem", "&OK;" ); }}else{ MessageBox.information( "Please select a figure.", "Problem", "&OK;" );}
Post edited by Richard Haseltine on
Comments
THANK YOU THANK YOU THANK YOU.
I'm at work right now but I'm going to attack this over the weekend.
Your so fabulous! :-)
I may have questions but again THANK YOU! :-)
The object has belonged to the skeleton since about the second beta of 4.0, so you could probably make your version check >= 4.0. I think the very first beta may have been different, at least for legacy figures.
thanks !
i have DS 1.8. 2.3, 3.1 and 4.7 for testing purposes but i think i had trouble finding/installing 4.0
This is one of those things I don't wish for often, but when I wish I had it, I really wish.
Thank you so much for sharing this!
You know... as many times as I've updated Gen3/Gen4 characters to use subsurface scattering, needing to select a whole mess of surfaces, it's a wonder I never thought of using something like this before. Thank you, Casual, for an idea that'll make certain tasks a lot less tedious.
OK. Questions.
So the script I'd like to make work for just the Supersuit. So do I put that somewhere in there or that's not important?
Can this be saved out as a .duf file. Just worried that perhaps the newer version of DS (what I use) might not like the older dsa format. Or perhaps a future release like DS 5 might not. Just want to make sure that the script continues to work for as long as it can work. I guess if it's also not important I guess the dsa will work as far back to where that format was first introduced (been so long can't remember... I guess DS 4.0?)
Thanks again!
i don't think scripts are ever in .duf format
the idea is to change, in the script, using notepad, the list of material names
to your list of supersuit material names
then you tell your users to select the supersuit node and run the script
if they did select a supersuit node, the script will be able to find the materials by name
and select them
if the user selects anything else the script will display a massage
OK. got all my surfaces for the first script in. Renamed the file to reflect the utility but when I run it, double click it, I get an error message. The suit is selected in the Scene tab. Am I missing something? It's for a suit I'm making for Dusk from Hivewire so not sure if there is something I did or didn't include that's causing this error.
This is from the log file:
Here is what the script looks like after I was done:
You need commas after the material names (except the very last one), as with the first in your array.
**Bangs head against the desk** thanks Richard! :-/
Holy Crap Batman, it works! YAY!
Oh and Casual, can you whip up a script to INVERT surface selection by any chance??
but cant you simply make another script with the other list of materials?
but cant you simply make another script with the other list of materials?
Just thinking about for general surface selection regardless of the surfaces....
OK. Got both scripts set up BUT the scripts don't deselect the previous scripts selection so instead of creating a reversal sort of action by running on script to select a set of surfaces and then running the second script all that happens is that the second script selects the remainder of the surfaces instead of turning off the previously selected surfaces. I guess that's why I was asking for a general InvertSurface sort of script. Just thought you'd appreciate the feedback and perhaps could come up with a simple line of code I could add to the current scripts or write an InvertSurface script.... Gracias for all your great help!
Invert would be
mat.select( ! mat.isSelected() );
going through the list (and not bothering to check names - just do that for every surface on the item).
Hmm, not sure why I didn't get a notice for this.. nothing new! lol
So I would replace the
with
??Also trying to figure out to make a "Deselect" script with this.
I just typed in:
Apparently that's wrong! lol
Part of the need for this aside from the common Invert script is that the current selection script if I click on the first one it does what it's supposed to do but then if I click on the second one to select the seams the other selections are still selected so perhaps there is something I can add to the current scripts to have it deselect the current selection and select what's in the matNames list?
Thanks!
Hmm, not sure why I didn't get a notice for this.. nothing new! lol
So I would replace the
with
??You would replace
with
(I think, not tested).
I take it the
is to be left off? I don't see anything in the current script that Casual posted that has a mentioned in it. So this is confusing me. Sorry for being a pita....The for loop is in Casual's script - it's taking each material on the shape in turn to check against the list of materials (original version) or to simply invert (modified version).
AH, NOW I see it. I must have been more tired than I thought last night. Sorry Richard.
OK. not working. Here is the altered script in it's entirety to look over.
How is it not working - an error, an undesired result or simply nothing?
error but I'm at work now so can't post exactly what it said.
Now, was this to cause the already selected surfaces to be deselected and to select the batch listed at the top of the list?
This toggled the selection of all items on the model, it didn't use the list (though you could fairly easily blend the two).
I get a parse error - you have duplicated the else block at the end, and have one too many closing brackets too.
Hmmm, I didn't touch those though. So that's odd.
bizarre i don't think i got the email about activity on this thread, but i'm subscribed to the thread
there seems to be a DS4 thing going on
if your current tool is the surface selection tool
and you select the clothing item's root node
and you select 1 material
run script shown below
you do-see on-screen that the surface selection gets indeed toggled
BUT if you look in the surfaces tab, you can see the selection is still that 1 initial material
... still studying the problem
arrgh now my delete key doesnt work in ds4.7 ... unless ...
I was wondering what happened to you Casual. I'll give your script a try and see what happens..