Setting / getting properties using maxscript when some property names are dupes

Setting / getting properties using maxscript when some property names are dupes

chrisell
Contributor Contributor
3,869 Views
19 Replies
Message 1 of 20

Setting / getting properties using maxscript when some property names are dupes

chrisell
Contributor
Contributor

I'm trying to work with an undocumented material plugin.

For each material I can use showproperties to list out all the properties.

The problem is that there are 8 repeated sections (for the 8 maps in these custom materials) where the property name is the same.

 

So when I do showproperties, I see this (for example):

.map : texturemap
.mipLODBias : float
.uvChannel : integer
.numFrames : integer
.map : texturemap
.mipLODBias : float
.uvChannel : integer
.numFrames : integer
.map : texturemap
.mipLODBias : float
.uvChannel : integer
.numFrames : integer

 

If I grab the material from medit and query one of those values:

mat=meditmaterials[3]

print mat.mipLODBias

 

Then it only returns the first value of mipLODBias

 

How do I get / set the other two values that have the same name? I'd thought I might be able to get at them directly by looking in a property array at array items 2,6 and 10 - the three mipLODBias values, but I've been going in circles trying to figure out how to do this.

 

Any help would be appreciated.

0 Likes
3,870 Views
19 Replies
Replies (19)
Message 2 of 20

Alfred.DeFlaminis
Alumni
Alumni

Hello @chrisell,

 

I am moving this thread to the programming forum because I think you're more likely to get an answer there.  I am not a skilled enough scripter to answer this question for you but I have strong hopes that someone in this new forum can help with this.  Another option is to join the ADN (Autodesk Developer Network) where you have access to a community about programming and scripting.  Thank you for your understanding.  

Best Regards,

0 Likes
Message 3 of 20

chrisell
Contributor
Contributor

Ok thanks - that makes sense ..

0 Likes
Message 4 of 20

denisT.MaxDoctor
Advisor
Advisor

we don't have your material and it hard for us to check real properties names... so we need more inspection:

 

try these checks:

print (getpropnames meditmaterials[1])

for k=1 to meditmaterials[1].numsubs do print meditmaterials[1][k].name

(use the right material index) 

 

the way you see property names is shown by a developer. they are looked duplicated, but in the system it absolutely impossible.

so we have to find real property names or corresponding SubAnim names (which are always unique)

 

Message 5 of 20

chrisell
Contributor
Contributor

When I dump the property names, I see largely the same thing:

 

#map
#mipLODBias
#uvChannel
#numframes
#fps
#horzScrollRate
#vertScrollRate
#isAnimated
#scrollUVs
#tilingMode
#uvOperation
#filterMode

 

Repeated 8 times. The numsubs loop returns 8 sets of ""

I know there has to be a way to find their ACTUAL names but I'm completely lost as to how to do it. If you fancy a challenge and have Max 2011-2015, these plugins are the material plugins (one for each year) : https://www.dropbox.com/s/ldqvdp30w4cgmuk/RWMaxPlugins.zip?dl=0

They're distributed with the dev tools for a game called Train Simulator.

 

If you create a new material, and for the type choose "RWMaterial", you'll get the custom material options. For the ShaderName, choose "TrainBumpSpecEnvMask.fx" and you'll see three slots where textures can be applied as well as a "Mip LOD Bias" and "UV Channel". It's those last two values I'm trying to query and change. But when I do the material.uvChannel, it only queries/changes the one in "Slot 1".

 

I'm relatively new to maxscript and I've been spinning my wheels on this for nearly a week, trying to look into the DLL directly, trying the maxscript inspector functions - I just can't figure out how to get at the values I need.

 

 

 

Message 6 of 20

denisT.MaxDoctor
Advisor
Advisor

where can I get TrainBumpSpecEnvMask.fx?

0 Likes
Message 7 of 20

denisT.MaxDoctor
Advisor
Advisor

@chrisell wrote:

When I dump the property names, I see largely the same thing:

 

#map
#mipLODBias
#uvChannel
#numframes
#fps
#horzScrollRate
#vertScrollRate
#isAnimated
#scrollUVs
#tilingMode
#uvOperation
#filterMode

 

