.net question

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  06 June 2008
.net question

I would have posted in the .net sticky, but at 8 pages already it's not so useable...

I've been chatting with someone about using .net to provide base64 encoded strings.

dnClass = dotNetClass "System.Convert"
 dnValue = (dotNetObject "System.String" "Dave")
 dnClass.ToBase64String dnValue
 
 dotNetClass:System.Convert
 dotNetObject:System.String
 -- Runtime error: No method found which matched argument list


I know next to nothing about .net, or how to lever it, so I don't really understand the error, or what I'm obviously doing wrong to not be able to access the method.

  .[static]<System.String>ToBase64String inArray
   .[static]<System.String>ToBase64String inArray options
   .[static]<System.String>ToBase64String inArray offset length
   .[static]<System.String>ToBase64String inArray offset length options
 



Looking forward to someone shedding some light on the basics for me,
Thanks,
Dave
__________________
Portfolio | Keyframes and Code
 
  06 June 2008
I've tried the same and found that it simply doesn't work. The ToBase64String method expects a byte array, which you cannot create using mxs. I wrote a dll with a couple of simple wrappers, including a method to convert strings to base64, but it's part of a larger project which I can't share. I can put just this functionality in a single dll if you want though, but the downside is that it adds an extra dependency to your script.

Here's how (I think) it should work:

(

	dnEncoding = (dotNetClass "System.Text.Encoding").Unicode -- or UTF8 or ASCII or ..
	dnConvert = dotNetClass "System.Convert"
	dnValue = dotNetObject "System.String" "Dave"
	
	-- Convert the string to an array of bytes.
	Bytes = dnEncoding.GetBytes dnValue

	-- Get the Base64 string using these bytes.
	dnConvert.ToBase64String Bytes

	-- Runtime exception ...
	-- max automatically converts the byte array retrieved from the
	-- GetBytes method to an array of integers, which dotNet is unable
	-- to convert back to an array of bytes ...
	
)


Cheers,
Martijn
 
  06 June 2008
a byte array is just an array of, well, bytes; in this case stored as 8bit ints. No reason you shouldn't be able to use it...


 dncConvert = dotNetClass "System.Convert"
 dotNetClass:System.Convert
 
 dnvStringIn = (dotNetObject "System.String" "Dave")
 dotNetObject:System.String
 
 dnoASCII = dotNetObject "System.Text.ASCIIEncoding"
 dotNetObject:System.Text.ASCIIEncoding
 
 dnvByteArrayIn = dnoASCII.getBytes dnvStringIn
 #(68, 97, 118, 101)
 
 dnvB64String = dncConvert.ToBase64String dnvByteArrayIn
 "RGF2ZQ=="
 
 dnvByteArrayOut = dncConvert.FromBase64String dnvB64String
 #(68, 97, 118, 101)
 
 dnoUTF8 = dotNetObject "System.Text.UTF8Encoding"
 dotNetObject:System.Text.UTF8Encoding
 
 dnvStringOut = dnoUTF8.getString dnvByteArrayOut
 "Dave"
 



Whether that does what you need it to do, however...
 
  06 June 2008
Hey guys,

Thanks so much for the info. We're just chucking ideas around at the moment, but that's really helpful.

Richard, in particular, thanks for working through the sticky stuff. .NET seems quite rigourous / unforgiving so it's good to have an example.

With that in mind, how would one go about getting to know how to use .NET without feeling like it's bashing your head against a brick wall? Do I need to get into Visual Studio and C# type stuff first?

Cheers,
Dave
__________________
Portfolio | Keyframes and Code
 
  06 June 2008
hi Dave,

i'd just go to microsoft and download the visual studio express edition. I went for the VB flavour, as i thought it would be a wee bit more straightforward than c#.
it's free and even without getting into it you will be able to see via the intellisense prompt how to declare the classes and what arguments and overloads pertain to each. It really will remove the guesswork about using .net within max. on a side note im frustrated as I am hoping to post some of my dotnet research soon, including usercontrols and a dotnet maxfile thumbnail class but am totally swamped at the mo.
__________________
Regards,
Pete

