Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem in Script

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
nikita.panasiuk.knm.2020
203 Views, 2 Replies

Problem in Script

Good afternoon everyone. My teacher threw off the script for study but there is an error in it, I tried to find it but I don’t understand what’s wrong. It seems that everything looks normal. Can you tell me where the problem could be because I don't see it.

 code:

#Author-
#Description-

from asyncio import constants
import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        # Create a document.
        doc = app.documents.add(
            adsk.core.DocumentTypes.FusionDesignDocumentType)
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
# Get the root component of the active design.
        rootComp = design.rootComponent

       
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(0, 0, 0)
        endPoint = adsk.core.Point3D.create(5, 9, 0)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof = sketch.profiles.item(0)
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(
            prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5.8)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT FRONT
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(4, 0, 1)
        endPoint = adsk.core.Point3D.create(5, 9, 1)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT Back
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(0, 0, 1)
        endPoint = adsk.core.Point3D.create(1, 9, 1)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT Diagonal
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(1, 9, 1)
        endPoint = adsk.core.Point3D.create(1, 7.0118, 5.8)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
 
        #problem here
        ext = extrudes.add(extInput)
        #problem here


        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(4, 0, 1)
        endPoint = adsk.core.Point3D.create(4, 1.9882, 5.8)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT Inside
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(1.7, 0, 2)
        endPoint = adsk.core.Point3D.create(3.3, 9, 2)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(2.7)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # ADD CYLINDER

        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.yZConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(-4.5, 4.5, 5.5)
        oCirc = circles1.addByCenterRadius(CentPoint, 2)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.JoinFeatureOperation)

        distance = adsk.core.ValueInput.createByReal(-6)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT CYLINDER
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.yZConstructionPlane)
        circles1 = sketch.sketchCurves.sketchCircles
        CentPoint = adsk.core.Point3D.create(-4.5, 4.5, 5.5)
        oCirc = circles1.addByCenterRadius(CentPoint, 1)
        # Get the profile defined by the rectangle.
        prof1 = sketch.profiles.item(0)
        extInput = extrudes.createInput(prof1, adsk.fusion.FeatureOperations.CutFeatureOperation)

        distance = adsk.core.ValueInput.createByReal(-6)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

        # CUT Top
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xYConstructionPlane)
        Lines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(0.4, 1.5, 5.8)
        endPoint = adsk.core.Point3D.create(4.6, 7.5, 5.8)


        Rect = Lines.addTwoPointRectangle(startPoint,endPoint)
        prof2 = sketch.profiles.item(0)

       
        # Create an extrusion input.
        features = rootComp.features
        extrudes = features.extrudeFeatures
        extInput = extrudes.createInput(prof2, adsk.fusion.FeatureOperations.CutFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(2.7)
        extInput.setDistanceExtent(False, distance)
        ext = extrudes.add(extInput)

       

       

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2 REPLIES 2
Message 2 of 3

Hi @nikita.panasiuk.knm.2020 .

 

By setting the values in the two error locations to negative values, we have completed the process.

・・・
        distance = adsk.core.ValueInput.createByReal(-5)
・・・
Message 3 of 3

Thank you very much, I changed the signs and everything worked. Specified for cropping, you need to set a negative value. Thanks again!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report