Notifications
Clear all

[Closed] Open dotNet Form with Maxscript

Actual “SplineAlignDialog.cs” code:

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Max;

namespace SplineAlign
{
    public partial class SplineAlignDialog : Form
    {
        IGlobal global;
        public SplineAlignDialog(IGlobal global)
        {
            this.global = global;
            InitializeComponent();
        }

        private void SplineAlignDialog_Load(object sender, EventArgs e)
        {

        }

        private void Button_Align_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World!");
        }
    }
}

I tried different ways but it dose not work. May be somebody help with it.
SplineAlignDialog takes the argument and if i am typing:


function LoadSplineAlign = ( 	
	
    local    iglobal    = dotNetClass   "Autodesk.Max.IGlobal" 
    global  Dialog     = dotNetObject "SplineAlign.SplineAlignDialog"
    Dialog.Show()
 
)

LoadSplineAlign ()

there are errors

-- Error occurred in LoadSplineAlign(); filename: ; position: 499; line: 15
--  Frame:
--   iglobal: dotNetClass:Autodesk.Max.IGlobal
-- Runtime error: No constructor found which matched argument list: SplineAlign.SplineAlignDialog
OK

once i am typing


function LoadSplineAlign = ( 	
	
    local    iglobal    = dotNetClass   "Autodesk.Max.IGlobal" 
    global  Dialog     = dotNetObject "SplineAlign.SplineAlignDialog(iglobal)"
    Dialog.Show()
 
)

LoadSplineAlign ()

then there are the errors

-- Error occurred in LoadSplineAlign(); filename: ; position: 508; line: 15
--  Frame:
--   iglobal: dotNetClass:Autodesk.Max.IGlobal
-- Runtime error: Cannot resolve type: SplineAlign.SplineAlignDialog(iglobal)
OK

I think i shoud give the argument into the constructor.

You are getting the error because the constructor in your class takes one parameter, and you are trying to build it in MaxScript with no params.

Use this in your C#:


 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using Autodesk.Max;
 
 namespace SplineAlign
 {
 	public partial class SplineAlignDialog : Form
 	{
 		IGlobal global;
 		public SplineAlignDialog()
 		{
 			global = GlobalInterface.Instance;
 		}
 
 		private void SplineAlignDialog_Load(object sender, EventArgs e)
 		{
 
 		}
 
 		private void Button_Align_Click(object sender, EventArgs e)
 		{
 			MessageBox.Show("Hello World!");
 		}
 	}
 }
 

And use this in your maxscript:


 myForm = dotNetObject "SplineAlign.SplineAlignDialog"
 myForm.show() --Windows form
 

I got it But what should i do if i need the paremeter in my constructor?

Well, there is no need to send the Iglobal instance because you can grab it through Autodesk.Max.GlobalInterface.Instance. But, if you wanted to send a param you can easily do that in maxscript dotNet.

dotNetObject “MyNameSpace.MyClass” “param1” “param2”

so if you wanted to get your old dll working, you would do:


--using the code posted above in the link i gave. this seems way too long winded tbh, could probably be much shorter, and im not sure you need to load the assembly as it is already loaded.
local Assembly = dotNetClass "System.Reflection.Assembly"
local maxroot = pathConfig.GetDir #maxroot
Assembly.LoadFile (maxroot + "\Autodesk.Max.dll")
GlobalInterface = dotNetClass "Autodesk.Max.GlobalInterface"  
MaxGlobal = GlobalInterface.Instance

 --finally send your control the correct params
Dialog  = dotNetObject "SplineAlign.SplineAlignDialog" MaxGlobal
Dialog.Show()

Well it dose not work

-- Error occurred in anonymous codeblock; filename: D:\work\MyTutors\GardenWorker\Scripts\1.ms; position: 110; line: 4
-- Runtime error: No constructor found which matched argument list: SplineAlign.SplineAlignDialog
-- Error occurred in anonymous codeblock; filename: D:\work\MyTutors\GardenWorker\Scripts\1.ms; position: 140; line: 5
-- Unknown property: "show" in undefined
1 Reply
(@timhawker)
Joined: 11 months ago

Posts: 0

Make sure that you have removed the params in your constructor, like in the code I posted:


public SplineAlignDialog()
{
	  global = GlobalInterface.Instance;
}

While it’s cool that the maxscript way worked, there really is no need for the extra max scripting code. It is much better to keep as much in C# as possible, so do try and get the above method working. There may be a typo as I just wrote it in the browser, not in visual studio, but it should definitely work.

This code works fine!

fn test = (
local Assembly = dotNetClass "System.Reflection.Assembly"
local maxroot = pathConfig.GetDir #maxroot
Assembly.LoadFile (maxroot + "\Autodesk.Max.dll")
GlobalInterface = dotNetClass "Autodesk.Max.GlobalInterface"  
global MaxGlobal = GlobalInterface.Instance
)

test ()

 --finally send your control the correct params
Dialog  = dotNetObject "SplineAlign.SplineAlignDialog" MaxGlobal
Dialog.Show()

Very Thanks!

Did not even look at the SplineAlignDialog code Thx for clarifying Tim! i knew I wasn’t too far off

Page 2 / 2