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

Merge from Metadata

The Merge structure extension (src/ForgeMergeStructure in forge-scripts) simplifies a product structure by merging sub-assemblies into single parts. It offers four strategies; this page details the Metadata one, and the code shows how to read the structure and replace it.

Job

JSON
{
  "JobName": "Merge structure",
  "ScriptRelativePath": "skrmergestructure/Skr.MergeStructure.exe",
  "DefaultSettings": {
    "Values": {
      "mergeStrategy": { "Value": "PartLimit", "ValueType": "String" },
      "metadataName": { "Value": "InstanceName", "ValueType": "String" },
      "metadataValue": { "Value": "planes.1", "ValueType": "String" },
      "mergeDepth": { "Value": "1", "ValueType": "Integer" },
      "mergePartLimit": { "Value": "1000", "ValueType": "Integer" },
      "mergeLevelsToRemove": { "Value": "1", "ValueType": "Integer" }
    }
  }
}

Strategies

mergeStrategy

Settings

What is merged

Metadata

metadataName, metadataValue

Each assembly whose metadata (or property, such as InstanceName) equals the value.

DepthFromLeaf

mergeDepth

Everything below max depth − mergeDepth. Example: max depth 7, mergeDepth 2 → below level 5.

PartLimit

mergePartLimit

Finds the level where merging can reach this number of parts, then merges first the components that fill their parent bounding box the most.

RemoveLevels

mergeLevelsToRemove

The given number of levels above every leaf.

How the Metadata strategy works

  1. Read the structure and the parts with Product3DComponentsContextHelper.

  2. Select the components to merge: the metadata metadataName must equal metadataValue; if the component has no such metadata, its property of that name is compared instead. Components that are parts themselves, or whose parent is already selected, are skipped.

  3. Merge the meshes of each selected assembly into a new part.

  4. Write the new parts and meshes, then the new structure, and declare ReplaceStructure and AddOrUpdatePart3Ds.

C#
// Program.cs: read the settings and the structure
var mergeStrategy = "";
var metadataName = "";
var metadataValue = "";
ForgeAgentHelper.TryGetArgumentValue(args, nameof(mergeStrategy), ref mergeStrategy);
ForgeAgentHelper.TryGetArgumentValue(args, nameof(metadataName), ref metadataName);
ForgeAgentHelper.TryGetArgumentValue(args, nameof(metadataValue), ref metadataValue);

var p3DccHelper = new Product3DComponentsContextHelper(workingDirectory, Logger);
var product3dComponents = await p3DccHelper.GetProduct3DComponentsAsync();
var parts3Ds = await p3DccHelper.GetPart3DsAsync();

// MergeFromMetadata.cs: does a component match?
var metadata = component.Metadatas.FirstOrDefault(m => m.Name == metadataName);
if (metadata != ProductMetadata.Empty)
    isMatching = metadata.Value == metadataValue;
else
    isMatching = typeAccessor[component, metadataName]?.ToString() == metadataValue; // property fallback

Output

C#
// OutputPersistence.cs
await p3DccHelper.WritePart3DsOutputFile(mergeResult.NewPart3Ds);   // + each mesh in GetMesh3DOutputFilePath(...)
await p3DccHelper.WriteOutputDeclarationFile(new Product3DComponentsContextOutput
{
    Product3DComponents = new Product3DComponentsOutput { ReplaceStructure = true },
    Part3Ds = new Part3DOutput
    {
        AddOrUpdatePart3Ds = true,
        AddVisualizationEngines = [VisualizationEngine.GenericLatest]
    }
});
await p3DccHelper.WriteProduct3DComponentsStructureRequestOutputFile(newStructure.ToAsyncEnumerable());

When nothing matches, the program writes an empty declaration and exits successfully: the structure is left unchanged.

Example: to merge every assembly named planes.1, set mergeStrategy = Metadata, metadataName = InstanceName, metadataValue = planes.1.