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

Missing dataFileComplete events after using saveCopyAs

sent-hil
Participant

Missing dataFileComplete events after using saveCopyAs

sent-hil
Participant
Participant

Hi,

 

I'm trying to write a script that copies over a base file x number of times and then sets different custom parameters in those files based on the file name. The script is here: https://gist.github.com/sent-hil/aa0c1f30abbf5b852de3cb348934c998

 

I'm using this following code to listen to file creation:

 

onDataFileComplete = MyDataFileCompleteHandler()
app.dataFileComplete.add(onDataFileComplete)
handlers.append(onDataFileComplete)

 

In the script MyDataFileCompleteHandler#notify does nothing but logs `args.file.name`. When I run the script I expect to see `MyDataFileCompleteHandler: <file name` 6 times, however, at times I'll see it 4 times or sometimes 5 times. As x increases, the chances of events being dropped increase. No matter how long I wait, the remaining onDataFileComplete are never fired.

 

I tried using `time.sleep` and  `adsk.doEvents()` to let it complete, but that didn't help.

 

Bug in API perhaps? Would appreciate some help.

 

Thanks,

Senthil

ToolWall

0 Likes
Reply
Accepted solutions (1)
352 Views
4 Replies
Replies (4)

kandennti
Mentor
Mentor

Hi @sent-hil .

 

Perhaps the variable "handlers" is released before the process is complete, and therefore the event is not fired.
Simply put, I don't think the dataFileComplete event is available to the script.

 

I have created an add-in to try the same process and have attached it for your reference.
After launching the add-in, you can execute this command to display the dialog.

1.png

 

The execution result is here.

1.png

 

However, when trying several times, it sometimes outputs incorrect messages as shown below, but we could not find the cause.

1.png

0 Likes

sent-hil
Participant
Participant

Hi @kandennti,

 

That is the behavior I sometimes see as well. It calls the event handler with the same file argument multiple times at times which is very unfortunate.

 

Are there any other ways to check if a file has been saved?

 

Thanks.

0 Likes

sent-hil
Participant
Participant
Accepted solution

Unfortunately, that didn't work either. I kept getting 'can't download file' when trying to open the file from the array, even though the file existed in the array.


However, I was able to solve the problem by modifying the user parameters first, then using `Document#saveAs` to save to a new document.

 

for file_name, user_params in HOLDERS.items():
    # Open the current document
    opened_document = app.documents.open(current_data_file, True)
    opened_design = app.activeProduct

    # Set user parameters
    for param_name, param_value in user_params.items():
        param = opened_design.userParameters.itemByName(param_name)
        if param:
            param.expression = param_value
    
    # Save the modified document in the new folder
    opened_document.saveAs(file_name, new_folder, '', '')
    opened_document.close(False)

 

Thanks for your reply.

1 Like