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
  10 October 2007
Yeah that's actually the part I'm having the most trouble with right now. I don't really know C#, JScript or Vbasic so converting the syntax is challenging

I did find this. And it's handy. Some form items like radiobuttons are pretty obvious but what to call a spinner based on a picture is useful.

http://www.oreillynet.com/wireless/...cs/image002.jpg

Anywhere I see "new" in C# or VJ# I should replace that with 'dotnetobject'? Seems to be working as a general rule so far...


Edit:
Good DataGrid reference:
http://samples.gotdotnet.com/quicks...c_datagrid.aspx

Last edited by thatoneguy : 10 October 2007 at 09:11 PM.
 
  10 October 2007
Originally Posted by thatoneguy: Some form items like radiobuttons are pretty obvious but what to call a spinner based on a picture is useful.

http://www.oreillynet.com/wireless/...cs/image002.jpg

Spinner in .Net Forms are called NumericUpDown.

Originally Posted by thatoneguy: Anywhere I see "new" in C# or VJ# I should replace that with 'dotnetobject'? Seems to be working as a general rule so far...

Yes, this is a good rule. And you have to use dotNetClass to get static classes, enumerations.
__________________

Last edited by ypuech : 10 October 2007 at 09:21 PM.
 
  10 October 2007
Ok I'm really stuck.

I can't for the life of me figure out how to insert columns (or rows) into a datagrid.

I did get tabs working but can't figure out how to fill out my datagrid.

 
(
 Color = dotNetClass "System.Drawing.Color"
 ScrollBars = dotNetClass "System.Windows.Forms.ScrollBars"
 
 -- Create Tabs Container 
 tabControl1 = dotnetobject "system.windows.forms.TabControl"
 tabControl1.size = dotnetobject "system.drawing.size" 395 195
 tabControl1.Location = dotnetobject "System.Drawing.Point" 0 0 
 
 --Create Tabs
 tabPage1 = dotnetobject "System.Windows.Forms.TabPage"
 tabPage1.text = "Goodbye World"
 tabPage2 = dotnetobject "System.Windows.Forms.TabPage"
 tabPage2.text = "Hello World"
 tabPage1.backColor = color.fromArgb 200 200 200 
 tabPage2.backColor = color.fromArgb 200 200 200 
 
 -- Create Datagrid
 
 
 DGrid1 = dotnetobject "System.Windows.Forms.DataGrid"
 DGrid1.Location = dotNetObject "System.Drawing.Point" 10 10
 DGrid1.Width = 365
 DGrid1.Height = 120
 DGrid1.Visible = true
 
 
 -- Add Some Columns to the Datagrid
 dt = dotnetobject "system.data.datatable"
 Column1 = dotnetclass "System.windows.data.DataColumn"
 
 -- Create TextBox
 TB1TextBox = dotNetObject "System.Windows.Forms.TextBox"
 TB1TextBox.Location = dotNetObject "System.Drawing.Point" 10 10
 TB1TextBox.Width = 365
 TB1TextBox.Height = 120
 TB1TextBox.Visible = true
 TB1TextBox.MultiLine = true
 TB1TextBox.ScrollBars = ScrollBars.Vertical
 TB1TextBox.AcceptsReturn = true
 TB1TextBox.AcceptsTab = true
 TB1TextBox.WordWrap = true
 
 -- Create Buttons
 button01 = dotnetobject "System.Windows.Forms.button"
 button01.text = "goodbye"
 button01.Location = dotNetObject "System.Drawing.Point" 300 138
 
 -- Create Form
 TabForm = dotNetObject "System.Windows.Forms.Form"
 TabForm.Size = dotNetObject "System.Drawing.Size" 400 225
 TabForm.Text = "Title"
 TabForm.TopMost = true
 FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
 TabForm.FormBorderStyle = FormBorderStyle.FixedDialog
 TabForm.ShowInTaskbar = false
 TabForm.MinimizeBox = true
 TabForm.MaximizeBox = false
 Tabform.helpbutton = true
 
 -- Add UI elements to Tabs
 tabpage1.controls.add(TB1textbox)
 tabpage1.controls.add(button01)
 tabpage2.controls.add(DGrid1)
  
 -- Add Tabs to Tab Container
 tabcontrol1.controls.add(tabpage1)
 tabcontrol1.controls.add(tabpage2)
 -- Add Tab Container to UI Form
 TabForm.Controls.Add(tabcontrol1)
 -- Show application Form
 TTApp = dotNetClass "System.Windows.Forms.Application"
 TTApp.Run TabForm
)
 
  10 October 2007