Repeated 8 times. The numsubs loop returns 8 sets of ""

 


i probably know whats going on... check getpropnames medimaterials[1][1]

 

it has to give you the list of props shown above. in this case the access to every set is by sub index:

medimaterials[1][i].mipLODBias, etc. 

0 Likes
Message 8 of 20

chrisell
Contributor
Contributor

Agh. So close. 

- Unknown property: "mipLODbias" in SubAnim:

 

If you look at my reply above, I edited it to include a link to a zip file with the material plugins in it along with instructions on how to create one of these materials to try to poke around in.

 

0 Likes
Message 9 of 20

denisT.MaxDoctor
Advisor
Advisor

what getpropnames medimaterials[1][1] says?

 

actually run:

mat = medimaterials[1] -- where medimaterials[1] is your material
for k=1 to mat.numsubs do
(
         format "sub >> %\n" mat[k]
         print (getpropnames mat[k])
)

 

and tell us the result

Message 10 of 20

chrisell
Contributor
Contributor

It showed the property names of the bitmaps in the material - it's like it went straight past the slot info into the bitmap info.

Any chance you can install the plugin and take a look? I spent another three hours last night trying to get to the bottom of this but I just don't know enough about maxscript yet. I can populate everything else automatically - I'm creating materials, setting the bitmaps with all their options, filling out all the other attributes but these **** UVchannel and MIPLODBias ones are just killing me.

 

0 Likes
Message 11 of 20

denisT.MaxDoctor
Advisor
Advisor

it doesn't work on my machine. it needs some extra data that i don't have (including some XML presets file and TrainBumpSpecEnvMask.fx)

 

i don't have time to search in internet for the dev tools for a game called Train Simulator.

 

0 Likes
Message 12 of 20

chrisell
Contributor
Contributor

Wow that's weird. You ought to be able to just drop the DLU file into the plugins folder. Let me take a look at my install tonight and see exactly how it sits. I'll also post the results of that last code snippit you sent 🙂

0 Likes
Message 13 of 20

chrisell
Contributor
Contributor

Ok my bad - the plugin needs to be installed:

 

Copy the relevant dlu file (RWMaxPlugin20xx_x64.dlu) to the 3ds Max plugins folder (Autodesk\x64\3ds Max 20xx\plugins)
Start up 3ds max
Go to Customize menu -> Plug-in Manager
Right click on any existing plugin, and click Load New Plug-in
Browse to the plugins folder and choose the RW Max Plugin.
Restart 3ds max

 

I also figured it would be worth you seeing the material interface in case you can't / don't want to install the plugin. 

The left side shows the main material. In the yellow box are the "slot" tabs. The green box shows the values I want. There are a pair of these values on each tab.

The red box shows what you get when you expand down into the "slot texture" bitmap.

matplugin.jpg

 

 

 

Anyway - 

The output from the code snippit above:

main body:RWMaterial
sub >> SubAnim:
#clipu
#clipv
#clipw
#cliph
#Jitter
#useJitter
#apply
#cropPlace
#filtering
#monoOutput
#rgbOutput
#alphaSource
#preMultAlpha
#bitmap
#coords
#output
#filename
#starttime
#playBackRate
#endCondition
#tieTimeToMatIDs
sub >> SubAnim:
#clipu
#clipv
#clipw
#cliph
#Jitter
#useJitter
#apply
#cropPlace
#filtering
#monoOutput
#rgbOutput
#alphaSource
#preMultAlpha
#bitmap
#coords
#output
#filename
#starttime
#playBackRate
#endCondition
#tieTimeToMatIDs
sub >> SubAnim:
#clipu
#clipv
#clipw
#cliph
#Jitter
#useJitter
#apply
#cropPlace
#filtering
#monoOutput
#rgbOutput
#alphaSource
#preMultAlpha
#bitmap
#coords
#output
#filename
#starttime
#playBackRate
#endCondition
#tieTimeToMatIDs
sub >> SubAnim:
undefined
sub >> SubAnim:
undefined
sub >> SubAnim:
undefined
sub >> SubAnim:
undefined
sub >> SubAnim:
undefined
OK

