Draft Feature API Sample

Description

Demonstrates creating a new draft feature.

Code Samples

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Get active design        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        # Get root component in this design
        rootComp = design.rootComponent

        # Get the first face of box
        face1 = rootComp.bRepBodies.item(0).faces.item(0)
        
        # Get all faces which connect to the first face
        connectedFaces = [];
        for edge in face1.edges:
            for face in edge.faces:
                if face1 != face:
                    connectedFaces.append(face)
        
        # Create draft feature
        drafts = rootComp.features.draftFeatures
        draftFeatInput = drafts.createInput(connectedFaces, face1, True)
        draftFeatInput.isDirectionFlipped = False
        angle = adsk.core.ValueInput.createByString("10 deg")
        draftFeatInput.setSingleAngle(True, angle)
        drafts.add(draftFeatInput)       
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
/**
 * Draft Feature API Sample
 * Demonstrates creating a new draft feature.
 */

import { adsk } from '@adsk/fusion'

function run() {

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

  // Create a document.
  const design = app.activeProduct as adsk.fusion.Design

  // Get the root component of the active design.
  const rootComp = design.rootComponent

  // Get the first face of box
  const face1 = rootComp.bRepBodies.item(0).faces.item(0)

  // Get all faces which connect to the first face
  const connectedFaces = [];

  for(let i= 0; i < face1.edges.count; i++){
    const edge = face1.edges.item(i)
    for(let j= 0; j < edge.faces.count; j++){
      const face = edge.faces.item(j)
      if (face1?.tempId != face?.tempId){
        connectedFaces.push(face)
      }
    }
  }

  // Create draft feature
   const drafts = rootComp.features.draftFeatures
   const draftFeatInput = drafts.createInput(connectedFaces, face1, true)
   draftFeatInput.isDirectionFlipped = false
   const angle = adsk.core.ValueInput.createByString("10 deg")
   draftFeatInput.setSingleAngle(true, angle)
   drafts.add(draftFeatInput)

}

run();