Retrieving file name?

Tagged: ,

  • Retrieving file name?

    Posted by Amelia Ruddock on August 20, 2024 at 6:13 pm

    Hello! I am new at bluebeam javascripting (and scripting in general) and I am trying to make an interactive stamp for office use. I have a functional script that I have edited from the Revu interactive library but I would like it to autofill parts of the file name. I cannot figure it out for the life of me!! I have attached the script – how would I auto-fill the the first four units of the filename in the “ProjectNo” field? Or just retrieve the filename in general without using the inbuilt “dynamic” feature. There’s more I would like to do but I will keep it at that in hopes that it will lead me to the rest of the answers…. Thanks in advance!

    Amelia Ruddock replied 3 months, 3 weeks ago 4 Members · 8 Replies
  • 8 Replies
  • David Cutler

    Member
    August 21, 2024 at 5:17 am
    Points: 26,769
    Rank: UC2 Brainery Advanced Brown Belt UC2 Brainery Advanced Advanced Brown Belt Rank

    Welcome to the Brainery @ameliarudd96 !

    Hopefully our resident JavaScript expert @lizlarsen will be along to chime in on this….

    • Doug McLean

      Member
      August 21, 2024 at 3:59 pm
      Points: 15,212
      Rank: UC2 Brainery Advanced Blue Belt UC2 Brainery Advanced Blue Belt Rank

      or @isaac-harned

  • Isaac Harned

    Member
    August 23, 2024 at 1:42 pm
    Points: 8,113
    Rank: UC2 Brainery Purple Belt III UC2 Brainery Purple Belt III

    var name = this.documentFileName;

    this.getField(“fieldname“).value = name;

    Alternatively if it needs to be split into multiple outputs it might look something like:

    var name = this.documentFileName;

    var parts = name.replace(“.pdf”, “”).split(“_”);

    var projectNum = parts[0];

    var projectName = parts[1];

    this.getField(“ProjectNo”).value = projectNum;

    this.getField(“ProjName”).value = projectName;

    This of course is if you are using the same identifier to split the Number and name in the doc title, i.e. “_” in this case

    Hopefully this helps, let me know if you have anything else!

    • Amelia Ruddock

      Member
      August 25, 2024 at 9:30 pm
      Points: 253
      Rank: UC2 Brainery Newbie UC2 Brainery Newbie Belt Rank

      Thank you! That’s great – I kinda sorta have it working but the file name is grabbing from the stamp’s file name rather than the document i am inputting into (I should’ve specified this….) what would be the alternative field?

      Also – is there a document where I can find the names of these fields?

      Thanks again!!

  • Isaac Harned

    Member
    August 25, 2024 at 11:03 pm
    Points: 8,113
    Rank: UC2 Brainery Purple Belt III UC2 Brainery Purple Belt III

    Played with this a little more, sorry, haven’t messed with stamps before, it should use an event callout that way it knows which file it’s looking at. Here is an example of the basic submittal approval stamp that’s built in to Revu, but modified to pull that File name. Check out the “getProjectNoFromDocName();” callout and function at the end. Let me know if this works, and if more issues, we may have to see the specific stamp file to help.

    var builder =

    {

    // These map to Text Fields in the Stamp

    textBoxes :

    [

    { field: “Other – Description”, description: “Other – Description:”, default: function() { return “”; } },

    { field: “CheckedBy”, description: “Checked by:”, default: function() { return Collab.user; } },

    { field: “Date”, description: “Date:”, default: function()

    {

    var curDate = new Date();

    return (curDate.getMonth() + 1) + “/” + curDate.getDate() + “/” + curDate.getFullYear();

    }

    },

    { field: “Submittal”, description: “Submittal #:”, default: function() { return event.source.source.documentFileName; } },

    { field: “Project”, description: “Project:”, default: function() { return getProjectNoFromDocName(); } }

    ],

    // This maps to a Radio Group in the PDF named ‘Type of Submittal’

    radioGroup : “Document Type”,

    radioButtons :

    [

    // value maps to the ‘Choice’ of each radio button in the group, description will show on the dialog

    { value: “SubmittalForApproval”, description: “Submittal For Approval” },

    { value: “Resubmittal”, description: “Re-Submittal For Approval” }

    ],

    checkBoxes :

    [

    { field: “Approved” },

    { field: “Rejected” },

    { field: “Revise” },

    { field: “Not Reviewed” },

    { field: “Other” }

    ]

    };

    function getProjectNoFromDocName() {

    var docName = event.source.source.documentFileName; // Access the document name correctly

    return docName.slice(0, 4); // Grab the first four characters

    }

    • Amelia Ruddock

      Member
      August 25, 2024 at 11:26 pm
      Points: 253
      Rank: UC2 Brainery Newbie UC2 Brainery Newbie Belt Rank

      That worked!!! I have been scratching my brain for weeks….. Thank you so much for taking the time to answer 🙂 very exciting for us!

      • Isaac Harned

        Member
        August 27, 2024 at 8:20 am
        Points: 8,113
        Rank: UC2 Brainery Purple Belt III UC2 Brainery Purple Belt III

        No worries, I’m glad it worked out! Not to make myself look like a loser but a lot of my answers come from GPT 🤣 If you guys ever struggle with this, just ask it questions based on “Adobe PDF JavaScript”. There are a few methods that don’t work in Revu, but with a little troubleshooting and back and forth with the bot, but that usually gets me pretty close to what I need.

        • Amelia Ruddock

          Member
          August 27, 2024 at 7:35 pm
          Points: 253
          Rank: UC2 Brainery Newbie UC2 Brainery Newbie Belt Rank

          this loser has been trying with chatGPT and still couldn’t figure it out until you helped… good to know that it runs on adobe because i found zero information RE bluebeam. thanks again!

Log in to reply.