Author Topic: Corona Select Map Maxscript  (Read 3797 times)

2019-07-15, 19:07:23

squeakybadger

  • Active Users
  • **
  • Posts: 31
    • View Profile
Hi,

I'm trying to switch out corona bitmaps in the Corona Select Map via maxscript (eventually pulling from an array), but I can't seem to create a new CoronaBitmap for the Select Map with a predefined bitmap already applied, only a blank one.

This is what I have so far, but I can't seem to get the syntax correct.

Code: [Select]
test = CoronaBitmap()
rootScene[#SME][#View1][#hdriHelperSwitcher____CoronaSelect].Properties.reference.texmaps[1] = test.filename = "\\test\test.jpg"

The listener error is:

Code: [Select]
-- Error occurred in anonymous codeblock; filename: ; position: 2155; line: 51
-- MAXScript Rollout Handler Exception:
-- Unknown property: "Properties" in undefined

Any ideas on how to fix it?

Thanks

2019-07-15, 21:00:51
Reply #1

Njen

  • Active Users
  • **
  • Posts: 557
    • View Profile
    • Cyan Eyed
You have three problems. The first problem is that you are incorrectly getting the material though slate, as your code is complaining that the actual material is undefined. The second problem is that you are relying on Slate to access materials in the first place, which you shouldn't do. If you know the name of your material, here is a script that will give you access to that material without relying on Slate or the compact material editor. All you have to do is replace the 'mat_name' variable in the first line with the name of your material.

Then once you run it, you can access the material properties using 'mat', for example 'mat.name'.

Code: [Select]
matName = "sdr_test"
matArrNum = 0
allSceneMaterials = for m in SceneMaterials collect m
for i = 1 to allSceneMaterials.count do
(
if allSceneMaterials[i].name == matName do matArrNum = i
)
mat = allSceneMaterials[matArrNum]

The third problem is that you are assigning too many variables as the same data. You need to break it down a little:
Code: [Select]
test = CoronaBitmap()
test.filename = "\\test\test.jpg"
mat.texmapDiffuse.texmaps[1] = test

[Edit]
I must add that this script relies on a material being applied to at least one object in your scene. I know you are just wanting to access an unconnected map node in Max, but it makes things much easier if you simply assigned this material to a hidden box, or some other simple object, then simply use an instance of the map used in the material any where you like.

« Last Edit: 2019-07-15, 21:38:51 by Njen »

2019-07-16, 08:54:20
Reply #2

Frood

  • Active Users
  • **
  • Posts: 2002
    • View Profile
    • Rakete GmbH
wanting to access an unconnected map node in Max

Yes, in this case you have to walk through all SME views and nodes to find it (by name), right? Needed that recently and could not find a better way.


Good Luck



Never underestimate the power of a well placed level one spell.

2019-07-17, 20:41:59
Reply #3

Njen

  • Active Users
  • **
  • Posts: 557
    • View Profile
    • Cyan Eyed
That's why I assign all "unconnected" maps to a material and then apply that to a hidden box. This is a much easier and simpler way to access all of your materials and maps rather than having to use SME or CME.

2019-07-18, 10:23:23
Reply #4

Frood

  • Active Users
  • **
  • Posts: 2002
    • View Profile
    • Rakete GmbH
Well, it's cumbersome for some scripts/tools if you have to assign any material/map onto any object in the first place. These would be generic functions to get something by name out of the material editors, searched for it but failed to find some quickly enough, so here are mine:

Code: [Select]
-- For SME:
fn getSMEObjectbyName nodename = (
if (nodename != undefined) then (
for i=1 to sme.getNumViews() do (
SMEview = sme.GetView(i)
viewNodeCount = SMEview.GetNumNodes()
for n = 1 to viewNodeCount do (
if ((SMEview.GetNode n).name) == nodename then (
return (trackviewNodes[#sme][i][n].reference)
)
)
)
)
return undefined
)

-- for CME:
fn getCMEObjectbyName objname = (
if (rootScene.Medit_Materials[objname]!=undefined) then return (rootScene.Medit_Materials[objname])
return undefined
)

-- Test:
(
testname="TestMaterialOrMap"
format "In SME: %\n" (getSMEObjectbyName(testname))
format "In CME: %\n" (getCMEObjectbyName(testname))
)


-- @squeakybadger: you may want to do this:
(
testname="hdriHelperSwitcher____CoronaSelect"
NamedMap=(getSMEObjectbyName(testname))

if (classof(NamedMap) == CoronaSelect) then (
print ("Corona Select map named '" + testname + "' found.")
--- inspect the select map:
showproperties NamedMap
--- print the current file path of map in slot 1:
print NamedMap.texmaps[1].filename
-- change the path to something else:
NamedMap.texmaps[1].filename=@"\\test\test.jpg"
) else (
print ("Object " + testname + " is of class '" + classof(NamedMap) as string + "' not 'CoronaSelect'.")
)
)


They do not handle multiple occurrences with the same name atm. but I don't need this most of the time.


Good Luck




Never underestimate the power of a well placed level one spell.