There you go dude, I've managed to add columns and rows, although I figured out how to use the System.Data.Datarow to declare a row and ended up using the NewRow... but after that I could't change the values as in something like row.items["id"]=i that didnt work, dont know why... and I ended up creating an array and adding that up to the datatable, seems to work fine. Cya and if anyone knows how to declare that row thingie please explain!

 
(
 
dotnet.loadassembly "System.Data"
 
 
 
Color = dotNetClass "System.Drawing.Color"
 
ScrollBars = dotNetClass "System.Windows.Forms.ScrollBars"
 
 
 
-- Create Tabs Container 
 
tabControl1 = dotnetobject "system.windows.forms.TabControl"
 
tabControl1.size = dotnetobject "system.drawing.size" 395 195
 
tabControl1.Location = dotnetobject "System.Drawing.Point" 0 0 
 
 
 
--Create Tabs
 
tabPage1 = dotnetobject "System.Windows.Forms.TabPage"
 
tabPage1.text = "Goodbye World"
 
tabPage2 = dotnetobject "System.Windows.Forms.TabPage"
 
tabPage2.text = "Hello World"
 
tabPage1.backColor = color.fromArgb 200 200 200 
 
tabPage2.backColor = color.fromArgb 200 200 200 
 
 
 
-- Add Some Columns to the Datagrid
 
dt = dotnetobject "system.data.DataTable""Test"
 
Column1 = dotnetobject "System.Data.DataColumn" "id" (dotnetclass "System.Int32")
 
Column2 = dotnetobject "System.Data.DataColumn" "Name" (dotnetclass "System.String")
 
dt.columns.add Column1
 
dt.columns.add Column2
 
 
 
for i=0 to 2 do
 
(
 
row=#(dotnetobject "System.Int32" i,dotnetobject "System.String" (i as string)) 
 
dt.rows.add row
 
)
 
 
 
-- Create Datagrid
 
DGrid1 = dotnetobject "System.Windows.Forms.DataGrid"
 
DGrid1.Location = dotNetObject "System.Drawing.Point" 10 10
 
DGrid1.Width = 365
 
DGrid1.Height = 120
 
DGrid1.Visible = true
 
DGrid1.DataSource = dt 
 
 
 
-- Create TextBox
 
TB1TextBox = dotNetObject "System.Windows.Forms.TextBox"
 
TB1TextBox.Location = dotNetObject "System.Drawing.Point" 10 10
 
TB1TextBox.Width = 365
 
TB1TextBox.Height = 120
 
TB1TextBox.Visible = true
 
TB1TextBox.MultiLine = true
 
TB1TextBox.ScrollBars = ScrollBars.Vertical
 
TB1TextBox.AcceptsReturn = true
 
TB1TextBox.AcceptsTab = true
 
TB1TextBox.WordWrap = true
 
 
 
-- Create Buttons
 
button01 = dotnetobject "System.Windows.Forms.button"
 
button01.text = "goodbye"
 
button01.Location = dotNetObject "System.Drawing.Point" 300 138
 
 
 
-- Create Form
 
TabForm = dotNetObject "System.Windows.Forms.Form"
 
TabForm.Size = dotNetObject "System.Drawing.Size" 400 225
 
TabForm.Text = "Title"
 
TabForm.TopMost = true
 
FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
 
TabForm.FormBorderStyle = FormBorderStyle.FixedDialog
 
TabForm.ShowInTaskbar = false
 
TabForm.MinimizeBox = true
 
TabForm.MaximizeBox = false
 
Tabform.helpbutton = true
 
 
 
-- Add UI elements to Tabs
 
tabpage1.controls.add(TB1textbox)
 
tabpage1.controls.add(button01)
 
tabpage2.controls.add(DGrid1)
 
 
 
-- Add Tabs to Tab Container
 
tabcontrol1.controls.add(tabpage1)
 
tabcontrol1.controls.add(tabpage2)
 
-- Add Tab Container to UI Form
 
TabForm.Controls.Add(tabcontrol1)
 
-- Show application Form
 
TTApp = dotNetClass "System.Windows.Forms.Application"
 
TTApp.Run TabForm
 
)
 
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com

