Home Technical Talk

Communication javascript and maxscript

Hey all,

I wanted to ask if it would be possible to send some kind of data from a javascrip to a maxscript.

I am just checking on something with javascript in photoshop. And if the condition would be true, it would send a integer or bool to 3ds max. So a script that I wrote would know that he has to call a function.

My first thought was to change the filename of the psd with the javascript. That file will be checked by 3ds max and if there is a change in the filename, then he will call the function.

Is this a good idae or is there a better way?

Greetz

Replies

  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    sorry for the late reply,-

    although I have not yet been experimenting with communication between MS and JS or html through ports/ sockets or with the help of additional tools - I was able to communicate more or less with an embedded html / JS within max.

    it requires though that the html or JS file that is used is run within max - which might make it unattractive for you.


    so on the maxscript side I used this (stripped down version):
    clearListener();
    try(destroydialog rFlash);catch()
    rollout rFlash "MZP/rs 64" width:540 height:600(
    	-------------------------------
    	dotNetControl web "System.Windows.Forms.WebBrowser" pos:[0,0] width:120 height:220 	dotNetControl exec "System.Windows.Forms.Textbox" pos:[0,0] visible:false --hidden textbox that will hold commands passed from javascript
    	-------------------------------
    	on rFlash open do( 
    		web.ScrollBarsEnabled = dotnetobject "System.Boolean" false;--no scrollbars!!
    		web.ObjectForScripting = exec;
    	)
    	---------check if the html document ("ObjectForScripting") has been changed---------------
    	on exec TextChanged e do( --once we get a command, execute it. Don't try this at home.
    		local elements = filterString (exec.text) "#";
    		
    		if (elements.count >= 2)then(--single element
    			local code  = elements[1] as string;
    			code = findAndReplace code "'" """;--just to be sure
    			
    			try(
    				execute code;
    				print("execute: "+code);
    			)catch(
    				format "could not execute:n% n" code;
    			);
    		)
    	)
    	-------------------------------
    	on rFlash resized size do(
    		web.size = dotnetobject "System.Drawing.Size" size[1] size[2];
    	)
    )
    --fromMaxScript
    CreateDialog rFlash 120 220 pos:[320,100] style:#(#style_titlebar,#style_resizing,#style_sysmenu,#style_toolwindow);
    

    and the html file was:
    <html>
    <head>
    <script>
    //maxscript functions
    function fromMaxScript(){
    	alert('received: '); 
    }
    function toMaxScript(codeString){
    	var time = new Date();
    	window.external.text=codeString+"#"+String(time.getTime());//add a unique timestamp at the end
    }
    </script>
    </head>...
    
    in my case I used Flash as middleware and called the toMaxScript method each time I wanted to send maxscript commands to maxscript and execute them there.

    Right now communicating back is not yet solved (sending from max back to the html/JS/flash but there are workarounds for that like writing to the disc or some other things.


    before I confuse you perhaps even more, before I used the above example it worked perfectly for me using ActiveX within 3dsmax to embed flash movies and communicate back and forth between the 2. However microsoft stopped activeX support for their newer operation systems (64 bit anyway, and Vista + win7 as well) - so thats not available for 64 bit operation systems anymore.
    Which is why I was forced to work with a dotNet control (the System.Windows.Forms.WebBrowser) and try to work my way through that even though documentation and examples for that are very rare.





    another way of communicating between Photoshop (cs4+) and 3dsmax might be using flash and their local connection ability:
    http://www.flashwonderland.com/communication-between-flash-movies.html
    because the way you call commands booth in Photoshop and Max is similar using the navigateToURL (as3, in as1+2 it was getURL(...)), e.g:
    v
    ar script:String = "functionName("" + "parameters"+ "");";
    			var myURL:URLRequest = new URLRequest("javascript:" + script + "");
    			navigateToURL(myURL,'_self');//
    

    with the ability in PS cs4 to embed custom panels using the SWF format you could use Flash as the communicator between the 2 applications and still execute javascript on the PS side.
  • Nysuatro
    wow. Thank you very much. This is very helpfull
Sign In or Register to comment.