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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Directly accessing geometries within occurrences

Message 1 of 6
197 Views, 5 Replies

Directly accessing geometries within occurrences



I have been developing an add-in that, in part, assigns attributes to sketch curves. When experimenting with the patterning sketch feature, I was unable to access the resulting curves within the generated occurrences within the API. Instead, any attempts would send me to the original sketches. I know that occurrences do not have geometry of their own, but is there any way to directly access these curves within occurrences? I'd like to read their individual attributes.


My current workaround has been to, by user selection, generate hidden sketch curves that reference the selected curves within the occurrences. It works, as I can now access the occurrence curves by using the new curves' references, but duplicates in the design make the add-in less scalable. 



A way of iterating through these sketch curves would be fantastic. Any help is appreciated. 


Thank you,



Message 2 of 6
in reply to: brightlu4GX5H

I'm not following what it is you're trying to do.  Can you post an example design that you can reference in your description?

Brian Ekins
Inventor and Fusion 360 API Expert
Message 3 of 6
in reply to: BrianEkins

Hi Brian,


I apologize for not being more clear. Here is a picture of an example design that I've been working with.



This is a chain design, made by using the sketch circular pattern feature on two sketches. To achieve the patterning, the circular pattern feature seems to generate new occurrences which contain direct references to the original sketches. I've developed an add-in that assigns attributes to user-selected sketch curves and later reads the attributes from them. I've found that the sketch curves, within the occurrences, generated by the circular pattern feature, are inaccessible through the API, although they can be directly accessed by user selection. This makes reading the attributes from all of the sketch curves in the design difficult.


Going back to the example design, if I wanted to access the sketch curve that relates to the LinkGroup:10 occurrence, the API is only able to find the original sketch and its curves that the occurrence was generated from. This is because the generated sketch curves, from the patterning feature, all stem from the same component. But that component only contains two sketches; the original two links. So accessing the other links through the API, as far as  I've tried, has been impossible.  


Sketch curves have a parent sketch, which has a parent component. This is how I would normally access a sketch curve; get a component, iterate through its sketches, and iterate through its curves. I've found that sketch curves generated by patterning features, as duplicates, reference the same parent sketch and the same parent component. This means that, in my example design, although there are 20 chain links, any attempt to iterate through them all simply iterates through the original two sketches (links) and child curves. I am wondering if there is a way, in the API, to directly access a sketch curve, such as those in LinkGroup:10, that was generated using patterning features. 


Best regards,


Message 4 of 6
in reply to: brightlu4GX5H

If you really want to solve the problem, you should attach data or code.


It takes too much time to reproduce the phenomenon.
It's the same for every question.

Message 5 of 6
in reply to: kandennti



You are correct, I should have provided example code. Here is a sample script, written to represent the problem. The script aims to iterate through every unique sketch curve, and accomplishes this by iterating through every component, every component sketch, and every curve in said sketch. It assigns an attribute, with an index, to every curve and displays the index using CustomGraphicsText.

#Author-Bright Lu
#Description-A sample script that attempts to assign attributes to sketch curves created by patterning features.\n
# Written for a Fusion 360 API Forum post
import adsk.core, adsk.fusion,, traceback

def run(context):
    app = adsk.core.Application.get()
    ui  = app.userInterface
    design = app.activeProduct
    # this loop will iterate through every sketch in every component.
    count = 0
    for component in design.allComponents:
        # This for loop allows the script to be ran multiple times in a design. 
        for cgGroup in component.customGraphicsGroups:
        for sketch in component.sketches:
            for curve in sketch.sketchCurves:
                if curve.attributes.count == 0:
                    curve.attributes.add('ArbitraryGroup' + str(count), 'ArbitraryName', 'ArbitraryValue' + str(count))

                    # this portion displays the attribute value for every unique curve.
                    cgGroup = component.customGraphicsGroups.add()
                    start = curve.geometry.asNurbsCurve.controlPoints[0]
                    x = adsk.core.Vector3D.create(1,0,0)
                    y = adsk.core.Vector3D.create(0,1,0)
                    z = adsk.core.Vector3D.create(0,0,1)
                    mat3D = adsk.core.Matrix3D.create()
                    cgText = cgGroup.addText(str(count), 'Arial', 1, mat3D)

We expect to see a unique index for every curve. We found that, when patterning is applied to sketches, this is true, as shown in Example 1.


However, when a sketch is placed in a component, which is then patterned, our method of iterating through each curve fails, as in Example 2. Although our example is in 2D, component patterning allows for 3D curves to be patterned. We would like to iterate through 3D curves that were generated by patterning.  Thank you for your time, any help would be greatly appreciated. 


Example 1: Sketch pattern


Example 2: Component Pattern




Message 6 of 6
in reply to: brightlu4GX5H

Please take a look at this topic in the Fusion API Help.  The idea of components, occurrences, and proxies can be a challenge to understand.  I think in your case, you actually want to assign the attributes to the proxies of the curves rather than the native curves in the component.

Brian Ekins
Inventor and Fusion 360 API Expert

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