Last edited by Kameleon : 10 October 2007 at 09:07 PM.
 
  10 October 2007
This is sort of spinning off from another thread, but it seems best to discuss it here. Can we talk about overall dotNet declaration?

A standard way to access a method is to call it's class:

  myFile = dotNetClass "System.IO.File"
  myFile.methodInQuestion
  


The tricky part is handling all the things that go along with that. For example, relief7 has a large list of local class declarations for interface elements before anything can be build with the messagebox .show() method:

  -- 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"
  


Is there a simple explanation of when you need to call something as an object, property or method as opposed to just accessing it via a call you made previously?

Seeing as it was an interesting exercise, here's the thread that resolved my issue in regards to reading tick values from a LastWriteTime property:
http://forums.cgsociety.org/showthr...p?f=98&t=555276
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems

Last edited by erilaz : 10 October 2007 at 12:59 AM.
 
  10 October 2007
Originally Posted by erilaz: A standard way to access a method is to call it's class:

     myFile = dotNetClass "System.IO.File"
     myFile.methodInQuestion
     


The tricky part is handling all the things that go along with that. For example, relief7 has a large list of local class declarations for interface elements before anything can be build with the messagebox .show() method:

     -- 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"
     


Is there a simple explanation of when you need to call something as an object, property or method as opposed to just accessing it via a call you made previously?

MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton and DialogResult are enumerations so it's not needed to create an object; just get their values. It's the same for the static Show() method of a MessageBox.
A static member belongs to the class rather than to the objects of the class. Static members are also known as class members and non-static members are known as instance members.

dotNetObject is used in the same manner than C# constructor new() :

C# code
FileInfo fileInfo = new FileInfo(fileName);


Equivalent MAXScript code:
fileInfo = dotNetObject "System.IO.FileInfo" fileName


So, when a value is returned from a method, there's no need to worry about its creation.
__________________

Last edited by ypuech : 10 October 2007 at 09:34 AM.
 
  10 October 2007
I just discovered that in 3ds Max 2008 there's a .Net SDK including an assembly that contains specific UI controls for use in Max. And a MaxForm class was developed so now we can use it in Max 2008 instead of standard "System.Windows.Forms.Form".

