How to extrude sketch text using API

How to extrude sketch text using API

Anonymous
Not applicable
1,866 Views
2 Replies
Message 1 of 3

How to extrude sketch text using API

Anonymous
Not applicable

My intent is to extrude sketch text.  But when I add SketchText object to the new sketch I always get empty sketch.profiles collection.  How can I provide a valid text-based profile to create ExtrudeFeatureInput object?

 

Fusion API Help indicates that Profiles class “also provides some additional utility functions to create open profiles and text based profiles that can be used as input for various features.”  Where these functions are described?

 

Any code sample would be greatly appreciated. 

 

Here is my test code that creates sketch text:

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        # Get sketch texts 
        sketchTexts = sketch.sketchTexts        
        # Create sketch text input
        point = adsk.core.Point3D.create(1.0, 1.0, 1.0)
        sketchTextInput = sketchTexts.createInput('example', 1.0, point)
        # Create sketch text
        sketchText = sketchTexts.add(sketchTextInput)
        
        m = sketch.sketchTexts.count
        n = sketch.profiles.count
        ui.messageBox("sketchTexts.count:  %i  \nprofiles .count: %i" % (m, n)) 
 

#    # Create an extrusion input
#    extrudes = rootComp.features.extrudeFeatures
#    extInput = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#    distance = adsk.core.ValueInput.createByReal(0.1)
#    extInput.setDistanceExtent(False, distance)
#    extInput.isSolid = True
#    
#    # Create the extrusion
#    ext = extrudes.add(extInput)

           
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

thanks

0 Likes
Accepted solutions (1)
1,867 Views
2 Replies
Replies (2)
Message 2 of 3

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

You can create an extrude by sketch text directly instead of profile. Please refer to the following codes:

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        # Get sketch texts 
        sketchTexts = sketch.sketchTexts        
        # Create sketch text input
        point = adsk.core.Point3D.create(1.0, 1.0, 1.0)
        sketchTextInput = sketchTexts.createInput('example', 1.0, point)
        # Create sketch text
        sketchText = sketchTexts.add(sketchTextInput)
         
        # Create an extrusion input
        extrudes = rootComp.features.extrudeFeatures
        extInput = extrudes.createInput(sketchText, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        distance = adsk.core.ValueInput.createByReal(0.1)
        extInput.setDistanceExtent(False, distance)
        extInput.isSolid = True
        
        # Create the extrusion
        ext = extrudes.add(extInput)

           
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 3

Anonymous
Not applicable

Great.  Thanks!

0 Likes