i-drop - drag and drop

Topic: version 4 MAXScript New Features/i-drop - drag and drop

i-drop drag-and-drop support in MAX allows i-drop-encapsulated files, scripts and texturemaps to be dragged from web pages directly onto a MAX viewport, toolbar or menubar.

Example:

Here is a simple HTML file containing a single i-drop active-X control that represents a MAX file that can be dropped into a MAX viewport. The HTML refers to an XML file containing details about the MAX file to drop. The image proxy, XML file and .max file names specify files on a local G: drive, you will have to adjust these for your setup.

HTML:

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Author" content="Your Name">

<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">

<title>example</title>

</head>

<body>

Here is an i-drop activeX control ....

<p>

<object name="idrop" width="64" height="80" classid="clsid:AF2880B4-B183-11D2-

ADE7-00A0245D8F3F">

<param name="package" value="file:///G:/iDrop/example.xml">

</object>

</body>

</html>

The XML package file:

<?xml version="1.0"?>

<package xmlns="x-schema:http://vizdevel/idrop/idrop-schema.xml">

<proxy defaultsrc="file:///g:/idrop/blob.gif">

<caption>i-Drop it!</caption>

<img src="file:///g:/idrop/blob.gif"/>

</proxy>

<dataset>

<datasrc clipformat="CF_IDROP.MAX">

<datafile src="file:///g:/idrop/foo.max"/>

</datasrc>

</dataset>

</package>

Drag-and-Drop Manager

Interface: dragAndDrop

A new type of datasrc file in an i-drop XML file can be specified that contains a macroScript with drag-and-drop handlers that will be run when you drag and drop the i-drop control onto a MAX viewport. These new kinds of files are called 'drop scripts' and have the suffix .ds . Such files should contain a single macroScript definition with handlers for one or more of the special dropscript events. If there is more than just a single macroScript in the .ds file, all other text is ignored.

Here is a sample XML specifying a dropScript file called "foo.ds":

<?xml version="1.0"?>

<package xmlns="x-schema:http://vizdevel/idrop/idrop-schema.xml">

<proxy defaultsrc="file:///g:/idrop/blob.gif">

<caption>i-Drop Script!</caption>

<img src="file:///g:/idrop/blob.gif"/>

</proxy>

<dataset>

<datasrc clipformat="CF_IDROP.MAX">

<datafile src="file:///g:/idrop/foo.ds"/>

</datasrc>

</dataset>

</package>

dropScript Events

The current dropScript events are delivered as a mixture of positional and keyword parameters. The first parameter is positional and is always the code name for the window on which the drop is currently occurring. Subsequent parameters are keyword parameters that vary in name and number depending on the window being currently dragged over or dropped on.

on droppable <window> node: point: do ...

on drop <window> node: point: do ...

<window>

a window identifier

node:

any item (scene node) currently under the mouse pointer

point:

If supplied, the 'droppable' handler is called continuously while the i-drop control is dragged over the MAX viewport, and should return true or false depending on whether the item is droppable at that position. If the mouse is not over a scene node, the <item> argument value is undefined. You implement the 'droppable' filter if the dropScript wants to limit droppability in any way.

The 'drop' handler is called when the user finally drops the i-drop control over a viewport and is given the same parameters as 'droppable'.

For example, currently for viewport windows, the full signatures are:

on droppable window node: point: do ...

on drop window node: point: do ...

but since keyword arguments are optional, you can choose any subset of the keyword arguments you need, such as:

on drop window node: do ...

or

on drop window do ...

Passing by keyword like this allows different context windows to supply a variable and large range of context info without requiring an unwieldy and fixed set of positional args.

Example:

Here is a sample 'foo.ds' file.

macroScript foo

(

on droppable window node: return

window == #viewport and

node != undefined and

classOf node == sphere

    

on drop window node do

(

node.scale *= 1.2

node.material = meditmaterials[1]

)

)

The droppable handle only allows dropping when the mouse is over a sphere scene node. When dropped, that sphere will be scaled up by 1.2 and be assigned the material currently in slot 1 in the material editor.

Dropping .max files from the Windows desktop

Behavior is handled differently depending on whether you drop the file on a viewport or anywhere else in the MAX UI. If you drop a scene file on a viewport, the file is MERGED. If you drop elsewhere, such as on the toolbars or menu bar, the file is OPENED, closing the currently open file.

When dropping .max scene files onto a MAX viewport, either from i-drop-enabled web pages or directly from file directories, the Merge/XRef/Cancel pop-up menu that is displayed now includes an Open item, which will perform a complete file open, replacing the currently open scene.

