Surface Selection Script
Szark
Posts: 10,634
Before I ask my question I would like to state that I have no idea how to make script or where to even start.
Can a script be made to select all surfaces with a particular named texture map or via material ID colour. This could be for surfaces that cannot be selected via the normal methods easily, say a light bulb in a shade, multiples of. Yes there is a reason I would like to know how or if it is even possible.
If it is possible would anyone like to help me achieve this.
Comments
I'm not sure if it's what you are asking for, but if you have the surface selection tool active and you right click on (for example) your characters arms, you get lots of selection options.
Cheers yes I am well aware of what tools and what functions we have in DS, been using it for over 6 years now, but thank you anyway. For that to work one needs to be able to select the surface first. The thing is not all surfaces can be accessed via the surface selection tool if the surface is blocked by another, in this case a light shade. To do so is to select the closet surface and use the Frame function and then manaully position the camera so the surface can be seelcted.
What I would like to offer is an easy way for say Light Bulbs to be selected in one go via a script using material ID or a named texture map. Ideally I would like to be able to do both. This is so a Light On preset can be applied without the need to jump though hoops to select a hidden surface.
ok, I follow you now, that would be handy to have.I can think of a few times something like that would have saved me much clicking.
Yes, its possible.
-Rob
well that is a good start. Do you have time to help Rob?
It looks like DzMaterial has a select(bool) method. So, you could iterate through all DzNodes to DzShapes to DzMaterials, look for the attribute you want, then set selected on the material to true.
Actually, reading further, it looks like you can iterate directly over DzMaterials without knowing what owns them. DzMaterial has two static methods, getNumMaterials() and getMaterial(int).
Esemwy I have no experience in scripting or coding at all, never, so all that great info went straight over me head.
I also had a thought that the script needs to be either by surface name (that appears in the Surface Pane) and/or Material ID. The sets I am working on can have different texture maps for the same light bulbs or the same map but different node names. It would have been great if I we could select a surface in the Surface Pane and then have the option of choosing all mats with the same Mat ID but alas we can't.
I will need it so I can change the surface name or Mat ID myself for each project.
I think I can help you out. You'd have to be specific about what criteria you want to select on. Selecting on surface name is easy. Mat ID takes a couple more steps.
Oh sweet thanks, man I really appreciate this Esemwy. We can leave at surface name and if there are more than one name I can make mulitple presets to suit each set.
First off I gather the surface name would go where "SsecretSurface" is?
and secondly how do I turn that coding in to a DS preset?
Just one other thing I just thought of, if possible, could this be extended to call up a Material Preset and load that material to the selected surface name. So in my case Turn the light bulb into a Emissive Surface as that is what I would be using it for. So instead of using the script to select and then load the mat preset can it be done in one go. No problem if it can't of if is too much work. I know I am being cheeky but hey if you don't ask. LOL
Ok, if using the surface name is sufficient, I'll finish it off here. Just copy and paste the script into a .dsa file like "SelectLights.dsa" and put it wherever you need it. Create the 91x91 icon however you usually do.
In answer to your last question, it's probably possible, but I don't know it off the top of my head. I'm willing to look into it, but it'll have to be in the morning.
Oh Esemwy thanks again. And please don't rush on my account. I gather I can do all this in Notepad and save it as a name of my choosing. I am off to bed myself. Nearly 5 am here and I better get some sleep.
Yep, notepad works. You can also paste it into the Script IDE in DAZ and save it from there. It's just a regular text file. Only the .dsa extension is important.
yeah sweet I got you on the dsa part too. Thanks again for taking the time to help this scripting dummy.
Esemwy I did more thinking on this and it might be best to leave at this. Just so people can select the named surfaces again and adjust the light settings.
You're quite welcome. I practically had it already written. I did something similar a month or so back.
Makes sense to stop where we are. I think I learned how to apply a preset, and I'll probably test it out of curiosity, so let me know if you decide you need it. I did find a small bug in my sleep though (happens more often than you'd think).
Where the script says:
Should say:
Otherwise, any surfaces that the user already has selected will also be in the selection when the script is done.
Ok cheers. I have added that now.
where it says "// Change surface name here" is there any formatting that needs doing or just plain text?
Personally I think it would be better just to select and not load a mat preset. Then it remains flexible.
Can you do me one little favour please and post the whole script as Notepad is throwing up some issues.
The // line is just a comment. It's meant to refer to the line below.
Here's a link to the file to save you the copy and paste.
Now that I'm not so sleepy, I think you may have to do edits in WordPad instead of Notepad. Notepad will probably throw the entire script onto a single line.
In case you need it later. You can drop this at the end of the file. It applies the Emission shader to the selected surfaces.
Okey pokey so do I need to remove the line "// Change surface name here". So "SecretSurface" that is where I enter the surface name, cool. Oh yeah notepad keeps the formatting but to make sure I am going to use the Script IDE in DS.
I will test this script tomorrow as the PC is tied up today so I will let you know how I get on. This is going to make life easy for others to load a pre-made mat preset.
DAZScript will ignore the // line. That's what the // is for, so that we can put human readable text amid all the gibberish.
Oh that is cool.
Connection issues and other priorities prevented me from responding again last night; my first response was made while standing on a moving train, on my way home from the office. Although I see that @Esemwy was able to help, I'll offer an alternate solution (see the Select By Tag sample) that uses the "Tags" property on materials to determine whether or not to select. This solution is a bit more like the "Select Surfaces with the Tag(s)..." option that is available from the viewport context menu when the Surface Selection Tool is active and you right-click on a surface that has a value in its "Tags" property. You'll notice that the main function provides a few options that allow you to change how it operates.
-Rob
No problem Rob and thanks even more knowing that. :) I like selecting via Surface name as it is one less step to worry about. But Taging could be an alternative soloution. So which one of thise examples would work for what I want to do. Just in case I need to expand across different surface names?
Rob's is certainly comprehensive, and tags are a bit more elegant than surface names. You could either use his as shown, or I can update mine to use tags if you prefer.
Esemwy as I don't know which of Rob's examples to use could you do a Tag one too, if isn't any trouble. And please don't rush.
I added some of Rob's optimizations and cleaned up a bit.
Download here
LOL I love the EDIT Here bit....that's what I like idiot proof. a BIG THANK YOU Esemwy for doing this for me and for the ones that will benifit from the ease of use in the future. Anytime you need my help just shout, if I can I will or at least try.