dotNet + MXS

Become a member of the CGSociety

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

REPLY TO THREAD
 
Thread Tools Search this Thread Display Modes
Old 10 October 2007   #16
Originally Posted by PEN: 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.

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
)
__________________
 
Old 10 October 2007   #17
Maybe give Windows.Forms a try instead of maxscript dialogs? I might solve it I think, although I never tried.




Light
 
Old 10 October 2007   #18
Originally Posted by Light: Maybe give Windows.Forms a try instead of maxscript dialogs? I might solve it I think, although I never tried.

Light


I am using "system.windows.forms.textBox" Are you thinking of something else?
__________________
Paul Neale
http://paulneale.com
 
Old 10 October 2007   #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 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!
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com
 
Old 10 October 2007   #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
 
Old 10 October 2007   #21
Originally Posted by Light: 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.

Yes it can be a solution.
Here is a way of creating a .Net form containing a TextBox that looks visually similar to a a MAXScript dialog. One of the main difference is that the form cannot get messages when the main Max window is minimized, maximized, resized etc. It's always displayed even if Max is minimized for example.You can set the parent if you create this form in C++/CLI in a plugin but not in MAXScript (it would be interesting to create a small patch to the dotNet bridge...).

Here is the code:
(
	-- Create TextBox
	hTextBox = dotNetObject "System.Windows.Forms.TextBox"
	hTextBox.Location = dotNetObject "System.Drawing.Point" 10 10
	hTextBox.Width = 280
        hTextBox.Height = 280
	hTextBox.Visible = true
	hTextBox.MultiLine = true
	ScrollBars = dotNetClass "System.Windows.Forms.ScrollBars"
	hTextBox.ScrollBars = ScrollBars.Vertical
	hTextBox.AcceptsReturn = true
	hTextBox.AcceptsTab = true
	hTextBox.WordWrap = true
	
	-- Create Form
	hForm = dotNetObject "System.Windows.Forms.Form"
	hForm.Size = dotNetObject "System.Drawing.Size" 310 335
	hForm.Text = ".Net 2.0 Form with TextBox"
	hForm.Controls.Add(hTextBox)
	hForm.TopMost = true
	FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
	hForm.FormBorderStyle = FormBorderStyle.FixedDialog
	hForm.ShowInTaskbar = false
	hForm.MinimizeBox = false
	hForm.MaximizeBox = false
	
	-- Set appropriate Form background color
	maxBackColor = colorMan.getColor #background
	Color = dotNetClass "System.Drawing.Color"
	hForm.BackColor = Color.FromArgb (maxBackColor[1] * 255.0f) (maxBackColor[2] * 255.0f) (maxBackColor[3] * 255.0f)
    
	-- Show application Form
	hApp = dotNetClass "System.Windows.Forms.Application"
	hApp.Run hForm
)


Also, App.Run() is better than Form.Show() because it initializes well the dialog and the keyboard handling. With Form.Show(), Max intercepts all the keyboard messages when writting in the TextBox...
__________________

Last edited by ypuech : 10 October 2007 at 10:34 PM.
 
Old 10 October 2007   #22
Hi !

I am following Erilaz's suggestion from another thread about message boxes. He asked me to paste a small test of mine with .NET standard dialog boxes into this thread as well. It is very basic and self-explanatory and could be useful if one needs those "fancy" icons or more functionality than the standard MaxScript messageBox().

Overall I am just getting into the whole .NET thing and I really love it ! It is so easy to get more functionality without all the cryptic ActiveX stuff. I remember that we used a RegEx class as well in C# some time back. Imagine having regular expressions in MaxScript or easy Database access, XML writing/parsing in MAXScript. Yay !!!

Ok so here is my humble contribution. I hope it helps someone get started...

/*
 ----------------------------------------------------------
 System.Windows.Forms.MessageBoxButtons (Enumeration)
 ----------------------------------------------------------
 .AbortRetryIgnore
 .OK
 .OKCancel
 .RetryCancel
 .YesNo
 .YesNoCancel
 
 ----------------------------------------------------------
 System.Windows.Forms.MessageBoxDefaultButton (Enumeration)
 ----------------------------------------------------------
 .Button1
 .Button2
 .Button3
 
 ----------------------------------------------------------
 System.Windows.Forms.MessageBoxIcon (Enumeration)
 ----------------------------------------------------------
 .Asterisk
 .Error
 .Exclamation
 .Hand
 .Information
 .None
 .Question
 .Stop
 .Warning
 
 ----------------------------------------------------------
 MessageBox.show (Method)
 ----------------------------------------------------------
 MessageBox.show ( text, caption, buttons, icon, defaultButton )
 
 */ 
 
 (
 	-- setup dotnet classes / objects
 	local mb = dotNetClass "System.Windows.Forms.MessageBox"
 	local buttons = dotNetClass "System.Windows.Forms.MessageBoxButtons"
 	local icons = dotNetClass "System.Windows.Forms.MessageBoxIcon"
 	local defaultButton = dotNetClass "System.Windows.Forms.MessageBoxDefaultButton"
 	local dialogResult = dotNetClass "System.Windows.Forms.DialogResult"
 	
 	local result = mb.show "Do you want to save before quitting ?" "Quit" buttons.YesNoCancel icons.Information defaultButton.Button3
 	
 	-- evaluate result of messageBox (which button has been pressed by the user)
 	if ( result == dialogResult.Yes ) then
 	(
 		format "YES\n"
 	)
 	else if ( result == dialogResult.No ) then
 	(
 		format "NO\n"
 	)
 	else if ( result == dialogResult.Cancel ) then
 	(
 		format "CANCEL\n"
 	)
 	
 )


