dotNet + MXS


#1

In light of David Mackenzie’s excellent Python+MXS thread, I figured it would make sense to have a thread focused on dotNet as well. Admittedly this is mainly because i’m interested in using it right now, but any and all techniques about dotNet can be discussed here!

In addition, don’t forget the beautiful piece of work that is Bobo’s ongoing work with the Maxscript dotNet Resource page.


#2

dotNet + MXS = MXS++
With the addition of dotNet in MAXScript, you can now develop powerful tools that you never thought possible!

dotNet bridge in MAXScript is very useful to access .Net classes:

  • .Net forms controls
  • file access
  • XML read/write
  • GDI+
  • DirectX Managed classes (video and audio)
  • OS informations
  • etc.

You can also create your own .Net classes and use them in script. This can be used to share components with your asset and workflow applications for example. Think also interop between your 3D applications (Maya wit Python, XSI with C# and 3ds Max with dotNet can now share components and communicate more easily).

I’ve recently released a small Avi Player developed in MAXScript and dotNet : http://ypuechweb.free.fr/avi_player.html. It uses DirectX Managed classes (video and audio) and a HScrollBar control (very useful because there’s no equivalent in MAXScript).
I also began the translation to dotNet and GDI+ of the “How To … Develop a Bitmap Painting Tool In Nine Easy Steps”. GDI+ is powerful but sometimes (very) slow.
I’ll release this doc and others (about XML access, some .Net forms controls and managed classes creation and use in script) in a couple of days/weeks :).

One of the limitation of the dotNet bridge is the impossibility to create and use managed arrays in MAXScript (corrected in Max 2008?).


#3

I’ll see what I can constribute as well as I have been using dotNet for the project I have been working on and have been using treeView, ListView, calanders, XML and others to get the job done. dotNet is far better then what we had with active X.


#4

This is a timely thread. Can it please be made sticky?

I have an issue finaly that I can’t resolve with a simple dotNetControl “system.windows.forms.textBox”

Some of the properties are not working as they should. The ones that I’m having issues with are acceptsTab and acceptsReturn, neither are having any affect on the control. multiLine has worked and I have also added scrollbars.

Any one used this before and have a solution?


#5

I would suggest to call Focus() on the TextBox. I had such problems with a RichTextBox control (other solution, useful to format and colour the text) and resolved them by calling Focus().
If it’s a multiline TextBox make sure the Multiline property is set to true.


#6

ypuech, can you explain to me what managed arrays are?


#7

Managed arrays are the arrays from .Net framework. In MAXScript you can’t handle them. For example:

local Array = dotNetObject "System.Windows.Forms.TreeNode[]" 5
 -- With a previously defined TreeNode object
 Array.Add Node -- Not possible to call Add method

#8

Thanks for the explanation on the arrays.

As for the focus() it didn’t help at all.

Here is what I have…


 rollout test "Test"
 (
 	dotNetControl tb "system.windows.forms.textBox" height:80
 	
 	on test open do
 	(
 		tb.multiLine=true
 		sb=dotNetClass "System.Windows.Forms.ScrollBars"
 		tb.scrollBars=sb.vertical
 		tb.acceptsReturn=true
 		tb.acceptsTab=true
 		tb.wordWrap=true
 		tb.focus()
 	)
 )
 createDialog test
 

Can any one get that to work?


#9

Hi Paul,

Are you trying to set the focus to the textbox? If so, it works here.

Light


#10

Well, in fact the Enter and Tab keys aren’t working in the TextBox. Yes, the focus is set but we cannot go to the next line with Enter and use the Tab key. I think the messages are intercepted by the main window of 3ds Max.


#11

No worries. I actually thought I already had! :smiley:


#12

One thing i’ve been focusing on is the use of message boxes and all their meanings. Although I can call a messageboxwith a simple text call via:

message = dotNetClass “System.Windows.Forms.MessageBox”
message.Show “Test”

I can’t work out the call of the buttons. Do I need to have a separate object call to define the button properties in .Show? I think i’m getting the syntax confused.


#13

