View Full Version : DotNet Loading Assembly

04 April 2008, 02:50 PM
I'd like to use following control in 3dsmax through Maxscript. I understand this can be done with dotNet.loadAssembly?

When I run this code
dotNet.loadAssembly "C:\\...path...\\XPTable.xml"
dotNet.loadAssembly "C:\\...path...\\XPTable.dll"
xpTable = dotNetObject "XPTable.Table"
hForm = dotNetObject "System.Windows.Forms.Form"
hForm.controls.add xpTable
hForm.topmost = true

I get this error: -- Runtime error: dotNet runtime exception: Invalid directory on URL.

Which is caused by the first line, when I'm trying to load the xml. Am I doing something wrong or is the XPTable.xml corrupted or something?

04 April 2008, 04:37 PM
dotNet.loadAssembly only works with dll files.
Why are you trying to load an XML file as an assembly ?

By the way, this custom ListView control looks pretty good and very interesting.

04 April 2008, 05:13 PM
Its just that the maxscript help file has code like this:

dotnet.loadAssembly "system.xml"
dotnet.loadAssembly "system.xml.dll"

And the release/ folder that came with the custom dotnet control had XML and DLL file, so I though you are supposed to load both of them.

Well only loading the DLL doesn't work either. I get following error msg: -- Runtime error: Cannot resolve type: XPTable.Table

However based on the documentation that is the correct class.

EDIT: Sorry my mistake, the correct class is "XPTable.Models.Table"

04 April 2008, 05:28 PM
should be an excellent control for your project - good luck :)

04 April 2008, 05:33 PM
Well I guess that control doesn't work too well on vista, or at least with max. Adding row crashes always.

dotNet.loadAssembly "XPTable.dll"
xpTable = dotNetObject "XPTable.Models.Table"
xpTable.ColumnModel = dotNetObject "XPTable.Models.ColumnModel"
xpTable.TableModel = dotNetObject "XPTable.Models.TableModel"
xpTable.Height = 200
xpTable.Width = 250
xpTable.ColumnModel.Columns.Add (dotNetObject "XPTable.Models.TextColumn" "Text")
xpTable.ColumnModel.Columns.Add (dotNetObject "XPTable.Models.CheckBoxColumn" "CheckBox")
xpTable.ColumnModel.Columns.Add (dotNetObject "XPTable.Models.ButtonColumn" "Button")
xpTable.TableModel.Rows.Add (dotNetObject "XPTable.Models.Row")

04 April 2008, 05:38 PM
Actually the problem is with 64bit system. Oh well.

should be an excellent control for your project - good luck :)

Yeah I was looking for it mainly because it has spinners. However it doesn't support reordering columns....

I guess I stick to standard dotnet stuff and use DataGridView, it's more suitable for spread sheet editor than ListView.

04 April 2008, 06:38 AM
Its just that the maxscript help file has code like this:

dotnet.loadAssembly "system.xml"
dotnet.loadAssembly "system.xml.dll"

I think you may have been miss reading the help file. system.xml and system.xml.dll are the same file. It's simply demonstrating the different approaches. I believe that the "system.xml" is actually an internal assembly, thus it might not need the extension...

04 April 2008, 08:27 AM
"System.Xml" is an assembly but not an XML file. It contains code for the System.Xml namespace. See the "assembly" directory in the WINDOWS path.
The documentation of dotNet.loadAssembly says first : "This method loads the specified assembly. The assembly can be specified as an assembly name or the filename of the dll containing the assembly."
"System.Xml" is an assembly name. "System.Xml.dll" is the filename of the dll containing the assembly.

04 April 2008, 09:58 AM
Actually the problem is with 64bit system. Oh well.

you might be able to take the source code into VS and recompile for x86 target platform, if that is what is causing the x64 incompatibility. If projects are compiled with the "any CPU" option it will load a 32bit dll into the x64 .net on an x64 system, while working fine on a 32 bit. changing the target platform to this and recompiling has got me round this previously. if you are using VS express, there is no option for this, but you can manually hardcode it into the project prior to compiling.