Btw, is anybody using a version control system for their scripts ? I recently setup a SVN and Apache server and I organized all my scripts into a system-independent directory structure. This way I can check out everything that is needed ( encrypted over SSH ) wherever the work place is (of course web access is required). It is pretty practical and wonder now why I have not installed something like that for such a long time... No more synchronisation between different computers required.

Just as a hint for someone who ( like me ) struggled organizing their files ! If someone has other thoughts about organizing their tools I would really love to hear how you handle it. No thread hijacking intended though.
 
Old 10 October 2007   #23
Here's the code for displaying data in a listbox.... But I still can't use DataSource and DisplayMember... it simply doesn't work, any help on that would be great!



(
 
rollout rolmain "Dotnet" 
 
(
 
 
 
dotNetControl lst_test "System.Windows.Forms.Listbox" width:250 height:150 align:#center
 
 
 
on rolmain open do
 
(
 
dotnet.loadassembly "System"
 
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"
 
 
 
--lst_test.DataSource = dataset.tables.item["tasks"]
 
--lst_test.DisplayMember = dotNetObject "System.String" "taskname"
 
 
 
for i=0 to dataset.tables.item["tasks"].rows.count-1 do
 
(
 
lst_test.items.Add (dotnetobject "System.String" dataset.tables.item["tasks"].rows.item[i].item["taskname"])
 
)
 
)
 
)
 
 
 
createDialog rolmain 300 300
 
)
 
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com
 
Old 10 October 2007   #24
Well I think I've found something, I've created a form and used the listbox there, with the datasource, displaymember etc etc and it worked just fine... seems like a limitation when using the listbox inside a rollout or something...
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com
 
Old 10 October 2007   #25
This is all realy good information guys. Looks like dotNet has some limitations if you include them with Max rollouts. Right now my tool is to far along to go back as I have to get it done but I will try a full dotNet UI next time and see what can be done.. or not.
__________________
Paul Neale
http://paulneale.com
 
Old 10 October 2007   #26
Does anybody know of a resource online that lists a whole gaggle of different .net interface items all in one script with a simple action for each? Kind of like in the Maxscript documentation with every single interface item.

I would like to redo the Volumes interface in .net but I don't really know where to start. If I can see a working script I'm very adept at reverse engineering.
 
Old 10 October 2007   #27
There is information in the Max help that covers how to set up .net controls. Have a look for converting axcontrols to .net and you should find it.

To get a list of everything that you can do with .net you will need to visit MSDN and look for the .net class library. Specificly to locate the UI items you will need to look up system.windows.forms and go from there. Here is a direct link to it.

http://msdn2.microsoft.com/en-us/li...dows.forms.aspx

Do the help files in the Max scritp help and then start looking at MSDN and it will start to make some sense.
__________________
Paul Neale
http://paulneale.com
 
Old 10 October 2007   #28
Originally Posted by relief7: Btw, is anybody using a version control system for their scripts ? I recently setup a SVN and Apache server and I organized all my scripts into a system-independent directory structure. This way I can check out everything that is needed ( encrypted over SSH ) wherever the work place is (of course web access is required). It is pretty practical and wonder now why I have not installed something like that for such a long time... No more synchronisation between different computers required.

Just as a hint for someone who ( like me ) struggled organizing their files ! If someone has other thoughts about organizing their tools I would really love to hear how you handle it. No thread hijacking intended though.


I created a new thread about code management, I'm very interrested in your setup, as I use turtoise svn for my code.

-Johan
__________________
Online: LinkedIn
 
Old 10 October 2007   #29
Is it possible to use a visual .Net forms tool and then import that code into Max? A .net IDE of some sort?
 
Old 10 October 2007   #30
Originally Posted by thatoneguy: Is it possible to use a visual .Net forms tool and then import that code into Max? A .net IDE of some sort?

The code generated by a Form designer is in C# or VB.NET so you have to convert it to MAXScript. The conversion is generally easy to implement; cf. the code I posted above.
__________________
 
reply 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 11:54 AM.


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