I don’t no that I would say excellent! but ill take any complements I can get so thanks Martin. I am very excited about the this thread as I am using dotnet more and more in my scripts and am sure I will have lots of questions…

Moving on DotNet, I have some trouble creating a SQL connection in MXS. I have been trying to use System.Data.Odbc but have had no luck Im sure there is something simple i have to do to get this to work but I’m having a mental blank!

I am presuming that it should be some thing like db = dotNetClass “System.Data.Odbc”
but all I get is undefined… Any help would very much appreciated!

Cheers
Dave


#14

System.Data.Odbc is a namespace name, not a class name.

I’ve not much experience with Database usage but I looked at the MSDN documentation and found some examples.

Here is one:

connectionString = "Driver={SQL Native Client};Server=(local);Trusted_Connection=Yes;Database=AdventureWorks;"

connection = dotNetObject "System.Data.Odbc.OdbcConnection" connectionString
connection.Open()

You can have a look at :
the namespace documentation : http://msdn2.microsoft.com/en-us/library/system.data.odbc.aspx
this tutorial : http://www.functionx.com/vbnet/odbc/paradox.htm


#15

Thanks but it is the tab and enter and I think that I have come to the same conclusion as ypuech, Max must be interfering with the operation. I’m just going to live with it at the moment as I have bigger things to deal with.


#16

It’s a strange bug because if you print the key pressed in the KeyPressed event you can see the Enter and Tab keys:

on tb keyPress senderArg keyPressEventArgs do
(
	print keyPressEventArgs.keyChar
)

#17

Maybe give Windows.Forms a try instead of maxscript dialogs? I might solve it I think, although I never tried.

Light


#18

I am using “system.windows.forms.textBox” Are you thinking of something else?


#19

specxor:

You have to do dotnet.loadassembly “System.Data” first. I have some code at work that may be of use to you.

And by the way… does anyone knows why the listbox doesnt display any info in a dataset?

I’ve sucessefully created a dataset, a table adapter, I can access the values on the rows, but after assigning the Datasource and Displaymember, the listbox remains empty… cant figure that out.

I dont have Max 9 here so I’ll write what I can remember :smiley: It’s something like this


(
rollout rollmain "dotnet" 
(
dotnetcontrol lst_test "System.Windows.Forms.Listbox" width:290 height:290 align:#center
 
on rolmain open do
(
dotnet.loadassembly "System.Data"
 
constring="data source=.\SQLEXPRESS;Initial Catalog=YOUR_DATABASE_HERE;Integrated Security=True;Connect Timeout=30"
con=dotnetobject "System.Data.SqlClient.SqlConnection" constring
 
dataset=dotnetobject "System.Data.Dataset"
tableadapter=dotnetobject "System.Data.SqlClient.SqlDataAdapter" "SELECT * FROM tasks" constring
 
tableadapter.Fill dataset "tasks"
 
--At this point you have your data into the dataset created before
--Now the problem seems to be with the listbox databinding... cant understand why
 
lst_test.Datasource=dataset.tables["tasks"]
lst_test.DisplayMember="taskname" --This is the column name used for displaying data and I thing the problem is here somewhere...
lst_test.ValueMember="id_task" -- Primary key column
 
--if you want to confirm the data in your dataset you could do this loop. This shows that the problem is not getting the data into the dataset but displaying it in the listbox
 
for i=0 to dataset.tables["tasks"].rows.count do -- it's this or dataset.tables["tasks"].rows.items.count, can't quite remember
(
print dataset.tables["tasks"].rows.item[i].item["taskname"] --I'm not sure about this one, but a ShowProperties on dataset.tables["tasks"] should help a little
)
 
)
)
createdialog rollmain 300 300
)

And that’s about it, hope this helps and if someone knows why the listbox is not displaying my data please say something! Cyas!


#20

Yes, I was thinking about:

frmMain = dotNetObject "System.Windows.Forms.Form"
frmMain.Show()

Doesn’t have some abilities of the maxscript rollout like docking inside the Max UI, but it behaves like a standalone UI.

Light