Thanks for the reply @kandennti! This is a great solution and I've learned so much from that solution. Thanks again for sharing it.
I did some digging on the Fusion360 API and my code during the day. As we all know, it is always good to give it some time. I guess the reason of attributes on the references documents being not available is the following implementation detail on the Fusion360 API:
When a document is opened that references other documents, only the top-level document will cause the documentOpened event to be fired.
Ref (Application.documentOpened): https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-270c87f0-04d7-4bd8-9632-0e025d68df39
This makes sense to me because the attributes on the active document are available but attributes on the referenced documents are not available and the above statement explains a difference between active document and referenced documents.
I am not sure if I discussed this in my first post but I am using "Edit in Place" function to edit linked components in my document. I am adding a SketchPoint from the UI and assigning attributes using a custom add-in that I have been working on for a while.
I see that the SketchPoint is stored on the linked component. If open the linked component separately, I can see the SketchPoint that I added via "Edit in Place". However, its attribute is empty for some reason. If I go back to the document which has a link to that component and query the attribute from the Design instance, I can retrieve it.
Therefore, I changed my implementation a little bit and I started using the attributes to get to the parents. To make it more clear, I'd like to share a code snippet below for the Application.documentOpened event:
import traceback
from adsk import core, fusion
class MyDocumentOpenedHandler(core.DocumentEventHandler):
def __init__(self) -> None:
super().__init__()
def notify(self, args: core.DocumentEventArgs) -> None:
try:
# Get design
design = args.document.design
# Get root component
root_component = design.rootComponent
# Get the items with the specificied attributes
attribs = design.findAttributes("my_group", "my_attr_name")
for attr in attribs:
attr_entity = attr.parent
# Check if this attribute belongs to a SketchPoint
if not attr_entity.objectType == fusion.SketchPoint.classType():
continue
# Do whatever you like
except:
print("Error in {}:\n{}".format(self.__class__.__name__, traceback.format_exc()))