Message 14 of 20

denisT.MaxDoctor
Advisor
Advisor

i found a way to make the plugin works... hmm... it's not easy to get/set these parameters via pure MXS.

 

what version of MAX do you use? 

0 Likes
Message 15 of 20

denisT.MaxDoctor
Advisor
Advisor

it's an example "how do not write plugins"... i can set all parameters but only using SDK. it was a very bad developer's idea to share property names across different parameter blocks (honestly i thought it's not possible), and make pblock2 nos as Animatable or true ReferenceTarget.

 

probably i can set parameters for all blocks via MXS but only in MAX 2016 (c#) or MAX 2017 (c# or python).

 

maybe MAX 2015 (c#), but i don't have this version to try

 

 

Message 16 of 20

chrisell
Contributor
Contributor

That makes me feel a bit better that the reason I was having so much trouble is that I really can't do what I want with MXS in this case.

I have Max 2015

 

When you're talking about python and C# - are you talking about an external program that would poke into 3ds max? Or can you embed C# into maxscript somehow?

 

If this is really a big hassle, I'll do it by hand and count this as "just one of those things" 🙂

0 Likes
Message 17 of 20

denisT.MaxDoctor
Advisor
Advisor

@chrisell wrote:

Or can you embed C# into maxscript somehow?


i can embed c# into mxs. you can find many my and other people examples on CGTalk. 

0 Likes
Message 18 of 20

chrisell
Contributor
Contributor

Ok cool - if you can give me a push in the right direction - some quick guidance on "how" to do it, I'll go and experiment. I'd like to learn for myself how to do this sort of thing.

It sounds like you were able to poke around enough in the plugin to find the values you could set so if you can show me how you did that, or how to get/set values using the SDK I might be able to figure it out from there.

0 Likes
Message 19 of 20

denisT.MaxDoctor
Advisor
Advisor
global MaxSDKAssembly
fn CreateMaxSDKAssembly forceRecompile:on =
(
	if forceRecompile or not iskindof ::MaxSDKAssembly dotnetobject or (::MaxSDKAssembly.GetType()).name != "Assembly" do
	(

source = ""
source += "using System;\n"
source += "using Autodesk.Max;\n"
source += "public class MaxSDK\n"
source += "{\n"
source += "	public Object GetGlobal()\n"
source += "	{\n"
source += "		return Autodesk.Max.GlobalInterface.Instance;\n"
source += "	}\n"
source += "}\n"

		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

		compilerParams.ReferencedAssemblies.AddRange #("System.dll", getdir #maxroot + @"Autodesk.Max.dll")

		compilerParams.GenerateInMemory = true
		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
		
		if (compilerResults.Errors.Count > 0 ) then
		(
			errs = stringstream ""
			for i = 0 to (compilerResults.Errors.Count-1) do
			(
				err = compilerResults.Errors.Item[i]
				format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs 
			)
			MessageBox (errs as string) title: "Errors encountered while compiling C# code"
			format "%\n" errs
			undefined
		)
		else
		(
			MaxSDKAssembly = compilerResults.CompiledAssembly
			MaxSDKAssembly.CreateInstance "MaxSDK"
		)
	)
)
MaxSDK = CreateMaxSDKAssembly()

using this snippet for max versions 2016+ (2015 maybe) we can get .net max global object:

gi = MaxSDK.GetGlobal()

 

after that get access to sdk interfaces like:

gi.CoreInterface 

 

after that get any node (INode), its material (IMaterial)...

ask for number of Parameter Blocks, get a Block by index...

get a list of PBlock2 parameters, find a parameter index by name, set and get a parameter by index, etc... and so on

 

 

 

0 Likes
Message 20 of 20

chrisell
Contributor
Contributor

I'm trying .. 

 

Can you give me any more clues? How do I query a material with this?

 

I don't understand what you mean by IMaterial and PBlock2.

I can showproperties on gi.CoreInterface but I don't understand what to do with this info. 

Like I said I'm a total newbie to maxscript ... 😞

I'm so lost right now I might just resign to doing this by hand.

 

0 Likes