My previously example with the .Net Form TextBox (http://forums.cgsociety.org/showpos...95&postcount=21) can now be coded as this under Max 2008:

(
	-- Load MaxCustomControls assembly
	-- This assembly contains UI components built on the .NET Framework for use in 3ds Max
	dotNet.loadAssembly "MaxCustomControls.dll"

	-- 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 Max Form
	hMaxForm = dotNetObject "MaxCustomControls.MaxForm"
	hMaxForm.Size = dotNetObject "System.Drawing.Size" 310 335
	hMaxForm.Text = "Max Form with TextBox"
	hMaxForm.Controls.Add(hTextBox)
	hMaxForm.TopMost = true
	FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
	hMaxForm.FormBorderStyle = FormBorderStyle.FixedDialog
	hMaxForm.ShowInTaskbar = false
	hMaxForm.MinimizeBox = false
	hMaxForm.MaximizeBox = false
    
	-- Show MaxForm
	hMaxForm.ShowModeless()
)


All the UI events from Max main window (it's the parent window of the form) are now correctly handled by the MaxForm.

This is a first example of the use of these assemblies primarly developed for use in plugin code but I think they are also very useful at scripting .
__________________

Last edited by ypuech : 10 October 2007 at 11:40 PM.
 
  10 October 2007
Autodesk guys wrote these assemblies for Scene Explorer which is mostly coded in C# but hooked into Max using C++/SLI.




Light
 
  10 October 2007
DotNet OpenFileDialog

I recently came across the problem of needing to let the artests in out studio select multiple files to perform operations on within my script.

I started out using the max getOpenFileName function, but soon discovered that it does not provide for multiple selections...a bit of a problem when dealing with a large number of files...So I thought I'd see what dn could do for me.

So after some time spent reading through the msdn docs, I came up with this...
local ofd = dotnetobject "System.Windows.Forms.OpenFileDialog"
 ofd.Filter = "XML Files (*.xml)|*.xml"
 ofd.RestoreDirectory = false			
 ofd.multiselect = true
  			
 if ofd.showDialog() == (dotNetClass "System.Windows.Forms.DialogResult").OK then (
   local sFile = ofd.fileNames
   -- Process the file array here...
 )
It seems to have worked quite well for what I need.

I hope it helps some one

Shane
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
  10 October 2007
I would like to compile a list of dotNet controls and classes that people are finding usful here and post it on my site with the test code that is being shown here. Does any one have a problem with me using the test code right from here so that I don't have to rewrite it? I will post links to the origainal authors of the code if they have sites as well.

It would be good if we had a reference page of useful tid bits that others can start to reference.
__________________
Paul Neale
http://paulneale.com
 
  10 October 2007
Originally Posted by PEN: I would like to compile a list of dotNet controls and classes that people are finding usful here and post it on my site with the test code that is being shown here. Does any one have a problem with me using the test code right from here so that I don't have to rewrite it? I will post links to the origainal authors of the code if they have sites as well.

It would be good if we had a reference page of useful tid bits that others can start to reference.


I'd prefer it to be translated over to the cgWiki like the geometrical calculations thread has been, but it's your call. It would be great to be able to cross-reference it with stuff like this.
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems
 
  10 October 2007
Why not do it both? I like Pauls site and have it under my favourites... I never seem to get around wiki's, don't understand the navigation of these things...

-Johan
__________________
Online: LinkedIn
 
  10 October 2007
Originally Posted by JHN: Why not do it both? I like Pauls site and have it under my favourites... I never seem to get around wiki's, don't understand the navigation of these things...

-Johan


I certainly have no problem with that, I'm just doing my job as a wiki/max moderator.
__________________
"There Really is No Secret"
Martin Brennand - mocha Product Manager - Imagineer Systems
 
  10 October 2007
While my brain was melting after a major commercial I did this to include in my scripts, it's a .ms file with class declarations to help the programming of .Net stuff, after that I've created a small script to enumerate all the variables assigned in that file... the files are quite self-explanatory.

I also added a variable called New that executes the string "dotNetObject" so when we want to create some object we can do something simple as textbox = new dotNetTextBox. There's still so much thing to add but that's the basic stuff I've seen on MSDN.

I'll add more as I need and you can also do the same, just keep the same structure, so when you run the Enumerate script it creates a .txt file with all the correct declarations and it's easier to share with others updated versions of the file. Hope you like it and feel free to download and improve it! Cya

PS - Both files need to be in the same directory.
Attached Files
File Type: zip dotnet.zip (1.0 KB, 186 views)
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com
 
  10 October 2007
Originally Posted by PEN: I would like to compile a list of dotNet controls and classes that people are finding usful here and post it on my site with the test code that is being shown here. Does any one have a problem with me using the test code right from here so that I don't have to rewrite it? I will post links to the origainal authors of the code if they have sites as well.

It would be good if we had a reference page of useful tid bits that others can start to reference.
Knock yourself out! I think it's great idea...the forum can get a little messy from time to time

Shane
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
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 07:55 AM.


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