[Closed] [solved] On Button pressed do Multi_Random_fn1,,fn2,fn3
Hi, thanks for the code, it works great.
My problem is that my knowledge is small. I studied something, reworked the whole code structure so that the “fn” were together and then just called them.
I don’t know where to place it (fn f1 = format “1 / n” etc …) but it works without it.
If I ever ask myself as a primitive, sorry.
But when I reworked everything, I rewrote the new code with the old code and lost part, and I don’t know what was already there. Any idea?
This is the line $ .modifiers [#VRayDisplacementMod] .texmap = ???
I need them to add early maps from the listbox.
on lml2 pressed do
(
----- loading from matlibrary --------
prevmlfn = getMatLibFileName()
mlfn = getMatLibFileName()
ff = true
if chk1d.state == false then
(
fileOpenMatLib()
mlfn = getMatLibFileName()
if prevmlfn == mlfn and matarrayd.count != 0 then ff = false
)
if ff == true then
(
try
(
matarrayd = #()
loadMaterialLibrary mlfn
for m in currentMaterialLibrary do
(
--if superclassof m == material then
if superclassof m == textureMap then
(
arrentity = #(m,100)
append matarrayd arrentity
refreshlistd()
)
)
--loadMaterialLibrary prevmlfn
if lbx1d.items.count != 0 then
(
lbx1d.selection = 1
lbselectedd 1
)
else (lbselectedd 0)
)
catch
(
)
)
)
on rnd pressed do
(
macros.run "Modifier Stack" "Convert_to_Poly"
modPanel.addModToSelection (VRayDisplacementMod ()) ui:on
$.modifiers[#VRayDisplacementMod].keepContinuity = on
$.modifiers[#VRayDisplacementMod].texmap = ------------------------------------???????
$.modifiers[#VRayDisplacementMod].amount = spn_1a.value
$.modifiers[#VRayDisplacementMod].shift = spn_2a.value
--- defining range
sc = 0
for m in matarrayd do sc = sc + m[2]
--- random function in range
--- defining the hit in range
for o in selection do
(
r = random 0.0 sc
trg = true
tmpm = undefined
s = 0
for m in matarrayd do
(
s = s + m[2] -- greater limit
if r <= s then
(
if trg then
(
--print m[1].name
tmpm = m[1]
)
trg = false
)
) -- end for matarray
try
(
o.material = tmpm
o.material.showInViewport = true
)
catch()
) -- end for selection
)
it fully depends what’s inside your listbox, it could or example contain filename or full path to texture
$ .modifiers [#VRayDisplacementMod] .texmap = Bitmaptexture filename:( your_listbox_control.items[ your_listbox_control.selection ] )
or if you want some procedurals
$ .modifiers [#VRayDisplacementMod] .texmap = Checker()
I see only filename. Your first variant work great, i have a lot of textures and i need random add. I think before that I had a function that worked for me, it was quite simply “= m ()” or “= m [1]” or something like that.
I finally solved it this way
$.modifiers[#VRayDisplacementMod].texmap = Bitmaptexture filename:( lbx1d.items [lbx1d.selection + (random 0 spn_limitmax.value )] )
I have to always set “spn”, does anyone have an idea all random from listbox automatic?
Only now have I come to full testing. My current problem is that only the name is written to the modfier.texmap section, but the file is empty, the foreign map is not loaded.
on lml2 pressed do
(
—– loading from matlibrary ——–prevmlfn = getMatLibFileName() mlfn = getMatLibFileName() ff = true if chk1d.state == false then ( fileOpenMatLib() mlfn = getMatLibFileName() if prevmlfn == mlfn and matarrayd.count != 0 then ff = false ) if ff == true then ( try ( matarrayd = #() loadMaterialLibrary mlfn for m in currentMaterialLibrary do ( --if superclassof m == material then if superclassof m == textureMap then ( arrentity = #(m,100) append matarrayd arrentity refreshlistd() ) ) --loadMaterialLibrary prevmlfn if lbx1d.items.count != 0 then ( lbx1d.selection = 1 lbselectedd 1 ) else (lbselectedd 0) ) catch ( ) ) )
this is my schematic for loading materials into a multilistbox.