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: 

Enviroment Not supported error: creating a construction point

1 REPLY 1
Reply
Message 1 of 2
nnamfoh
429 Views, 1 Reply

Enviroment Not supported error: creating a construction point

I'm trying to create a construction point at the rough center of a component using the center point of the Components Bounding box.

When I try to create the point I get "RuntimeTimeError 3: Enviroment is not supported".

What does this mean and how can it be avoided. I need a point at center of the component in order to "blow it out" but I cannot find away to access this and use it as an origin for the scale. Please reference the code below:

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

ui = None
def generatePrototypeGeometry(root, scale =1.2, faces =[]):
    occurencesOfCopy = root.allOccurrencesByComponent(root)
    occ =occurencesOfCopy.item(0)
    collection = adsk.core.ObjectCollection.create()
    for body in root.bRepBodies:
        collection.add(body) 
    bounding = root.boundingBox
    constructionPoints = root.constructionPoints
    scalePointInput = constructionPoints.createInput()
    scalePointInput.setByPoint(adsk.core.Point3D.create((bounding.maxPoint.x-bounding.minPoint.x)/2,(bounding.maxPoint.z-bounding.minPoint.z)/2, (bounding.maxPoint.z-bounding.minPoint.z)/2))
    scalePoint = constructionPoints.add(scalePointInput) 
    scalePoint = scalePoint.createForAssemblyContext(occ)
    scales = root.features.scaleFeatures
    scaleFactor = adsk.core.ValueInput.createByReal(scale)
    scaleUniformInput = scales.createInput(collection, scalePoint, scaleFactor)
    scales.add(scaleUniformInput)
    dist = bounding.minPoint.distanceTo(bounding.maxPoint)
    distance = adsk.core.ValueInput.createByReal(dist)
    extrudes = root.features.extrudeFeatures
    for face in faces:
        extInput = extrudes.createInput(face, adsk.fusion.FeatureOperations.CutFeatureOperation)
        extInput.setDistanceExtent(False, distance)
        extrudes.add(extInput)
def run(context):
    try:
        app = adsk.core.Application.get()
        global ui
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root = design.rootComponent
        faces = [root.bRepBodies.item(0).faces.item(0)]
        generatePrototypeGeometry(root, 1.2, faces)

    
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
1 REPLY 1
Message 2 of 2
liujac
in reply to: nnamfoh

Hi,

 

Here is the documentation about the setByPoint method of ConstructionPointInput.
“Providing a Point3D object is only valid when working in a direct edit model (do not capture design history). This is not valid when working in a parametric model and will fail.”

 

You need to switch the environment from parametric modeling to direct modeling or create a base feature.

 

 

 

design.designType = adsk.fusion.DesignTypes.DirectDesignType#switch to direct modeling
scalePointInput.setByPoint(adsk.core.Point3D.create((bounding.maxPoint.x-bounding.minPoint.x)/2,(bounding.maxPoint.y-bounding.minPoint.y)/2, (bounding.maxPoint.z-bounding.minPoint.z)/2))
scalePoint = constructionPoints.add(scalePointInput)

OR

 

 

baseFeat = None
if design.designType == adsk.fusion.DesignTypes.ParametricDesignType:
    baseFeat = root.features.baseFeatures.add()
if baseFeat:
    baseFeat.startEdit()
scalePointInput.setByPoint(adsk.core.Point3D.create((bounding.maxPoint.x-bounding.minPoint.x)/2,(bounding.maxPoint.y-bounding.minPoint.y)/2, (bounding.maxPoint.z-bounding.minPoint.z)/2))
scalePoint = constructionPoints.add(scalePointInput)
if baseFeat:
    baseFeat.finishEdit()

 

 

Thanks,

Jack

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report