Note: Dropping .max scene file anywhere onto the MAX UI outside viewport will automatically perform a scene open.

Dropscripts from Toolbars

dragging-and-dropping dropScripts from the MAX toolbars is possible. DropScripts are simply macroScripts with 'on drop' and optionally 'on droppable' handlers, as defined above. If a macroScript button on a toolbar has an 'on drop' handler defined, you can drag that button off the toolbar to initiate dropScript drag-and-drop.

Example:

Here's a simple dropScript that applies a newly created brick material to the object that it is dropped on. Note that it also has an 'on execute' handler that does the same thing to the current selection. By providing both 'on drop' and 'on execute' handlers, you can make such a macroScript installable in menus, hotkeys and toolbars or droppable from toolbars, the web, etc.

macroScript dropBricks category:"DropScripts" Icon:#("MAXScript", 3)

(

on droppable window node: return

window == #viewport and node != undefined

    

on drop window node: do

node.material = standard diffuseMap:(bricks()) showInViewport:true

    

on execute do if selection.count == 1 then

$.material = standard diffuseMap:(bricks()) showInViewport:true

)

Note the use of the newly-added 'showInViewport' property on materials.

Drag-and-Drop script files

Drag-and-drop MAXScript Zip files

See also Zip-file Script Packages

The OLE-based drag-and-drop system in MAXScript accepts the dropping of MAXScript .mzp zip packages. They can be dropped either from i-drop-enabled web pages or directly from file directories, say from the Windows Explorer or the new MAX Asset Browser.

The main use for this feature is to allow script packages to be dropped into MAX and automatically run, particularly packaged dropScripts. But, since the package can contain files of any kind, it is possible to use it to drop any set of files, say a scene file and its maps & other supporting files, or a new plug-in, etc. The mzp.run control file allows you to set up arbitrary distributions of the files in the package using the extract to, copy and move commands. This can be a useful alternative to the current i-drop package-dropping mechanism, which simply places all the downloaded files listed in the i-drop to the MAX downloads directory.

.mzp drop protocol

When a .mzp package is dropped, the sequence of events that occurs differs slightly, depending on whether it is dropped via an i-drop control or directly from a file directory. In summary, the i-drop first downloads the package and then extracts it, dropping from a file directory extracts directly from that file. Further, the 'on droppable' handler in any dropScript specified in the package is only run if the package is droped via a i-drop, dropping from a file directory is a system-controlled action that doesn't provide any drag-over callbacks in which to run the 'on droppable' test.

From an i-drop, the .mzp file is first downloaded to the <max>\downloads directory, along with any other files specified in the i-drop XML file, overwriting any files currently there. If the .mzp file is the first file in the i-drop file set, it is the prime dropped file and the following .mzp processing continues. The .mzp file is then extracted to a new temp directory, in the system's main TEMP directory, and the mzp.run control file is run. If there is no mzp.run file in the package, the first file in the .mzp package is dropped, causing whatever drop protocol is appropriate for that file type. If supplied, a typical mzp.run control file will contain extract to, move and copy commands to control the disposition of the files extracted from the package, say placing any texture files in $maps & scene files in $scenes, etc.

During this execution of the mzp.run file after initial load, all copies and moves are performed, and a 'drop' command is looked for. The file specified on the drop command is remembered for later drop processing. Any 'run' commands are ignored.

At this point, the drop file is known, either because it was supplied on a 'drop' command in the mzp.run file or because it is the first file in the .mzp package if there was no mzp.run file or drop command. If the drop file is anything other than .ds dropScript file, the drop protocol appropriate to that file is engaged. If it is a .ds dropScript, and the drop is from an i-drop, any 'on droppable' handler in the dropscript is repeatedly run as the mouse is moved off MAX's windows, and the cursor changes to show valid drop targets. If the drag-and-drop is from a file directory, the arrow+ cursor shows, but the 'on droppable' handler is NOT called. This is a consequence of the limitations of simple file drag-and-drop in Windows. When the mouse-click is released, the 'on droppable' handler is called on the target window and object and if it returns OK or is not supplied, the 'on drop' handler is called. This protocol is identical to dropping .ds dropScript files directly, as if they were not inside a .mzp package.

Note: you can specify a file type other than a dropScript on the 'drop' command, such as an image or scene file. This allows the .mzp drag-and-drop to be used for dropping any kind of package, not just scripts.

See also