by Jonathan D. Kriek, May 11, 2015

Autodesk PLM 360: The Scripting Librarian

Back to Blog

plm360_2015

Library scripts are designed to enable reuse of code and eliminate repetitive programming tasks. Today we’ll look at creating a library script to notify all users of a group without specifying each user or email address, creating a new item in a separate work space using out of the box library scripts, and then creating a new task for that item – all wrapped up in a single action script.

Library Script Creation

  1. Navigate to Administration > System Configuration > Scripting
  2. Click on “New Script”
  3. Under Script Type choose “Library”
  4. Under Unique Name type NotifyGroup

We’re now going to create a function that accepts three arguments: 

groupName: The user group to be notified

eSubject: The subject of the email being sent

eBody: The body of the email being sent

library


/* Email Users in Group */
function notifyGroup(groupName, eSubject, eBody) {

    // assign arguments to vars
    var email = new Email();
    email.subject = eSubject;
    email.body = eBody;

    // get all users from group
    var users = Security.listUsersInGroup(groupName);

    // email each user in group
    for(var index in users) {
        email.to = users[index].email;
        email.send();
    }
}


Click “Save and Close”

Action Script Creation

Now that we have a library script, let’s create an action script to call it:

  1. Click on “New Script”
  2. Under Script Type choose “Action”
  3. Under Unique Name type escalGroup
  4. Under “Imports” click the [+] Plus button and select NotifyGroup and createNewItem

We now have a reference to the NotifyGroup library script we created as well as an out of the box Library script called createNewItem. Take a look at the createNewItem script for it’s arguments.

Note: I’m using a custom group called “MGMT” and a custom workspace with ID of WS_ESCALATIONS and properties ESC_TITLE and ESC_DESC, you’ll either need to create these or change these values to suit your setup.

action


/*
assign current item
props to vars
*/
var number = item.NUMBER;
var title = item.TITLE;

/*
send email to group users
using our new Library script
*/
var msg = 'New escalation request for ';
var body = msg + number + ' : ' + title;
notifyGroup('MGMT', 'Escalation Approval Needed', body);

// Create Item in escalation Workspace
var wsProps = [];
wsProps.ESC_TITLE = number + ' : ' + title;
wsProps.ESC_DESC = 'Escalation Request';
var newItem = createNewItem('WS_ESCALATIONS', wsProps);

    // Create Task on item
    if (newItem !== null){
        newItem.project.addTask('Approve Escalation');
    }


Setup The Action Script 

  1. Navigate to Administration > Workspace Manager 
  2. Select the workspace(s) you want to call the script FROM
  3. Choose “Behaviors”
  4. For this script I’ve chosen Script to run on demand and selected escalGroup

workspaceSetup

Call The Action Script 

  1. Navigate to the workspace you chose in the last step.
  2. Click on an item
  3. Click the run icon in the top right corner (see below)

scriptRun

The Results 

  • An email was sent to all members of the group
  • An item was created in a separate workspace 
  • A task was assigned to the new item

email

newItem

task

Final Thoughts 

I hope this was useful to you in your PLM 360 scripting! Library scripts certainly make automation much easier in this environment. I love to see what others are doing with this amazing platform, so please share and stay tuned to Side Note.

If you have ideas on how to improve the product then check out the IdeaStation and submit!

PLM 360 IdeaStation

ideastation

Back to Blog

2 Replies to “Autodesk PLM 360: The Scripting Librarian”

Leave a Reply

Your email address will not be published. Required fields are marked *

More stories from KETIV

Blog

KETIV Technologies and ANSYS Partner to Bring Advanced Simulation Solutions to the Manufacturing Industry

               FOR IMMEDIATE RELEASE: BREA, CA, September 19, 2018 – KETIV, a premier engineering solutions provider and expert manufacturing consultant since 1983, has announced its partnership with ANSYS. KETIV and ANSYS, a global leader…

Read post
Blog

Creating a Rivet Hole Chart in Autodesk Inventor

In my adventures taking aircraft maintenance classes at Mount San Antonio College, I’ve learned a lot of things. Not the least of which, is how much I have to learn! Another piece of knowledge I’m grateful for, is how to drive and set…

Read post