macros that are running javascript

macros that are running javascript

nozby
Advocate Advocate
1,283 Views
7 Replies
Message 1 of 8

macros that are running javascript

nozby
Advocate
Advocate

Hello all,
I was hoping that someone can help me with this:
I have some macros that are running javascript or VBS.
They can be lunch from a regular MAC file like any other macro using a link like this:

 

      pmillhelp url fille:///C:\PM_Macro\test\example.html

 

All macros look pretty much the same. Something like this:

 

html>
<head>
<script language = "javascript">

  var PowerMill = top.external;

      function apply_click() {

         PowerMill.Execute("Do some work",1);

       }

</script>

</head>
<body>

<form>

<input type = 'button' name = 'button' value = 'apply' OnClick = 'apply_click();'/>

</form>

</body>
</html>

 

My problem is that they all need a button to lunch the script, and I can't figure out how do I create something that runs just by lunching the MAC file, which contains the link to that script. In other words, how can I eliminate the button from my programs?
I hope I am explaining my problem clearly enough.

Thank you for your help.

 

0 Likes
Accepted solutions (1)
1,284 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Try this:

<html>
<head>
<script language = "javascript">
  var PowerMill = top.external;
  PowerMill.Execute("MESSAGE INFO 'Javascript running'",1);
</script>
</head>
<body>
</body>
</html>
0 Likes
Message 3 of 8

nozby
Advocate
Advocate

Thank you for your response, but that's what I'm trying to do and somehow can't make it work. Also, the SPLITTER TABBROWSER keeps opening, and I don't know how to prevent that.

0 Likes
Message 4 of 8

Anonymous
Not applicable
<html>
<head>
<script language = "javascript">
  var PowerMill = top.external;
  PowerMill.Execute("BROWSER HOME",1);
  PowerMill.Execute("SPLITTER TABEXPLORE",1);
  PowerMill.Execute("EXPLORER SELECT Workplane 'Workplane\\1p' NEW",1);
  PowerMill.Execute("MESSAGE INFO 'Javascript running'",1);
  </script>
</head>
<body>
</body>
</html>
0 Likes
Message 5 of 8

nozby
Advocate
Advocate

I'm still doing something wrong. I even copied your code just to make sure I got it right. It is not working. 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable
Accepted solution

Sorry, I only tested from the command line, it worked that way, but it doesn't really work from a macro call. Specifically, javascript runs but does not set the PowerMill variable well. To eliminate the problem
I did the following: I downloaded AutoIt v3 https://www.autoitscript.com/site/autoit/  and made it
a script

 

#include-once
#include <WinAPI.au3>
#include <Memory.au3>
#include <WinAPISys.au3>
#include <WinAPIFiles.au3>
#include <MsgBoxConstants.au3>
Local $DropFile=""
If $CmdLine[0] = 0 Then
   $DropFile="c:\temp\test.html"
Else
   $Dropfile=$CmdLine[1]
EndIf
If Not FileExists($DropFile) Then
   MsgBox($MB_SYSTEMMODAL, "Drag&Drop", "File not found -" & $DropFile, 10)
   Exit
 EndIf
 Local $tPointStruct = _WinAPI_GetMousePos ()
 Local $hWndDragDropTarget = _WinAPI_WindowFromPoint($tPointStruct)
 Local $aWindows = _WinAPI_EnumWindows()
 For $i = 1 To $aWindows[0][0]
   If _WinAPI_IsChild ($hWndDragDropTarget, $aWindows[$i][0] ) Then
      $hWndDragDropTarget = $aWindows[$i][0]
	  ExitLoop
   EndIf
 Next
 $tPointStruct = _WinAPI_GetMousePos (True, $hWndDragDropTarget)
 _FileDragDrop($hWndDragDropTarget,$DropFile,DllStructGetData($tPointStruct, "x"),DllStructGetData($tPointStruct, "y"))
Exit
.
.
.

 

that performs a drag & drop operation The original code . This also works well from HTML + javascript macro calls. For security reasons, I uploaded the source code, if you want to try it, compile it.

 

You have to rewrite the file paths, I used the c:\temp folder

0 Likes
Message 7 of 8

Anonymous
Not applicable

Oops! double post

 

0 Likes
Message 8 of 8

nozby
Advocate
Advocate

That help. Thank you.

0 Likes