Notifications
Clear all

[Closed] 16 bit presision

Is it possible to call this function in max script with .net?
or does anyone have a script to do this?
Thanks so much in advance and happy holidays.
http://msdn.microsoft.com/en-us/library/dw4t9w27.aspx?appId=Dev10IDEF1&l=EN-US&k=k(EHINVALIDCAST)&rd=true

10 Replies

it seams the same as [b]bit.floatAsInt

[/b]UInt16 doesn’t make any sense in MXS. Using MAX->.NET value conversion you can convert mxs float to Single and after that staying in .NET you can convert Single to UInt16, but UInt16 converted to mxs value becomes Integer.

Yes that is what i want to do is convert a float i read in max. Then using .net inside max convert it to 1/2 precision floating point that is usable in max. Can you explain in a small example how to do that please.
Thanks again


single = dotnet.ValueToDotNetObject <any_float> (dotnetclass "System.Single")
-- it's .net object now and you can pass to other .net method
uint = single.ToUInt16 asdotnetobject:on
-- it's a .net object

ps. i don’t have a chance to check it. i’m answering from my cell phone.

I think its using this class but i cant figure out what i am doing wrong to get it working.

Convert = dotnet.ValueToDotNetObject 1.0f (dotnetclass “System.Convert”)
– it’s .net object now and you can pass to other .net method
uint = Convert.ToUInt16 asdotnetobject:on
– it’s a .net object

i get the error
– Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts; position: 42; line: 1
– Unable to convert: 1f to type: System.Convert
– Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts; position: 180; line: 3
– Unknown property: “ToUInt16” in undefined
OK

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

did I use “Convert” class in my sample? No. Please check MXS help
[font=Verdana]MAXScript / DotNet Value Conversions[/font]

single = dotnet.ValueToDotNetObject 1.0 (dotnetclass “System.Single”)
– it’s .net object now and you can pass to other .net method
uint = single.ToUInt16 asdotnetobject:on
– it’s a .net object

gives the error

dotNetObject:System.Single
– Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2010\Scripts; position: 175; line: 3
– Unknown property: “ToUInt16” in dotNetObject:System.Single
OK

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

ok. that’s my bad. you have to use “Convert” class…


(dotnetclass "System.Convert").ToUInt16 single asdotnetobject:on

technically max should convert float to UInt16 directly:


  dotnet.ValueToDotNetObject <any_float> (dotnetclass "System.UInt16")
  

Thanks for all your time.
I get no errors now but when i try to do something like this

test = 1.0
dotnet.ValueToDotNetObject test (dotnetclass “System.UInt16”)
print test

I am not sure how to get the value out.
I am very bad at this i know i am sorry in advance.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

 test_float = 1.0
 test_uint16 = dotnet.ValueToDotNetObject test_float (dotnetclass "System.UInt16")
 print test_uint16
 print (test_uint16.ToString())