View Full Version : Access C# .DLL Control?
Kickflipkid687 07-12-2011, 08:16 PM Hey,
I've started getting into C#, and have started learning how to implement it into 3ds max.
I found a thumbnail tool I want to modify/use, and I have been able to compile it and load the .dll and UI in Max just fine. It works just the same in max as it does in VS or as a standalone.
So, now I am wondering how I might be able to access a control in my dll/dotnetcontrol so I can possibly feed it a folder location, or preferrably, an array of image paths.
In my MainForm, I have a
privateThumbnailController m_Controller;
in a Public MainForm() function(?) I have
m_Controller = new ThumbnailController();
m_Controller.OnStart += new ThumbnailControllerEventHandler(m_Controller_OnStart);
m_Controller.OnAdd += new ThumbnailControllerEventHandler(m_Controller_OnAdd);
So my question is, in max can I do something like,
m_Controller.AddFolder("PATH");
I'm showing my UI in max right now by making a rollout, then doing
dotNetControl tib_control "marlie.TumbnailDotnet.mainform" pos:[0,0] width:651
height:542
then for the Rollout Open, I just do tib_control.show()
Hopefully that make sense....
Thanks!
|
|
denisT
07-12-2011, 09:25 PM
you have to add ThumbnailController to rollout (not mainform):
dotnetcontroller tib_control "marlie.TumbnailDotnet.ThumbnailController" pos:[0,0] width:651
height:542
and on rollout open event call AddFolder method:
on <rollout> open do (tib_control.AddFolder "PATH")
Kickflipkid687
07-12-2011, 11:02 PM
When I try to add the controller and not the mainform, I get an system exception...?
dotnet.loadassembly "C:\Program Files\Autodesk\3ds Max
2011\marlie.TumbnailDotnet.dll"
rollout textureinfobrowser_rollout "TextureInfoBrowser"
width:651 height:542
(
--dotNetControl tib_control
"marlie.TumbnailDotnet.mainform" pos:[0,0] width:651 height:542
dotnetcontrol tib_control "marlie.TumbnailDotnet.ThumbnailController"
pos:[0,0] width:651 height:542
on textureinfobrowser_rollout open do
(
tib_control.show()
--setDialogpos
textureinfobrowser_rollout [0,0]
destroydialog
textureinfobrowser_rollout
--tib_control.m_Controller.AddFolder("C:\Users\a-malich\Desktop\Textures\\");
)
)
createdialog
textureinfobrowser_rollout style:#(#style_resizing, #style_titlebar,
#style_border, #style_sysmenu)
Edit:
privateThumbnailController m_Controller;
Would that be why? Should I make a public function to allow access to it, in the main form?
Edit:
So I tried doing
dotNetControl tib_control
"marlie.TumbnailDotnet.m_Controller" pos:[0,0] width:651 height:542
on textureinfobrowser_rollout open do
(
--tib_control.show()
--setDialogpos
textureinfobrowser_rollout [0,0]
destroydialog
textureinfobrowser_rollout
tib_control.AddFolder("C:\Users\a-malich\Desktop\Textures\\");
)
Which then said
---------------------------
MAXScript Rollout Handler
Exception
---------------------------
-- Unknown property: "AddFolder" in
dotNetControl:tib_control:(null)
---------------------------
OK
---------------------------
Kickflipkid687
07-13-2011, 03:35 PM
I tried something here a programmer recommended, which was to make a public function in the mainform.cs and it worked :)
I did,
public void mControllerFolder(string folderPath)
{
this.flowLayoutPanelMain.Controls.Clear();
m_Controller.AddFolder(folderPath);
this.buttonCancel.Enabled = true;
this.buttonBrowseFolder.Enabled = false;
}
Then in Max, I did
dotNetControl tib_control
"marlie.TumbnailDotnet.mainform" pos:[0,0] width:651 height:542
on textureinfobrowser_rollout open do
(
tib_control.show()
tib_control.mControllerFolder("C:\Users\a-malich\Desktop\Textures");
destroydialog
textureinfobrowser_rollout
)
Now I just need to find out if I can somehow take an array of image paths and put them into a folder for my code to read. I don't want to copy the images to a temp folder.
The code reads images from a folder right now, so that it can send the folder as a backroundworker I believe. I'm not sure if I could feed in an array of image paths instead? I guess its the same thing, but I'm not sure.
private void AddFolder(object folderPath)
{
string path = (string)folderPath;
if (this.OnStart != null)
{
this.OnStart(this, new ThumbnailControllerEventArgs(null));
}
this.AddFolderIntern(path);
if (this.OnEnd != null)
{
this.OnEnd(this, new ThumbnailControllerEventArgs(null));
}
CancelScanning = false;
}
private void AddFolderIntern(string folderPath)
{
if (CancelScanning) return;
// not using AllDirectories
string[] files = Directory.GetFiles(folderPath);
foreach(string file in files)
{
if (CancelScanning) break;
Image img = null;
try
{
img = Image.FromFile(file);
}
catch
{
// do nothing
}
if (img != null)
{
this.OnAdd(this, new ThumbnailControllerEventArgs(file));
img.Dispose();
}
}
Edit: Sorry for the horrible formatting... stupid copy/paste
Kickflipkid687
07-13-2011, 06:46 PM
Ok, so the same guy here wrote a couple functions quick for me to support a string array.
Then in my mainform I had to add
public void AddFiles(string[] files)
{
m_Controller.AddFiles(files);
}
So now in max I can just do,
tib_control.show()
local stringArray = #()
stringArray = #("C:\Users\a-malich\Desktop\Textures\1266801488.jpg","C:\Users\a-malich\Desktop\Textures\Carpet0020_2_S.jpg")
tib_control.Addfiles(stringArray)
CGTalk Moderation
07-13-2011, 06:46 PM
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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.