Documentation Home
v1.22 v1.23
v1.22 v1.23

CAD Forge Max extension - C#

A CAD Forge Max extension is a small C# console program that CAD Forge Max runs on the product structure of a 3D Library element. This page describes what an extension is made of, and the contract between your program and CAD Forge Max. To set up your machine, see Getting started – C# Dev environment.

Anatomy of an extension

File

Role

<name>.skrjob

Describes the job: its name, the executable to run and its settings.

<Name>.skrmanifest

Describes the package for the Marketplace (name, description, TargetPlatform: Script).

<Project>.csproj + Program.cs

The console program. It references the Skr.ComputationAgent.Model and Skr.ComputationAgent.Utilities libraries (SkrComputationAgentModel repository).

The .skrjob file

JSON
{
  "JobName": "Merge structure",
  "ScriptRelativePath": "skrmergestructure/Skr.MergeStructure.exe",
  "DefaultSettings": {
    "Values": {
      "mergeStrategy": { "Value": "PartLimit", "ValueType": "String" },
      "mergePartLimit": { "Value": "1000", "ValueType": "Integer" }
    }
  }
}

Field

Role

JobName

Unique name of the job in CAD Forge Max. Also the prefix of its settings (see below).

ScriptRelativePath

Path of the executable, relative to the folder of the .skrjob. The build looks for a .csproj with the same name as the executable.

DefaultSettings

The settings of the job and their default values. ValueType: String, Integer, Double, Boolean, DateTime or TimeSpan.

ScriptContext (optional)

DataLibrary (default) or PostImport. It is published with the job to XR Center.

The program contract

CAD Forge Max launches your executable like this:

PowerShell
Skr.MergeStructure.exe <workingDirectory> -mergeStrategy Metadata -metadataName InstanceName -metadataValue planes.1

Item

Rule

First argument

The task working directory. Read it with ForgeAgentHelper.TryGetWorkingDirectory.

Next arguments

-<setting> <value> for each setting of the .skrjob. Read them with ForgeAgentHelper.TryGetArgumentValue.

Exit code

0 means success. Any other value fails the task.

Progress

ForgeAgentHelper.ReportProgress(new ProgressState(step, total, message), logger) writes a JSON line that CAD Forge Max shows as the task progress.

Logs

Use the logger from ForgeAgentHelper.SetupLogging(). Standard output is logged as information, standard error as errors.

Setting values are passed without quotes: a value that contains spaces is cut at the first space.

Read the input

Create a Product3DComponentsContextHelper with the working directory, then:

Method

Returns

GetProduct3DComponentsAsync()

All the product components of the element (structure, metadata, materials, transforms).

GetPart3DsAsync()

All the parts.

LoadPart3DMeshesAsync(part) / EnumerateAllPartMeshsAsync()

The meshes of the parts.

GetPartsToProductComponentsAsync()

For each part, the product components that use it.

Declare the output

Your program writes its changes in the Output folder, then always writes a declaration file with WriteOutputDeclarationFile (even empty, when there is nothing to change). CAD Forge Max applies only what is declared:

Declaration

File to write

Effect

Product3DComponents.ReplaceStructure

WriteProduct3DComponentsStructureRequestOutputFile

Replaces the whole product structure.

Product3DComponents.AddOrUpdateProduct3DComponents

WriteProduct3DComponentsOutputFile

Adds or updates the components you write.

Product3DComponents.RemoveProduct3DComponents

—

Removes the components whose IDs are listed.

Part3Ds.AddOrUpdatePart3Ds

WritePart3DsOutputFile + meshes in GetMesh3DOutputFilePath

Adds or updates parts and their meshes.

Part3Ds.AddVisualizationEngines / RemoveVisualizationEngines

—

Declares the visualization engines your meshes target.

See the Examples for complete programs.