Skip to content

Commit

Permalink
Merge branch 'release/0.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
petrbroz committed May 30, 2019
2 parents ed1991f + 77e15cf commit 1e0e876
Show file tree
Hide file tree
Showing 18 changed files with 828 additions and 449 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
language: node_js
node_js:
- '10'
script: npm run build

before_install:
- sudo add-apt-repository ppa:duggan/bats -y
- sudo apt-get update -y
- sudo apt-get install bats jq -y

script:
- npm run build
- npm link
- bats tests

deploy:
- provider: npm
Expand All @@ -12,7 +21,7 @@ deploy:
- provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file: bin/*
file: bin/*.zip
skip_cleanup: true
on:
tags: true
113 changes: 80 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,113 @@ Command line tools for Autodesk Forge services.

[![asciicast](https://asciinema.org/a/244057.svg)](https://asciinema.org/a/244057)

## Usage
## Installation

### Using npm

- install the library, either in your own npm project (`npm install --save forge-cli-utils`),
or globally (`npm install --global forge-cli-utils`)
- setup `FORGE_CLIENT_ID` and `FORGE_CLIENT_SECRET` env. vars with your app credentials
- use the following scripts for different Forge services:
- `forge-dm` - [Forge Data Management](https://forge.autodesk.com/en/docs/data/v2) service
- `forge-md` - [Forge Model Derivative](https://forge.autodesk.com/en/docs/model-derivative/v2) service
- `forge-da` - [Forge Design Automation](https://forge.autodesk.com/en/docs/design-automation/v3) service
Install the `forge-cli-utils` library, either in your own npm project
(`npm install --save forge-cli-utils`), or globally (`npm install --global forge-cli-utils`).

### Self-contained binaries

Scripts in this library are also packaged into self-contained binaries for various platforms
using the [pkg](https://www.npmjs.com/package/pkg) module. You can download the binaries on
the [release](https://github.com/petrbroz/forge-cli-utils/releases) pages.
using the [pkg](https://www.npmjs.com/package/pkg) module. You can download the binaries from
[release](https://github.com/petrbroz/forge-cli-utils/releases) pages.

## Usage

### Providing Forge credentials

## Examples
The CLI tools require Forge app credentials to be provided as env. variables.

### Data Management
> If you don't have a Forge app yet, check out this tutorial: https://forge.autodesk.com/en/docs/oauth/v2/tutorials/create-app/.
Listing buckets as full JSON
On macOS and linux:
```bash
export FORGE_CLIENT_ID=<your client id>
export FORGE_CLIENT_SECRET=<your client secret>
```

On Windows, using _cmd.exe_:
```
set FORGE_CLIENT_ID=<your client id>
set FORGE_CLIENT_SECRET=<your client secret>
```

On Windows, using PowerShell:
```powershell
$env:FORGE_CLIENT_ID = "<your client id>"
$env:FORGE_CLIENT_SECRET = "<your client secret>"
```

### Scripts

Use the following scripts for different Forge services:
- `forge-dm` - [Forge Data Management](https://forge.autodesk.com/en/docs/data/v2) service
- `forge-md` - [Forge Model Derivative](https://forge.autodesk.com/en/docs/model-derivative/v2) service
- `forge-da` - [Forge Design Automation](https://forge.autodesk.com/en/docs/design-automation/v3) service

`forge-dm list-buckets`
Each script expects a _subcommand_ similar to `git`. To get a list of all available commands,
run the script with `-h` or `--help`.

Listing object IDs of specific bucket
> When using bash, use the _tools/autocomplete-bash.sh_ script to setup a simple auto-completion
> for the basic commands of each script: `source tools/autocomplete-bash.sh`.
`forge-dm list-objects my-test-bucket --short`
Most commands output raw JSON output from Forge services by default, but in many cases
you can use `-s` or `--short` flag to output a more concise version of the results.
The raw JSON output can also be combined with tools like [jq](https://stedolan.github.io/jq)
to extract just the pieces of information that you need:

Listing object IDs without specifying a bucket (will show an interactive prompt with list of buckets to choose from)
```bash
# Listing buckets as full JSON
forge-dm list-buckets

`forge-dm list-objects --short`
# Listing bucket keys
forge-dm list-buckets --short

Getting an URN of an object
# List creation dates of all buckets
forge-dm list-buckets | jq '.[] | .createdDate'
```

`forge-dm object-urn my-bucket-key my-object-key`
### Examples

### Design Automation
#### Data Management

Creating a new app bundle
```bash
# Listing buckets as full JSON
forge-dm list-buckets

`forge-da create-appbundle BundleName path/to/bundle/zipfile Autodesk.Inventor+23 "Bundle description here."`
# Listing object IDs of specific bucket
forge-dm list-objects my-test-bucket --short

Updating existing activity
# Listing object IDs without specifying a bucket (will show an interactive prompt with list of buckets to choose from)
forge-dm list-objects --short

`forge-da update-activity ActivityName BundleName BundleAlias Autodesk.Inventor+23 --input PartFile --output Thumbnail:thumbnail.bmp`
# Getting an URN of an object
forge-dm object-urn my-bucket-key my-object-key
```

Creating work item
#### Design Automation

`forge-da create-workitem ActivityName ActivityAlias --input PartFile:https://some.url --output Thumbnail:https://another.url --short`
```bash
# Creating a new app bundle
forge-da create-appbundle BundleName path/to/bundle/zipfile Autodesk.Inventor+23 "Bundle description here."

### Model Derivative
# Updating existing activity
forge-da update-activity ActivityName BundleName BundleAlias Autodesk.Inventor+23 --input PartFile --output Thumbnail:thumbnail.bmp

Translating a model based on its URN
# Creating work item
forge-da create-workitem ActivityName ActivityAlias --input PartFile:https://some.url --output Thumbnail:https://another.url --short
```

`forge-md translate dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cG9jLWJvdXlndWVzLWltbW9iaWxpZXIvaW5wdXQucnZ0`
#### Model Derivative

Showing an interactive prompt with all viewables in an URN, and then getting properties of the selected viewable
```bash
# Translating a model based on its URN
forge-md translate dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cG9jLWJvdXlndWVzLWltbW9iaWxpZXIvaW5wdXQucnZ0

`forge-md get-viewable-props dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cG9jLWJvdXlndWVzLWltbW9iaWxpZXIvaW5wdXQucnZ0`
# Showing an interactive prompt with all viewables in an URN, and then getting properties of the selected viewable
forge-md get-viewable-props dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cG9jLWJvdXlndWVzLWltbW9iaWxpZXIvaW5wdXQucnZ0
```

> For additional examples, check out the _tests_ subfolder.
> For additional examples, check out the _examples_ subfolder.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
theme: jekyll-theme-hacker
theme: jekyll-theme-minimal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sample scripts for creating and running a Forge Design Automation
pipeline that generates a thumbnail from an Autodesk Inventor file.

The _setup-pipeline.sh_ script:
The _setup-pipeline_ script:
- creates (or updates) an app bundle for Autodesk Inventor engine,
using a pre-packaged Inventor plugin _ThumbnailPlugin.bundle.zip_
- creates (or updates) an alias pointing to the latest version of the app bundle
Expand All @@ -12,7 +12,7 @@ The _setup-pipeline.sh_ script:
on its output
- creates (or updates) an alias pointing to the latest version of the activity

The _run-pipeline.sh_ script:
The _run-pipeline_ script:
- uploads an example Inventor file included with this sample
- creates signed URLs for the input Inventor file and the output thumbnail
- creates a work item for the activity defined during the setup
Expand All @@ -21,10 +21,20 @@ The _run-pipeline.sh_ script:

## Running

### On macOS/linux (using bash)

```bash
export FORGE_CLIENT_ID=<your client id>
export FORGE_CLIENT_SECRET=<your client secret>
export FORGE_BUCKET=<your bucket>
./setup-pipeline.sh
./run-pipeline.sh
```

### On Windows (using PowerShell)

```powershell
$env:FORGE_CLIENT_ID = "<your client id>"
$env:FORGE_CLIENT_SECRET = "<your client secret>"
.\setup-pipeline.ps1
```
46 changes: 46 additions & 0 deletions examples/inventor-thumbnail/run-pipeline.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

$forge_dm_bin = "node ..\..\src\forge-dm.js"
$forge_da_bin = "node ..\..\src\forge-da.js"

$activity_name = "MyTestActivity"
$activity_alias = "dev"

$input_file_path = ".\Clutch_Gear_20t.ipt"
$input_object_key = "input.ipt"
$thumbnail_object_key = "thumbnail.bmp"

# If it does not exist, create a data bucket
$result = Invoke-Expression "$forge_dm_bin list-buckets --short" | Select-String -Pattern $env:FORGE_BUCKET | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating a bucket $env:FORGE_BUCKET"
Invoke-Expression "$forge_dm_bin create-bucket $env:FORGE_BUCKET"
}

# Upload Inventor file and create a placeholder for the output thumbnail
Write-Host "Preparing input/output files"
Invoke-Expression "$forge_dm_bin upload-object $input_file_path application/octet-stream $env:FORGE_BUCKET $input_object_key"
New-Item -Name "output" -Path "." -ItemType "directory"
New-Item -Name "thumbnail.bmp" -Path ".\output" -ItemType "file"
Invoke-Expression "$forge_dm_bin upload-object .\output\thumbnail.bmp image/bmp $env:FORGE_BUCKET $thumbnail_object_key"

# Generate signed URLs for all input and output files
Write-Host "Creating signed URLs"
$input_file_signed_url = Invoke-Expression "$forge_dm_bin create-signed-url $env:FORGE_BUCKET $input_object_key --access read --short"
$thumbnail_signed_url = Invoke-Expression "$forge_dm_bin create-signed-url $env:FORGE_BUCKET $thumbnail_object_key --access readwrite --short"

# Create activity and poll the results
Write-Host "Creating work item"
$workitem_id = Invoke-Expression "$forge_da_bin create-workitem $activity_name $activity_alias --input PartFile:$input_file_signed_url --output Thumbnail:$thumbnail_signed_url --short"
Write-Host "Waiting for work item $workitem_id to complete"
$workitem_status = "inprogress"
while ($workitem_status -eq "inprogress") {
Start-Sleep -s 5
$workitem_status = Invoke-Expression "$forge_da_bin get-workitem $workitem_id --short"
Write-Host $workitem_status
}

# Download the results
Write-Host "Downloading results to output/thumbnail.bmp"
Invoke-Expression "$forge_dm_bin download-object $env:FORGE_BUCKET $thumbnail_object_key output\thumbnail.bmp"
Write-Host "Process complete. See the thumbnail in the output folder, or download it from $thumbnail_signed_url"
File renamed without changes.
59 changes: 59 additions & 0 deletions examples/inventor-thumbnail/setup-pipeline.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, and FORGE_BUCKET must be set before running this script.

$forge_da_bin = "node ..\..\src\forge-da.js"

$appbundle_name = "MyTestBundle"
$appbundle_alias = "dev"
$appbundle_file = ".\ThumbnailPlugin.bundle.zip"
$appbundle_engine = "Autodesk.Inventor+24"

$activity_name = "MyTestActivity"
$activity_alias = "dev"

# Create or update an appbundle
Write-Host "Creating an appbundle $appbundle_name"
$result = Invoke-Expression "$forge_da_bin list-appbundles --short" | Select-String -Pattern $appbundle_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle"
Invoke-Expression "$forge_da_bin create-appbundle $appbundle_name $appbundle_file $appbundle_engine"
} else {
Write-Host "Updating existing appbundle"
Invoke-Expression "$forge_da_bin update-appbundle $appbundle_name $appbundle_file $appbundle_engine"
}

# Create or update an appbundle alias
Write-Host "Creating an appbundle alias $appbundle_alias"
$appbundle_version = Invoke-Expression "$forge_da_bin list-appbundle-versions $appbundle_name --short" | Select-Object -Last 1
Write-Host "Last appbundle version: $appbundle_version"
$result = Invoke-Expression "$forge_da_bin list-appbundle-aliases $appbundle_name --short" | Select-String -Pattern $appbundle_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle alias"
Invoke-Expression "$forge_da_bin create-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
} else {
Write-Host "Updating existing appbundle alias"
Invoke-Expression "$forge_da_bin update-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version"
}

# Create or update an activity
Write-Host "Creating an activity $activity_name"
$result = Invoke-Expression "$forge_da_bin list-activities --short" | Select-String -Pattern $activity_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity"
Invoke-Expression "$forge_da_bin create-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail:thumbnail.bmp"
} else {
Write-Host "Updating existing activity"
Invoke-Expression "$forge_da_bin update-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --input PartFile --output Thumbnail:thumbnail.bmp"
}

# Create or update an activity alias
Write-Host "Creating an activity alias $activity_alias"
$activity_version = Invoke-Expression "$forge_da_bin list-activity-versions $activity_name --short" | Select-Object -Last 1
Write-Host "Last activity version: $activity_version"
$result = Invoke-Expression "$forge_da_bin list-activity-aliases $activity_name --short" | Select-String -Pattern $activity_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity alias"
Invoke-Expression "$forge_da_bin create-activity-alias $activity_alias $activity_name $activity_version"
} else {
Write-Host "Updating existing activity alias"
Invoke-Expression "$forge_da_bin update-activity-alias $activity_alias $activity_name $activity_version"
}
File renamed without changes.
Loading

0 comments on commit 1e0e876

Please sign in to comment.