Surface Selection Script

2

Comments

  • EsemwyEsemwy Posts: 578

    Glad to be of service.wink

  • SzarkSzark Posts: 10,634

    I haven't had a chance to test these yet but I should be doing so tomorrow.

  • SzarkSzark Posts: 10,634

    Well I finally got around to testing this and it works great, both do, thank you.  All went without a hitch but for one minor issue, the surfaces don't appear in the surfaces pane selected. To show them in the surfaces pane one has to select the node in the scene pane. But I did want to avoid that which was the main basis for the script. Would/is there a way for them to show up in the surfaces pane after the script has run? I must stress that it will do if the last question isn't possible as it serves part of the purpose but it would be nice for customers to have them showing in the surfaces pane automatically for fine tuning.

  • EsemwyEsemwy Posts: 578

    I guess it would be possible to select the corresponding node when the surface gets selected. I think that would do it. I can't think of any other way off the top of my head. 

  • Szark said:

    Well I finally got around to testing this and it works great, both do, thank you.  All went without a hitch but for one minor issue, the surfaces don't appear in the surfaces pane selected. To show them in the surfaces pane one has to select the node in the scene pane. But I did want to avoid that which was the main basis for the script. Would/is there a way for them to show up in the surfaces pane after the script has run? I must stress that it will do if the last question isn't possible as it serves part of the purpose but it would be nice for customers to have them showing in the surfaces pane automatically for fine tuning.

    The Surface pane option menu - lined button in the top corner or right-click the tab - should give three show options, one of which is everything; select that.

  • SzarkSzark Posts: 10,634

    Yeah that should work as when all the nodes were selected manually after the script had been run, the surfaces were expanded and all surfaces with that tag or name were available for editing so with what you have said above that sounds like what is needed.

    I do realize though that by doing so I am restricting the script by constraining it to look for just one common node name but in some circumstances that will be perfect. But they are both still usable for just applying an Emissive light preset so for that they work great.

    Can I be cheeky, if does take to much of your time, and have a script to just select named nodes by themselves. Saying no isn't as issue for me at all. Ast my old pa used to say "you don't get anything without asking".That way I could do all the jobs needed. The tagged script could be used to load a mat preset across different named nodes and surfaces and the node script to select a portion of those multiple named nodes. In some cases the customer might want adjust a section of lighting and leave the others alone, in their preset default state. It's all about ease of selecting a lot of surfaces or nodes quickly.

  • SzarkSzark Posts: 10,634
    Szark said:

    Well I finally got around to testing this and it works great, both do, thank you.  All went without a hitch but for one minor issue, the surfaces don't appear in the surfaces pane selected. To show them in the surfaces pane one has to select the node in the scene pane. But I did want to avoid that which was the main basis for the script. Would/is there a way for them to show up in the surfaces pane after the script has run? I must stress that it will do if the last question isn't possible as it serves part of the purpose but it would be nice for customers to have them showing in the surfaces pane automatically for fine tuning.

    The Surface pane option menu - lined button in the top corner or right-click the tab - should give three show options, one of which is everything; select that.

    yeah they will only show up with "Display All Itens". The other two don't show any nodes when the script has been run. I should have added that as I did test that, thanks Richard.

  • EsemwyEsemwy Posts: 578

    I'm not sure what you mean. Do you mean select by tag for selected nodes? If so, I already have that written, but need to test it more.

    Szark said:

    Can I be cheeky, if does take to much of your time, and have a script to just select named nodes by themselves. Saying no isn't as issue for me at all. Ast my old pa used to say "you don't get anything without asking".That way I could do all the jobs needed. The tagged script could be used to load a mat preset across different named nodes and surfaces and the node script to select a portion of those multiple named nodes. In some cases the customer might want adjust a section of lighting and leave the others alone, in their preset default state. It's all about ease of selecting a lot of surfaces or nodes quickly.

     

  • rbtwhizrbtwhiz Posts: 2,267
    edited September 2015

    You do realize that the Select By Tag sample I posted already handles node selection, correct?  It even provides options for whether or not to synchronize node and/or surface selection; i.e. whether or not to drop selection of nodes and/or surfaces that do not have the specified tag.

    -Rob

    Post edited by rbtwhiz on
  • EsemwyEsemwy Posts: 578
    rbtwhiz said:

    You do realize that the Select By Tag sample I posted already handles node selection, correct?  It even provides options for whether or not to synchronize node and/or surface selection; i.e. whether or not to drop selection of nodes and/or surfaces that do not have the specified tag.

    -Rob

    Yes, I am aware. I produced a simpler script that did only one job.

  • SzarkSzark Posts: 10,634
    edited September 2015
    Esemwy said:

    I'm not sure what you mean. Do you mean select by tag for selected nodes? If so, I already have that written, but need to test it more.

    Szark said:

    Can I be cheeky, if does take to much of your time, and have a script to just select named nodes by themselves. Saying no isn't as issue for me at all. Ast my old pa used to say "you don't get anything without asking".That way I could do all the jobs needed. The tagged script could be used to load a mat preset across different named nodes and surfaces and the node script to select a portion of those multiple named nodes. In some cases the customer might want adjust a section of lighting and leave the others alone, in their preset default state. It's all about ease of selecting a lot of surfaces or nodes quickly.

     

    Well some surfaces have the same settings which can be across different named nodes. I was assuming you can't do multiple nodes if the names are different. To clarify. Some light bulbs can be spread over different nodes that have different names. So if I am right about the last sentence in this reply then I would need a script that just selects nodes of the same name, period.

    Post edited by Szark on
  • SzarkSzark Posts: 10,634
    rbtwhiz said:

    You do realize that the Select By Tag sample I posted already handles node selection, correct?  It even provides options for whether or not to synchronize node and/or surface selection; i.e. whether or not to drop selection of nodes and/or surfaces that do not have the specified tag.

    -Rob

    Rob if that was aimed at me then it fell of deaf eyes as I have no idea what I am looking at or which to choose.  :) But thanks for popping in.

  • EsemwyEsemwy Posts: 578
    edited September 2015

    Rob and I both have scripts with the ability to select by any criteria you would like. The script can select all materials with a particular tag across the entire scene, or it can select only the materials with a tag from selected node(s). I've been testing against i13 Modern Loft since it has heirarchies of both nodes and surfaces. What I wanted to be able to do is select all the "Emissive" materials in a given part of the loft.

    I assume you still want to select by tag. I believe that's more appropriate than selecting by name. That way (using the lighting example) the surface name can be "flame," "filament," or "tube," while the material is tagged "Emissive," or "Light."

    This script traverses the heirarchy of the currently selected nodes and selects all the surfaces with the specificied tag. It also selects the node for the newly selected surface such that the selections are displayed properly in he surface pane.

    If you start off with the scene selected like this,

    then run the script, you end up with your scene like this,

    and your surfaces tab like this.

    Is this what you're after, or something else?

    scene-initial.jpg
    234 x 251 - 28K
    scene-result.jpg
    276 x 351 - 42K
    surfaces-result.jpg
    145 x 727 - 49K
    Post edited by Esemwy on
  • SzarkSzark Posts: 10,634

    Sorry been watching the Rugby World Cup.

    Yeah from what I can make out I would say that is what I would like very much. Just so we are on the same page the last scripts didn't need anything selected in the scene before hand I assume this will still be the case? if it is then YES your example is ideal.

  • EsemwyEsemwy Posts: 578

    OK, I've got two separate scripts:

    SelectSurfacesByTag.dsa

    SelectSurfaceByTagForNodes.dsa

    The first selects all surfaces in the scene with a given tag. The second selects surfaces only from nodes (and their children) that are selected in the scene tab. Both of them display the selected surfaces in the surfaces tab when they're done.

  • SzarkSzark Posts: 10,634

    Oh cool thank you I will give them a test and report back. I think the first one is more what I require as I don't really want to have to select anything in the scene prior to running the script. I appreciate this very much Esemwy.

  • SzarkSzark Posts: 10,634

    Esemwy thank you for you efforts that latest Tag script works a treat.

  • Ivo ShandorIvo Shandor Posts: 74
    edited October 2015

    I needed a version of the seach-surface-by-name script in this thread. I didn't want to go through tags as I am thinking of converting "Urban Sprawl 2" by Stonemason over to Iray: http://www.daz3d.com/urban-sprawl-2-the-big-city

    Many of the surfaces are named "WindowE", "WindowA", WindowE1" and all sorts of surfaces that are all the same texture but contain the keyword "Window" in their surface name. So I needed all partial matches. This script below is an edit of that original script in this thread to do a partial match. I just put it into the Script IDE window and hit execute to select all of the partial matches.

     

    // Change surface name here	var searchTerm = "Window";var nNodes = Scene.getNumNodes();for (var i=0; i < nNodes; i++) {	var oNode = Scene.getNode(i)	var oObj = oNode.getObject();	if (! oObj) continue;	var nShapes = oObj.getNumShapes();	for (var j=0; j < nShapes; j++) {		var oShape = oObj.getShape(j);		var nMat = oShape.getNumMaterials();		for (var k=0; k < nMat; k++) {			var oMat = oShape.getMaterial(k);			var sName = oMat.getName();								if (sName.search(searchTerm) != -1) {				oMat.select(true);			}		}	}}

     

    Post edited by Ivo Shandor on
  • SzarkSzark Posts: 10,634
    edited March 2016

    does anyone if I can merge this Clear Selection Script 

    // Get list of nodesvar selectedItems = Scene.getSelectedNodeList();// go through deselectingfor ( var n = 0 ; n < selectedItems.length ; n++ ) {	selectedItems[ n ].select( false );}

    with the Tag selection script so when the script is executed the script will clear whatever is selected prior and then select the surfaces with the given tag.  

    Post edited by Szark on
  • EsemwyEsemwy Posts: 578

    That'll clear your selected nodes, but not necessarily selected surfaces. I can gen up something this evening (GMT-5), when I get home, if you can wait. If you look at Rob's script above, the function getMaterialForStatic will get the first material, then you can get the selected materials and unselect them like you do with the nodes in hour example. 

  • SzarkSzark Posts: 10,634

    Like with all my requests for help there is never any rush. LOL 

     

    Esemwy that would be awesome. All I need is for the script to unselected any nodes that have been selected before engaging the Tag selection script. As I have it now the customer will have to run the Clear Selection script before running the tag selection script and I would like them both in one script if possible.

  • EsemwyEsemwy Posts: 578
    edited March 2016

    OK, I think this is what you need. I added an explicit unselect of all the nodes in the tag selection function. It was a one line change. This makes sure that only the nodes and surfaces of the current tag are selected.

    // DAZ Studio version 4.9.1.30 filetype DAZ Scriptfunction selectSurfaceByTag(sSelectedTag) {    var nSelected = Scene.getNumNodes();    for (var i=0; i < nSelected; i++) {        var oNode = Scene.getNode(i);        oNode.select(false);        var oObj = oNode.getObject();        if ( ! oObj ) continue;        var nShapes = oObj.getNumShapes();        for (var j = 0; j < nShapes; j++) {            oShape = oObj.getShape(j);            if (! oShape ) continue;            var nMats = oShape.getNumMaterials();            for (var k = 0; k < nMats; k++) {                var oMaterial = oShape.getMaterial(k);                if ( ! oMaterial ) continue;                var aTags = oMaterial.getTags();                if ( aTags.indexOf( sSelectedTag ) >= 0 ){                    oMaterial.select( true );                    oNode.select(true);                }                else {                    oMaterial.select( false );                }            }        }    }}/****************** EDIT HERE *******************///                      |//                      VselectSurfaceByTag("Light");

    If you want to unselect everything, this one will do the job.

    // DAZ Studio version 4.9.1.30 filetype DAZ Scriptfunction unselectAll() {    var nSelected = Scene.getNumNodes();    for (var i=0; i < nSelected; i++) {        var oNode = Scene.getNode(i);        oNode.select(false);        var oObj = oNode.getObject();        if ( ! oObj ) continue;        var nShapes = oObj.getNumShapes();        for (var j = 0; j < nShapes; j++) {            oShape = oObj.getShape(j);            if (! oShape ) continue;            var nMats = oShape.getNumMaterials();            for (var k = 0; k < nMats; k++) {                var oMaterial = oShape.getMaterial(k);                if ( ! oMaterial ) continue;                oMaterial.select( false );            }        }    }}//***************** UNSELECT  *******************/unselectAll();

    The second one is entirely unnecessary if you're just going to run the first one afterward, but I thought it might be useful.

    Post edited by Esemwy on
  • V3DigitimesV3Digitimes Posts: 3,172

    Personally I'm using :

    var oCurrentScene = Scene;oCurrentScene.selectAllNodes(false);oCurrentScene.selectAllSkeletons(false);

     

    For my use this is enough, I never needed more. But it does not unselect previously selected materials. Just the nodes.

  • SzarkSzark Posts: 10,634
    edited March 2016

    Esemwy thanks again. I will test the first one out tonight. Yeah I don't think I will need the latter but I will keep it just in case.

    The reason why I would like other nodes and surfaces deselected first is so when poeple use the script they have the right surfaces selected to be  adjusted to thier desired taste. All without the need to Clear selection first which has no predifined shortcut. I made one myself for my UI.

    Post edited by Szark on
  • SzarkSzark Posts: 10,634

    Well Esemwy you nailed that. A big wam hearted thanks for that. Works perfectly and all the scripts have been updated. This will make it so easy to select hidden or obscured surface zones.

  • ooofestooofest Posts: 36
    edited January 2019

    I realize that this is an old topic, but am curious if any of the scripts previously linked by Esemwy might possibly exist somewhere, please.

     

    Am new to Daz scripting and was hoping to experiment with a script that looks through the surfaces of all objects in a scene, identifying which ones have Iray emissive nodes.  These scripts sound like a good base from which to start.

    Post edited by ooofest on
  • EsemwyEsemwy Posts: 578

    I’ve got a script. It needs some work, but is generally useful for what you want. 

    dsa
    dsa
    searchsurfaces.dsa
    6K
    searchsurfaces.dsa.png
    91 x 91 - 4K
  • ooofestooofest Posts: 36
    Esemwy said:

    I’ve got a script. It needs some work, but is generally useful for what you want.

    Thank you Esemwy !

  • TotteTotte Posts: 14,013

    I stumbled upon this thread trying to figure out why DzMaterial.select(false) doesnt work?

    It says isSelected() == false after a select(false) but still selected (I see that in the Surface tab while running the script. Must be a way to unselect the materials, from a script, as select(true) works, but looping through the matrial zones doing select (true) /* stuff */ select (false) just extends the selection.

    Anyone solved this?

  • @Totte

    I cannot reproduce. Does the following not work for you, or do I not understand what you are trying to do?

    (function(){	setBusyCursor();	var oShape = Scene.getPrimarySelection().getObject().getCurrentShape();	oShape.clearMaterialSelection();	for (var i = 0; i < oShape.getNumMaterials(); i++)	{		var oMaterial = oShape.getMaterial(i);		oMaterial.select(true);		sleep (1000);		oMaterial.select(false);	}	clearBusyCursor();})();

     

    dsa
    dsa
    DzMaterial Select Unselect.dsa
    384B
Sign In or Register to comment.