# Playground

## Overview

This web page does NOT use WebLink! ;)

ANY LANGUAGE could be used to automation Creo with CREOSON using JSON Transactions via HTTP Post!

You can roll your own, or use already available libraries.

Here are some popular options:

- Python - CREOPYSON
- JavaScript / Node.JS - Source in Directory --> creoson/web/assets/creoson_stuff/creoson_js

This page uses the CREOSON JavaScript Library to make JSON requests (using jQuery and AJAX from the Web Browser) to the already running your CREOSON micro-Server.

The CREOSON micro-Server actually executes the JLINK requests into the CREO Parametric Kernel, waits for the Kernel's response, then responds with a JSON Response.

These operations can be executed locally -OR- remotely over a network from other applications!

Give it a TRY!

If you get stuck - or this page is not working... please let us know!

## Get a sessionId

The first thing you must do is establish a connection to the CREOSON JSON Server, once you have successfully connected, you will get a 'sessionId'.

The sessionId value must be included in ALL subsequent calls/requests to CREO via CREOSON.

    let sessObj = new creo.ConnectionObj();

    sessObj.connect();

## Play with some Code!

Just make some recommended changes in the code below and press the Execute Button!

This assumes your current Working directory (or workspace); and can retrieve models from Windchill if connected.

NOTE: Many of the CREOSON commands support *wildcards* as options! (see function help)

    let fileObj = new creo.FileObj();

        fileObj.file = 'test.prt';  //  <<-- ENTER CREO FILE and EXTENSION

        fileObj.display = true;          // true / false
        fileObj.activate = true;         // true / false

        // TRY DIFFERENT COMMANDS
        //  replace the .open() with one of the following...
        //  --> .massprops()
        //  --> .has_instances()
        //  --> .get_mass_units()
        //  --> .get_cur_material()
        //  --> .get_fileinfo()
        //  --> .regenerate()
        //  --> .erase()

        fileObj.open();

JSON Request
JSON Response

## Get some Parameters!

Just make some recommended changes in the code below and press the Execute Button!

This assumes that your model(s) are currently in-session within Creo.

NOTE: THIS is an super flexible function! :)

    let paramObj = new creo.ParameterObj();

        paramObj.file = '*.prt'; //  <<-- ENTER CREO FILE and EXTENSION (can be wildcard)

        paramObj.name = 'DESC*'     // Parameter 'name' within a Model / Drawing to find  (can be wildcard)
        paramObj.value = '*'        // Parameter 'value' within a Model / Drawing to find  (can be wildcard)

        paramObj.list();

JSON Request
JSON Response

## Batch Example

This example demonstrates that you CAN easily create your own batch execution processes with CREOSON.

NOTE: You can enter wildcard values for model/drawing names / extensions as a test. :)

    function processItem(itemName) {

        let fileObj = new creo.FileObj();
        fileObj.display = true;
        fileObj.activate = true;
        fileObj.file = itemName;

        return fileObj.open();

    }

    function batchFiles () {

        let creoObj = new creo.CreoObj();
        let creosonUtilObj = new creo.CreosonUtils();

        creoObj.filename = "*.drw";  // <<-- ENTER CREO FILE (*) and EXTENSION

        creoObj.list_files()
            .then(function (respObj) {
                return creosonUtilObj.loopItems(respObj.filelist, processItem)
            })
            .then(function () {
                alert("Finished Batching!");
            })
            .catch((err) => {
                alert('ERROR: '+err);
            });

    }

    // START THE BATCH PROCESS!
    batchFiles();

### Awesome Creo Automation Apps!

#### Automate w/ Excel!

Download

#### BOM Automation!

Download

#### Pro/PROGRAM

Download