Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Insert and constrain a component at different points

AlainHAp
Contributor

Insert and constrain a component at different points

AlainHAp
Contributor
Contributor

Hello,

I would like to position loaded components from the hard drive
I create a document, then a sketch with a base point.
I create a position list
I constrain my point of the list to that of the base point
I call the component file, here AA.f3d
And I have the error when I want to constrain the component "AA" to the different points.

My script below.

Can you help me please, thanks
My greetings

 

 

import adsk.core, adsk.fusion, traceback
import os.path

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        importManager = app.importManager
        
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        newOccs = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        objectA = newOccs.component
        
        # Create a new sketch on the xy plane.
        Esquisses = objectA.sketches
        xZPlane = objectA.xZConstructionPlane
        sketch = Esquisses.add(xZPlane)
        
        # Get sketch health state
        health = sketch.healthState
        if health == adsk.fusion.FeatureHealthStates.ErrorFeatureHealthState or health == adsk.fusion.FeatureHealthStates.WarningFeatureHealthState:        
            msg = sketch.errorOrWarningMessage


        EsqPoint = sketch.sketchPoints
        
        # Point de base
        pointOrigin = adsk.core.Point3D.create(1.8, 0, 0)
        recPointO = EsqPoint.add(pointOrigin)
   

        TablChr =[80,480,880,1280]  #Position list

        Max = len(TablChr)
        Inc = 0
        while Inc < Max:
            iX = pointOrigin.x
            iY = float(TablChr[Inc]/10)
            iZ = 0.0
            point = adsk.core.Point3D.create(iX,iY,iZ)
            recPoint = EsqPoint.add(point)

            
            sketch.geometricConstraints.addVerticalPoints(recPointO, recPoint)       
           
            sketch.sketchDimensions.addDistanceDimension (recPointO, recPoint,
                                                          adsk.fusion.DimensionOrientations.VerticalDimensionOrientation,
                                                          adsk.core.Point3D.create (-2,recPoint.geometry.y-8, 0));

            fileNameCharniere = 'F:\AA.f3d'      #File to open and to position     
            
            archiveOptions = importManager.createFusionArchiveImportOptions(fileNameCharniere)
            
            importManager.importToTarget(archiveOptions, objectA)
               
            occ = objectA.occurrences.item(objectA.occurrences.count-1)
            
            cmp = occ.component
            Circle = RetourneCurves(cmp)
            
            
            geo0 = adsk.fusion.JointGeometry.createByPoint(recPoint)
            geo1 = adsk.fusion.jointGeometry.createByCurve(Circle, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)      
            
            joints = objectA.joints
            jointInput = joints.createInput(geo0, geo1)
            jointInput.isFlipped = True
            jointInput.setAsRigidJointMotion()
           
            joint = joints.add(jointInput)
            
            Inc +=1

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

def RetourneCurves(Cmp):
    try:
        CmpEsqs = Cmp.sketches  #retourne collection stretch
        
        Esq = CmpEsqs.item(0)   #retourne 1e 1er élément stretch
        
        Cirs = Esq.sketchCurves.sketchCircles  #retourne collection de circles
        
        Cir= Cirs.item(0)
        
        return Cir

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

0 Likes
Reply
Accepted solutions (1)
902 Views
1 Reply
Reply (1)

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

There was a typo error in the line as below. It should be big "J". However I still get error during creating joint. It is our bug and logged as UP-37250 in our internal system.

 

"geo1 = adsk.fusion.jointGeometry.createByCurve(Circle, adsk.fusion.JointKeyPointTypes.CenterKeyPoint) "

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes