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

DocumentReference.referencedDocument broken

Anonymous

DocumentReference.referencedDocument broken

Anonymous
Not applicable

When I try to open a linked document from a documentReference object, Fusion has strange behavior. It will NOT activate the referenced document, but it will proceed to edit the occurrence of the document that is found within the document from which I am linking. For example, assume you have a pyramid made up of linked cubes. If both the pyramid and cubes were open, and your code attempted to walk to the cube by way of the referenceDocument property, you could then, say, edit the parameters. However, the viewport would stay on the pyramid and just the cube within the pyramid file would change, leaving the original linked file unchanged. I made a script below that isolates this problem that you can run with the pyramid design here: http://a360.co/2j8Rhfr and the cube design that it contains is here: http://a360.co/2Btgnfz . The script I'm running is this: 

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


def run(context):
    """Change parameters for a whole assembly by also changing parameters of
    linked components.
    """

    params_desired = {"Length": "10 in", "Width": "10 in", "height": "1 in"}

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        fdoc = app.activeDocument
        doc_refs = fdoc.documentReferences
        for i in range(doc_refs.count):
            doc_ref = doc_refs.item(i)
            fdoc = doc_ref.referencedDocument
            params = adsk.fusion.FusionDocument.cast(fdoc).design.allParameters
            # Loop through the parameters  dictionary in a single component
            for param_name in params_desired:
                param_desired = params_desired[param_name]
                param_actual = params.itemByName(param_name)
                if param_actual:
                    param_actual.expression = str(param_desired)

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

 And I'm posting a screencast:

 
0 Likes
Reply
202 Views
0 Replies
Replies (0)