easily adaptable script to select a list of surface materials

mCasualmCasual Posts: 4,607
edited November 2015 in Freebies

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
«1

Comments

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    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! :-)

  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    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.

  • mCasualmCasual Posts: 4,607
    edited December 1969

    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

  • Three WishesThree Wishes Posts: 471
    edited December 1969

    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!

  • MorganRLewisMorganRLewis Posts: 233
    edited December 1969

    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.

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    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!

  • mCasualmCasual Posts: 4,607
    edited December 1969

    RAMWolff said:
    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

  • RAMWolffRAMWolff Posts: 10,212
    edited November 2015

    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:

     

    Error in script execution: F:/Users/RAMWorks/My Documents/DAZ 3D/Studio/My Library/People/Dusk/Clothing/RAMWorks/SupersSuit Set/Utilities/SuperSuit-SuitSelection.dsaWARNING: QAccessibleWidget::rect: This implementation does not support subelements! (ID 20 unknown for QWidget)Loading script: F:/Users/RAMWorks/My Documents/DAZ 3D/Studio/My Library/People/Dusk/Clothing/RAMWorks/SupersSuit Set/Utilities/SuperSuit-SuitSelection.dsaWARNING: Script Error: Line 6WARNING: SyntaxError: Parse errorWARNING: Stack Trace: ()@:6

     

    Here is what the script looks like after I was done:

     

    // DAZ Studio version 3.1  filetype DAZ Scriptvar matNames = [  "Belt-Border",  "BeltBuckle"  "BeltLoops" "CollarLower" "CollarMid" "CollarUpper-Cent" "Pant_KneeLow" "Pant_KneeLow_Cuff" "Pant_KneeUp_Cuff" "Pant_KneeUpper" "Pant_Shin" "Pant_ShinUpper" "Pant_ShinUpper_Cuff" "Pant_ShortsLong" "Pant_ShortsLong_Cuff" "Pant_ShortsMid" "Pant_ShortsMid_Cuff" "Shirt_Long01_Cuff" "Shirt_LongSleeve" "Shirt_MidCuff" "Shirt_MidLong_Cuff" "Shirt_MidLongSleeve" "Shirt_MidSleeve" "Shirt_Muscle_Cuff" "Shirt_MuscleSleeve" "Shirt_Short_Cuff" "Shirt_ShortSleeve" "Shorts" "Shorts_Cuff" "Tank" "Tank-Seam"];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 version 4.0 and up,    //the skeleton owns the DzObject      //the DzObject owns the shape   //the shape owns all the figure's materials   nodelist = [skel];   }  else  {   //with version 1, 2, 3   //each bone owns a DzObject   //each DzObject owns a shape   //each shape owns some or all the material figures   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 adifferent 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
  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    You need commas after the material names (except the very last one), as with the first in your array.

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    **Bangs head against the desk** thanks Richard! :-/

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    Holy Crap Batman, it works! YAY!

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    Oh and Casual, can you whip up a script to INVERT surface selection by any chance??

  • mCasualmCasual Posts: 4,607
    edited December 1969

    RAMWolff said:
    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?

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    Casual said:
    RAMWolff said:
    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?

    Just thinking about for general surface selection regardless of the surfaces....

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    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!

  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    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).

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    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

    var matNames = [ ];

    with

    mat.select( ! mat.isSelected() );
    ??
  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    Also trying to figure out to make a "Deselect" script with this.

    I just typed in:

    var matNames = [ deselect,
    
    ];

    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!

  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    RAMWolff said:
    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

    var matNames = [ ];

    with

    mat.select( ! mat.isSelected() );
    ??

    You would replace

       for( var j = 0; j < nMats; j++ )
       {
        var mat = shp.getMaterial( j );
        if( matNames.find( mat.name ) >= 0 )
        {
         bFoundSomeMatches = true;
         mat.select( true );
        }
       }

    with

       for( var j = 0; j < nMats; j++ )
       {
        var mat = shp.getMaterial( j );
        mat.select( ! mat.isSelected() );
       }

    (I think, not tested).

  • RAMWolffRAMWolff Posts: 10,212
    edited March 2015

    I take it the

    for(
    is to be left off? I don't see anything in the current script that Casual posted that has a
    for( 
    mentioned in it. So this is confusing me. Sorry for being a pita....
    Post edited by RAMWolff on
  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    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).

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    AH, NOW I see it. I must have been more tired than I thought last night. Sorry Richard.

  • RAMWolffRAMWolff Posts: 10,212
    edited November 2015

    OK. not working. Here is the altered script in it's entirety to look over.

     

    // DAZ Studio version 3.1  filetype DAZ Scriptvar matNames = [  &quot;Belt-Center&quot;,  &quot;BeltBuckle-Cent&quot;,  &quot;Blend-KneeLow&quot;, &quot;Blend-KneeUp&quot;, &quot;Blend-ShinLower&quot;, &quot;Blend-ShinUpper&quot;, &quot;Blend-ShortsCuff&quot;, &quot;Blend-ShortsLong&quot;, &quot;Blend-ShortsMid&quot;, &quot;CollarLower-Seam&quot;, &quot;CollarMid-Seam&quot;, &quot;CollarUpper&quot;, &quot;CollarUpper-Seam&quot;, &quot;Pant_ShinLower_Cuff&quot;, &quot;Pant_SideSeam&quot;, &quot;Shirt_Long02_Cuff&quot;, &quot;Shirt_Side_Strip&quot;, &quot;Shorts-Zipper&quot;, &quot;Shorts_Seams&quot;, &quot;Tank-FrontSeam&quot;, &quot;Tank-Seam&quot;, &quot;Tank_Cuff&quot;];var DSVersion = new Number( App.versionString );var skel = Scene.getPrimarySelection();//we&#39;ll detect users attempting to apply this script to the wrong figurevar bFoundSomeMatches = false; if( skel ){ if( skel.inherits( &quot;DzBone&quot; ) ) {  skel = skel.getSkeleton(); } if( skel.inherits( &quot;DzSkeleton&quot; ) ) {  var nodelist;  if( DSVersion &gt;= 4.0 )  {   //with version 4.0 and up,    //the skeleton owns the DzObject      //the DzObject owns the shape   //the shape owns all the figure&#39;s materials   nodelist = [skel];   }  else  {   //with version 1, 2, 3   //each bone owns a DzObject   //each DzObject owns a shape   //each shape owns some or all the material figures   nodelist = skel.getAllBones()  }  var nNodes = nodelist.length;  for( var i = 0; i &lt; nNodes; i++ )  {   var obj = nodelist[ i ].getObject();   var shp = obj.getCurrentShape();   var nMats = shp.getNumMaterials();   for( var j = 0; j &lt; nMats; j++ )   {    var mat = shp.getMaterial( j );    mat.select( ! mat.isSelected() );    }   }  }  if( !bFoundSomeMatches )  {    MessageBox.information(      &quot;This script was designed\n&quot;     +&quot; for adifferent figure than\n&quot;     +&quot; the one you selected.&quot;,      &quot;Problem&quot;,      &quot;&amp;OK;&quot;     );} } else {  MessageBox.information( &quot;Please select a figure.&quot;, &quot;Problem&quot;, &quot;&amp;OK;&quot; ); }}else{  MessageBox.information( &quot;Please select a figure.&quot;, &quot;Problem&quot;, &quot;&amp;OK;&quot; );}

     

    Post edited by Richard Haseltine on
  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    How is it not working - an error, an undesired result or simply nothing?

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    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?

  • Richard HaseltineRichard Haseltine Posts: 100,941
    edited December 1969

    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.

  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    Hmmm, I didn't touch those though. So that's odd.

  • mCasualmCasual Posts: 4,607
    edited December 1969

    RAMWolff said:
    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

  • mCasualmCasual Posts: 4,607
    edited November 2015

    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

     

    var DSVersion = new Number( App.versionString );var skel = Scene.getPrimarySelection();//we&#39;ll detect users attempting to apply this script to the wrong figureif( skel ){ if( skel.inherits( &quot;DzBone&quot; ) ) {  skel = skel.getSkeleton(); } var nodelist; if( skel.inherits( &quot;DzSkeleton&quot; ) ) {  if( DSVersion &gt;= 4.0 )  {   //with version 4.0 and up,    //the skeleton owns the DzObject      //the DzObject owns the shape   //the shape owns all the figure&#39;s materials   nodelist = [skel];   } else  {   //with version 1, 2, 3   //each bone owns a DzObject   //each DzObject owns a shape   //each shape owns some or all the material figures   nodelist = skel.getAllBones()  }  var nNodes = nodelist.length;  for( var i = 0; i &lt; nNodes; i++ )  {   var obj = nodelist[ i ].getObject();   var shp = obj.getCurrentShape();   var nMats = shp.getNumMaterials();   for( var j = 0; j &lt; nMats; j++ )   {    var mat = shp.getMaterial( j );    var sel = mat.isSelected();    mat.select( !sel );   }  } } else {  MessageBox.information( &quot;Please select a figure.&quot;, &quot;Problem&quot;, &quot;&amp;OK;&quot; ); }} else {  MessageBox.information( &quot;Please select a figure.&quot;, &quot;Problem&quot;, &quot;&amp;OK;&quot; ); }

     

    arrgh now my delete key doesnt work in ds4.7 ... unless ...

    plink.jpg
    758 x 570 - 105K
    Post edited by Richard Haseltine on
  • RAMWolffRAMWolff Posts: 10,212
    edited December 1969

    I was wondering what happened to you Casual. I'll give your script a try and see what happens..

Sign In or Register to comment.