Corner Closure Sample

Description

Demonstrates creating a new sheet metal corner closure feature.

Before running: Open or create a sheet metal design in the DESIGN workspace, unless the script builds its own sheet metal body.

Code Samples

// Corner Closure API sample — demonstrates creating and configuring corner closure features.
//
// Requires APISampleSheetMetalFlangePreparedToCorner.f3d to be open.
// Edge indices are specific to that document.

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>

using namespace adsk::core;
using namespace adsk::fusion;

static const size_t TWO_BEND_DOMINANT_IDX = 5;
static const size_t TWO_BEND_SUBMISSIVE_IDX = 77;
static const size_t THREE_BEND_DOMINANT_IDX = 5;
static const size_t THREE_BEND_SUBMISSIVE_IDX = 55;

Ptr<Application> app;

#define CHECK_PTR(ptr)                                                                                                 \
    if (!ptr)                                                                                                          \
    {                                                                                                                  \
        return false;                                                                                                  \
    }

// Delete all corner closure features and return a fresh collection.
static Ptr<CornerClosureFeatures> clearCornerFeatures(const Ptr<Features>& features)
{
    auto cornerFeatures = features->cornerClosureFeatures();
    while (cornerFeatures && cornerFeatures->count() > 0)
    {
        cornerFeatures->item(0)->deleteMe();
        cornerFeatures = features->cornerClosureFeatures();
    }
    return cornerFeatures;
}

extern "C" XI_EXPORT bool run(const char* context)
{
     Get the active design and root component
    app = Application::get();
    if (!app)
        return false;

    auto product = app->activeProduct();
    CHECK_PTR(product);
    auto design = product->cast<Design>();
    CHECK_PTR(design);
    auto rootComp = design->rootComponent();
    CHECK_PTR(rootComp);

    auto features = rootComp->features();
    CHECK_PTR(features);
    auto cornerFeatures = features->cornerClosureFeatures();
    CHECK_PTR(cornerFeatures);

     Clean up any existing corner closure features
    cornerFeatures = clearCornerFeatures(features);
    CHECK_PTR(cornerFeatures);

    auto body = rootComp->bRepBodies()->item(0);
    CHECK_PTR(body);
    auto edges = body->edges();
    CHECK_PTR(edges);

     Example 1: Create a two-bend corner closure with symmetric gap alignment
    auto inp = cornerFeatures->createInput(edges->item(TWO_BEND_DOMINANT_IDX), edges->item(TWO_BEND_SUBMISSIVE_IDX));
    CHECK_PTR(inp);
    inp->gap(ValueInput::createByReal(0.1));
    inp->bendTransition(BendTransitionTypes::StraightLineCornerBendTransitionType);

    auto twoBendFeature = cornerFeatures->add(inp);
    CHECK_PTR(twoBendFeature);
    app->log("Created two-bend corner closure: " + twoBendFeature->name());

     Example 2: Create a three-bend corner closure
    cornerFeatures = clearCornerFeatures(features);
    CHECK_PTR(cornerFeatures);
    edges = rootComp->bRepBodies()->item(0)->edges();
    CHECK_PTR(edges);

    inp = cornerFeatures->createInput(edges->item(THREE_BEND_DOMINANT_IDX), edges->item(THREE_BEND_SUBMISSIVE_IDX));
    CHECK_PTR(inp);
    inp->gap(ValueInput::createByReal(0.15));

    auto threeBendFeature = cornerFeatures->add(inp);
    CHECK_PTR(threeBendFeature);
    app->log("Created three-bend corner closure: " + threeBendFeature->name());

    app->log("CornerClosureSample completed successfully.");
    return true;
}

#undef CHECK_PTR
/**
 * Corner Closure API sample — demonstrates creating and configuring corner closure features.
 *
 * Requires APISampleSheetMetalFlangePreparedToCorner.f3d to be open.
 * Edge indices are specific to that document.
 */

import { adsk } from '@adsk/fusion';

const TWO_BEND_DOMINANT_IDX = 5;
const TWO_BEND_SUBMISSIVE_IDX = 77;
const THREE_BEND_DOMINANT_IDX = 5;
const THREE_BEND_SUBMISSIVE_IDX = 55;

// Get the edges of the first body in the component.
function getBodyEdges(rootComp: adsk.fusion.Component): adsk.fusion.BRepEdges {
  const body = rootComp.bRepBodies.item(0);
  if (!body) throw Error("No body at index 0.");
  return body.edges;
}

// Delete all corner closure features and return a fresh collection.
function clearCornerFeatures(features: adsk.fusion.Features): adsk.fusion.CornerClosureFeatures {
  let cf = features.cornerClosureFeatures;
  while (cf.count > 0) {
    cf.item(0).deleteMe();
    cf = features.cornerClosureFeatures;
  }
  return cf;
}

function run() {

  // Get the Fusion API's application object
  const app = adsk.core.Application.get();
  if (!app) throw Error("No adsk.core.Application.");

  // Get the active design and root component
  const product = app.activeProduct;
  if (!product) throw Error("No active product.");

  const design = product as adsk.fusion.Design;
  if (!design) throw Error("No active design.");

  const rootComp = design.rootComponent;
  if (!rootComp) throw Error("No root component.");

  const features = rootComp.features;
  if (!features) throw Error("No features.");

  // Clean up any existing corner closure features
  let cornerFeatures = clearCornerFeatures(features);

  let edges = getBodyEdges(rootComp);

  // Example 1: Create a two-bend corner closure with symmetric gap alignment
  let inp = cornerFeatures.createInput(
    edges.item(TWO_BEND_DOMINANT_IDX),
    edges.item(TWO_BEND_SUBMISSIVE_IDX));
  inp.gap = adsk.core.ValueInput.createByReal(0.1);
  inp.bendTransition = adsk.fusion.BendTransitionTypes.StraightLineCornerBendTransitionType;

  const twoBendFeature = cornerFeatures.add(inp);
  adsk.log(`Created two-bend corner closure: ${twoBendFeature.name}`);

  // Example 2: Create a three-bend corner closure
  cornerFeatures = clearCornerFeatures(features);
  edges = getBodyEdges(rootComp);

  inp = cornerFeatures.createInput(
    edges.item(THREE_BEND_DOMINANT_IDX),
    edges.item(THREE_BEND_SUBMISSIVE_IDX));
  inp.gap = adsk.core.ValueInput.createByReal(0.15);

  const threeBendFeature = cornerFeatures.add(inp);
  adsk.log(`Created three-bend corner closure: ${threeBendFeature.name}`);

  adsk.log('CornerClosureSample completed successfully.');
}

run();