Results 1 to 6 of 6

Thread: JavaScript: Add new menuitem in Acrobat 5.0 [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Exclamation JavaScript: Add new menuitem in Acrobat 5.0 [Resolved]

    I am having trouble getting this script to run. I have it entered at
    the Document level and I need to know where its going wrong.
    Code:
    function APD_Menu(){
     app.addMenuItem({cName: "Save to Working dir...", cParent: "File", cExec: "app.alert("Save to Working directory!");",cEnable: "event.rc = (event.target != null);",nPos: 0});
    }
    When I try to call my function it gives the error - "SyntaxError: syntax error undefined"

    Any ideas or suggestions?
    Thanks in advance for any help on this.
    Last edited by RobDog888; Sep 25th, 2003 at 04:24 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This is working so far.
    Code:
    function APD_Menu(){
    app.addMenuItem({ cName: "Save to Working Dir...", cParent: "File", cExec: "app.alert(this.path)", cEnable: "event.rc = event.target != null",nPos: 7});
    }
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    "app.alert("Save to Working directory!");",
    Try masking the inner quotes:
    "app.alert(\"Save to Working directory!\");",
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I finally got it to add the menu item and execute some code.
    Now I just need to see if I can get it to prompt for verification
    before the saveas and handel the response.
    Global.WorkingDir is a global static variable that I setup in
    another script to contain the absolute path.
    Code:
    var sPos = "5";
    
    app.addMenuItem({cName: "Save to Working Dir...", cParent: "File", cExec: "var aDocs = app.activeDocs; var myForm = aDocs [0]; myForm.saveAs(global.WorkingDir + 'Test.pdf');" , nPos: sPos});
    How do I get a function to return a value so I can embed the
    function call into the addMenuItem call?

    I can use that to determine if the file is to be saved or not.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Just add a return statement? Or is there any specific reason why this wouldn't work?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is the update that is working.
    Code:
    var sPos = "5";
    
    app.addMenuItem({cName: "Save to Working Dir...", cParent: "File", cExec: "event.rc = SaveWorking() != 2", cEnable: "event.rc = TypeOfDocSave() != 0", nPos: sPos});
    
    function TypeOfDocSave() {
    
      var d = this.info;
      var sTitle = d.Title
      var sGood = sTitle.indexOf("APD");
    
      if (event.target == null) {
        return 0; 
      }
      if (sGood == "0") {
        return 1;
      }
      else {
        return 0;
      }
    }
    
    
    function SaveWorking() {
    
      var cResp = app.alert('Save to - ' + global.WorkingDir + 'Test.pdf',2,1);
    
      if (cResp == 1) {
        app.alert('Saving to - ' + global.WorkingDir + 'Test.pdf',3,0);
        this.saveAs(global.WorkingDir + 'Test.pdf')
        return 1;
      }
      if (cResp == 2) {
        app.alert('Canceled',1,0);
        return 2;
      }
    }
    This will only be enabled and execute if the document has "APD" in the title.
    If there are other documents opened, when switched to them the menu item is disabled!

    I still need filename generation code for this part of my prject to be complete.
    Review my other thread for the details, please.

    Any ideas?


    Thanks for the assistance.
    Last edited by RobDog888; Sep 25th, 2003 at 04:23 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width