[Closed] Maxscript, SDK and .NET
Out of curiosity… have you considered not loading 10,000 or 1,000 or even 100 objects into the list?
It would be nice if you could, but let’s face it – the user can’t display 100 lines on screen as it is (okay, those running at 2560×1600 could).
So perhaps you can just chunk it up into N items maximum at a time, and let any unloading/loading happen dynamically (based on the scrollbar position or… who knows what).
ypuech, it uses 100% of one core and does nothing.
ZeBoxx2, yeah I thought about that. I guess I’ll give it a try, it might give annoying delay when scrolling since its all running on the same thread (I think).
One option is to do everything with SDK and .NET but it would mean a lot more work not to mention making changes and customizing the thing would be a pain.
Okey I finally found a way to do it. Maxscript -> SDK -> .NET. However its still pretty slow, and the time to update single cell seems like O(n^2). It also hangs when there are >2000 cells or something like that. Anyways, here are the functions:
#pragma managed
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System::Windows::Forms;
namespace BerconExplorer {
void managedUpdateColumn(int handle, int index, char** arr, int length) {
System::Windows::Forms::Control ^ cont = gcnew System::Windows::Forms::Control();
DataGridView ^ dGW = (DataGridView ^)cont->FromHandle(System::IntPtr(handle));
for (int i = 0; i<length; i++)
dGW->Rows[i]->Cells[index]->Value = gcnew System::String(arr[i]) ;
}
}
#pragma unmanaged
#include "definsfn.h"
def_visible_primitive(BerconExplorer, "BerconExplorer");
using namespace BerconExplorer;
Value* BerconExplorer_cf(Value **arg_list, int count) {
check_arg_count(BerconExplorer, 3, count);
int handle = arg_list[0]->to_int();
int index = arg_list[2]->to_int();
Array* nameArr = (Array *)arg_list[1];
int length = nameArr->size;
char** stringArr = new char*[length];
for (int i = 0; i<length; i++)
stringArr[i] = nameArr->data[i]->to_string();
BerconExplorer::managedUpdateColumn(handle, index, stringArr, length);
return &ok;
}
That’s a good try Jerry.
But, is DataGridView cells number limited ?
Have you tried to use dGW->Rows->Add() instead of dGW->Rows[i] ?
I create the rows before calling that update. Its kinda weird that the code I posted is actually slower than doing it maxscript, or doing it using the assembly you made. I’m not really sure why. I do have two conversions, first from maxscript string to char* and then to .NET String. But I think thats unavoidable and it shouldn’t really be THAT slow.
Anyway, the correct way to work here would probably be using DataGridView in virtual mode, so it’d only update the shown values. I’ll have to check out how well that works out.
Okey, I tried the virtual mode and all I can say is WHOA. Its very fast, without any lag even with 10 000 objects.
I also studied what was actually slow in the SDK function. It turns out that reserving memory for new string takes ages! Meaning the gcnew System::String(“Hello”).
Anyway I wont be needing that any more since using the Virtualmode (only updating the displayed cells) is so much faster.
Thanks for everybody for support.
Hi Bercon,
i’m struggling with a listview. I want it to display a nodeselection (name and wirecolor). It’s rather slow when selecting large numbers of nodes. I also stumbled across the virtualmode for the .net listview. But i’m having trouble understanding it.
I’m able to display my testItems in the listview using the virtualmode, like so:
lvPreview = dotNetObject "listview"
lvPreview.virtualmode = true
--the virtualListSize gets set through a callback
--so i'm always getting the correct amount of listviewItems
--in this example i'll just use an arbitrary number
lvPreview.virtualListSize = 26
--the event handler function
function fn_createVirtualItem control arg =
(
newItem = dotNetObject "listViewItem" "myTestItem"
newItem.subItems.add "theSub"
arg.item = newItem
)
dotNet.addEventHandler lvPreview "RetrieveVirtualItem" fn_createVirtualItem
So i’m just creating a certain amount of listviewItems which are the same. Could you help me with creating each listviewItem to display the name and wirecolor of each selected object? Somehow i need to get into that eventHandler function and change the properties of the listviewItems, but i don’t see how.
Klaas