sweep works on rootComponent but not on newOccuranceComponent

adminTCYL2
Enthusiast
Enthusiast

sweep works on rootComponent but not on newOccuranceComponent

adminTCYL2
Enthusiast
Enthusiast

Ich habe im folgenden Code ein möglichst einfaches Sweep erstellt (ein Kreis entlang eines geraden Pfades), um dem Fehler auf die Spur zu kommen. Es funktioniert auf der root Component, wenn ich Zeile 15 aktiviere. Ich will es aber auf der new_occurrence.component zum funktionieren bringen. Eine einfache Extrusion klappt, aber das Sweep bringt folgenden Fehler: 

..... 
line 24, in run

path = adsk.fusion.Path.create(pathLine, chainedOption)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File .....line 37652, in create

return _fusion.Path_create(curves, chainOptions)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(obj.get(), objPath, nullptr, contextPath)

Hier mein Code: 

import adsk.core, adsk.fusion, traceback
   
def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        new_occurrence = design.rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        comp = new_occurrence.component
        comp.isActive = True

        #comp = design.rootComponent

        # create pathline
        path_sketch = comp.sketches.add(comp.xYConstructionPlane)
        pathLine = path_sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(9,0,0))
        feats = comp.features
        chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        if adsk.fusion.BRepEdge.cast(pathLine😞
            chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        path = adsk.fusion.Path.create(pathLine, chainedOption)
        path = feats.createPath(pathLine)
       
        # create circle-profile
        radius = 2.5
        profile_sketch = comp.sketches.add(comp.yZConstructionPlane)
        center = comp.yZConstructionPlane.geometry.origin
        center = profile_sketch.modelToSketchSpace(center)
        profile_sketch.sketchCurves.sketchCircles.addByCenterRadius(center, radius)
        profile = profile_sketch.profiles[0]
       
        # create sweep
        sweepFeats = feats.sweepFeatures
        sweepInput = sweepFeats.createInput(profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepFeat = sweepFeats.add(sweepInput)

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

 

0 Likes
Reply
91 Views
2 Replies
Replies (2)

adminTCYL2
Enthusiast
Enthusiast

Jetzt bin ich einen Schritt weiter. Die ChainedOption funktioniert offensichtlich auf der new_occurrence.component nicht. Für mein einfaches Beispiel brauche ich sie nicht. Deaktiviere ich sie, so funktioniert das Sweep. 

import adsk.core, adsk.fusion, traceback
   
def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        new_occurrence = design.rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        comp = new_occurrence.component
        comp.isActive = True

        #comp = design.rootComponent

        # create pathline
        path_sketch = comp.sketches.add(comp.xYConstructionPlane)
        pathLine = path_sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(9,0,0))
        # chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
        # if adsk.fusion.BRepEdge.cast(pathLine):
        #     chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
        # path = adsk.fusion.Path.create(pathLine, chainedOption)
        path = comp.features.createPath(pathLine)

        # create circle-profile
        radius = 2.5
        profile_sketch = comp.sketches.add(comp.yZConstructionPlane)
        center = comp.yZConstructionPlane.geometry.origin
        center = profile_sketch.modelToSketchSpace(center)
        profile_sketch.sketchCurves.sketchCircles.addByCenterRadius(center, radius)
        profile = profile_sketch.profiles[0]
       
        # create sweep
        sweepFeats = comp.features.sweepFeatures
        sweepInput = sweepFeats.createInput(profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
        sweepFeat = sweepFeats.add(sweepInput)

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

 

0 Likes

kandennti
Mentor
Mentor

Hi @adminTCYL2 -San.

 

This is a proxy problem.
A one-line modification like this will allow it to run without error.

・・・
        # create pathline
        path_sketch = comp.sketches.add(comp.xYConstructionPlane)
        path_sketch = path_sketch.createForAssemblyContext(new_occurrence) #Add here
        pathLine = path_sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0,0,0), adsk.core.Point3D.create(9,0,0))
        feats = comp.features
・・・

 

For more information on proxies, see “Proxies” here.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 

1 Like