[Closed] DotNet Drag Drop File Operation
hello,
If you need to mimic the way that max presents you with merge/open/xref options when you drag into a viewport, you can perform this yourself with DotNet. Max expects a dataobject containing a string array. Depending on the contents of this array will depend on whether max will prompt you with a file open menu, or a texturemap as viewport background. You can also pass a map to drag onto the material editor.
I though i’d share the method as there are a few recent posts about asset browsers, i would have thought that it would be useful for this sort of application.
get the file here –
Very nice, I wanted to do more poking at that for up coming tools so thanks.
well now that looks fun, but for some reason I had to change line 20 to read
dropfile.set 0 filenameString
--instead of
--dropfile.setvalue filenameString 0
which kept returning the error:
>> MAXScript Rollout Handler Exception: – Runtime error: No method found which matched argument list <<
even though setvalue was showing the .SetValue <System.Object>value <System.Int32[]>indices in the showevents list?
I’m using max2008 here.
Hi Dave,
you’re right, It works fine in 2009 but i get an error in 2008. Can you post your working max 2008 code?
it must be something they have fixed between versions. if i explicitly define integer and string classes for 2008 it works again. think i might have read something about this issue before with max and its automatic dotnet/mxs conversion with strings.
rollout DragDropOps "LoneRobot Drag Drop" width:136 height:150
(
dotNetControl btndragdrop "label" pos:[5,5] width:125 height:139
on DragDropOps open do
(
btndragdrop.text = "Hooray! A Drag/Drop Enabled Label!!!
To drop a Texturemap, just pass the map path string in the dataobject instead of a max file path. This will also work if draging a map to the material editor"
btndragdrop.borderstyle = (dotNetClass "System.Windows.Forms.BorderStyle").fixedsingle
btndragdrop.backcolor = (dotnetclass "System.Drawing.Color").orangered
btndragdrop.forecolor = (dotnetclass "System.Drawing.Color").yellow
)
on btndragdrop mouseDown sender args do
(
theIniFile = getdir #maxData + "3dsmax.ini"
theKeys = getIniSetting theIniFile "FileList"
maxfilearray = for o in theKeys where o != "MaxFiles" collect getIniSetting theIniFIle "FileList" o
intnum = dotnetobject "System.Int32" 0
filenamestring= dotnetobject "System.string" maxfilearray[1]
dropfile = dotnetobject "System.String[]" 1
dropfile.setvalue filenamestring intnum
DataObj = dotnetobject "DataObject" ((dotnetclass "DataFormats").filedrop) dropfile
sender.dodragdrop Dataobj ((dotnetclass "DragDropEffects").Copy)
)
)
createdialog DragDropOps style:#(#style_toolwindow, #style_sysmenu)
actually the 2008 compatible version also works in 2009, so i guess i will just update the link with that one.
Ah so all you have had to do is create dotNetClass string and int values for it to work? That is good to know and maybe I should be testing code that I do in 2009 to make sure that what I have will continue to function.
I had thought after reading the help that MXSdotnet should convert mxs types like integer and string to their dotnet object equivalents. However, this doesnt appear to be happening in 2008. I will have to update some code i am currently writing to reflect this too.