06 June 2008, 06:55 PM
Was looking for an alternative to DataGridView and I stumbled on to this thread. Very cool control and I was having the same problems of locking up and crashing that Bercon was having. Recompiling the .dll did not provide the magic fix I was hoping for so I created a new application in VS and took a look at the code it was generating. It looks like the missing piece was defining some cells for the info to go into.

dotNet.loadAssembly "XPTable.dll"

table1 = dotNetObject "XPTable.Models.Table";
columnModel1 = dotNetObject "XPTable.Models.ColumnModel";
tableModel1 = dotNetObject "XPTable.Models.TableModel";

row1 = dotNetObject "XPTable.Models.Row";
cell1 = dotNetObject "XPTable.Models.Cell";
comboBoxColumn1 = dotNetObject "XPTable.Models.ComboBoxColumn";

-- table1
table1.ColumnModel = columnModel1;
table1.Name = "table1";
table1.TabIndex = 0;
table1.TableModel = tableModel1;
table1.Text = "table1";
-- columnModel1
columnModel1.Columns.Add comboBoxColumn1;
-- tableModel1
row1.Cells.Add cell1;
row1.ChildIndex = 0;
row1.ExpandSubRows = true;
row1.Height = 15;
tableModel1.Rows.Add row1;
-- comboBoxColumn1
comboBoxColumn1.Text = "DD";
-- Form1
hForm = dotNetObject "System.Windows.Forms.Form"
hForm.Text = ""
hForm.Width = 400
hForm.Height = 300
hForm.TopMost = true
hForm.TopLevel = true
hForm.Controls.Add table1
hApp = dotNetClass "System.Windows.Forms.Application"
hApp.Run hForm

So for what its worth!

01 January 2009, 11:38 AM
<useful code>

Works great, but gives some errors on the properties of row1:

Unknown property: "ChildIndex" in dotNetObject:XPTable.Models.Row
Unknown property: "ExpandSubRows" in dotNetObject:XPTable.Models.Row
Unknown property: "height" in dotNetObject:XPTable.Models.Row

Don't know what you're trying to achieve there, but these are the properties of row1:

.Alignment : <XPTable.Models.RowAlignment>
.AnyCellsSelected : <System.Boolean>, read-only
.BackColor : <System.Drawing.Color>
.Cells : <XPTable.Models.CellCollection>, read-only
.Editable : <System.Boolean>
.Enabled : <System.Boolean>
.Font : <System.Drawing.Font>
.ForeColor : <System.Drawing.Color>
.Index : <System.Int32>, read-only
.RowStyle : <XPTable.Models.RowStyle>
.SelectedCellCount : <System.Int32>, read-only
.SelectedIndicies : <System.Int32[]>, read-only
.SelectedItems : <XPTable.Models.Cell[]>, read-only
.TableModel : <XPTable.Models.TableModel>, read-only
.Tag : <System.Object>

01 January 2009, 12:34 PM
[edit] Asked how to add the XPTable to a rollout, found the answer, which is below (quite simple actually).

To add the XPTable to a rollout instead of running it as an application, create a listview like you would with a normal dotnet listview:

dotNetControl XPTableControl "System.Windows.Forms.ListView"

Then use Dave's code, and add the following code to embed the XPTable into your listview

XPTableControl.controls.add table1

02 February 2009, 08:35 AM
Time to dig the XPTable thread up again (maybe change the thread title and make it into an XPTable discussion?).

Some of the event handlers seem bugged to me. For example, CellButtonClicked: whether I asked for the row or the column, it always returns the column. A possible workaround is to use CellMouseDown to get the clicked row.

Also had problems with the EditingStopped event. This handler is called before the edited value is stored, thus making the handler itself useless.

fn onCellEditStop s e =
print s.text

dotNet.addEventHandler theXPTable "EditingStopped" OnCellEditStop

Whenever I edit a textfield, it prints the old name as soon as I stop editing. I tried using other events to get the cell value, but couldn't find an event that's called everytime editing is stopped. Tried using a dotnet timer, but couldn't get this to work properly.

(In order to use the keyboard in the text fields (instead of triggering shortcuts) use "if not XPTableControl.Focused then XPTableControl.Focus()" in the BeginEditing event handler. Enter won't work, but all other keys do.)

CGTalk Moderation
02 February 2009, 08:35 AM
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.