Read my technical blog - lonerobot.net
 
  06 June 2008
in addition to grabbing express, I'd say find the nearest book store and pick up a copy of a beginner-level .NET book; there's plenty of resources online as well, of course, but books tend to have better flow
 
  06 June 2008
So the ToBase64String method does work for you guys?
Weird.. here's what I get:

Quote: -- Runtime error: dotNet runtime exception: Cannot widen from source type to target type either because the source type is a not a primitive type or the conversion cannot be accomplished.


This is on max2008 32bit btw.

Martijn
 
  06 June 2008
Originally Posted by magicm: So the ToBase64String method does work for you guys?

In 3ds max 2009 - sure!
( nothing noted in the help file topic "What's new in..." )

Originally Posted by magicm: This is on max2008 32bit btw.

As some people frequently tell me... "who cares about older max versions?"

Confirmed, for what it's worth (ditto 3ds Max 9) - so either they silently fixed something somewhere, or it was automagically fixed with the new compile.

Edit: I don't remember where this was linked from, but I remember I had browsed it before;
The following link should go to a post at The Area that deals with byte array handling in maxscript
http://area.autodesk.com/index.php/...ewthread/13286/


The code then* becomes something like:

 dncConvert = dotNetClass "System.Convert"
 dotNetClass:System.Convert
 dnvStringIn = (dotNetObject "System.String" "Dave")
 dotNetObject:System.String
 dnoASCII = dotNetObject "System.Text.ASCIIEncoding"
 dotNetObject:System.Text.ASCIIEncoding
 dnvByteArrayIn = dnoASCII.getBytes dnvStringIn
 #(68, 97, 118, 101)
 
 -- ByteArrayTools
 arry = dotnetobject "System.Byte[]" dnvByteArrayIn.count
 dotNetObject:System.Byte[]
 for i = 1 to dnvByteArrayIn.count do ( ByteArrayTools.SetValue arry (i - 1) dnvByteArrayIn[i] )
 OK
 -- /ByteArrayTools
 
 dnvB64String = dncConvert.ToBase64String arry
 "RGF2ZQ=="
 
 dnvByteArrayOut = dncConvert.FromBase64String dnvB64String
 #(68, 97, 118, 101)
 dnoUTF8 = dotNetObject "System.Text.UTF8Encoding"
 dotNetObject:System.Text.UTF8Encoding
 
 -- ByteArrayTools
 arry = dotnetobject "System.Byte[]" dnvByteArrayOut.count
 dotNetObject:System.Byte[]
 for i = 1 to dnvByteArrayOut.count do ( ByteArrayTools.SetValue arry (i - 1) dnvByteArrayOut[i] )
 OK
 -- /ByteArrayTools
 
 dnvStringOut = dnoUTF8.getString arry
 "Dave"
 

( tested in 3ds Max 9x32 )

Edit: Added link to The Area post
Edit2: Added sample code using the assembly created from The Area post
Edit3: * after evaluating the 'CreateAssembly' and 'CompileByteArrayTools' functions from The Area post.

Last edited by ZeBoxx2 : 06 June 2008 at 12:16 PM.
 
  06 June 2008
Thanks for checking. I'm glad I won't be needing that dll anymore

Edit: And thanks for posting that link as well Richard, useful stuff!

Cheers,
Martijn

Last edited by magicm : 06 June 2008 at 12:21 PM.
 
  06 June 2008
Also note on the .net sticky thread I posted a message from someone on the area who found a way to compile dotnet classes/objects in mxs runtime... which leads to "probably" never have to compile a dll again! The .cs file as string can be used.

-Johan
__________________
Online: LinkedIn
 
  06 June 2008
Originally Posted by ZeBoxx2: Edit: I don't remember where this was linked from, but I remember I had browsed it before


Originally Posted by JHN: Also note on the .net sticky thread I posted a message from someone on the area who found a way to compile dotnet classes/objects in mxs runtime...

Aha, that was where had browsed the non-sticky threads to find the reference and came up empty-handed
 
  06 June 2008
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:55 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.