move(targetFolder) method on dataFile object broken?

move(targetFolder) method on dataFile object broken?

SendItCNC
Advocate Advocate
504 Views
4 Replies
Message 1 of 5

move(targetFolder) method on dataFile object broken?

SendItCNC
Advocate
Advocate

dataFile.move(targetFolder) causes the dreaded "A software problem has caused Fusion to close unexpectedly" message. Ouch.

 

dataFile.copy(targetFolder) works just fine.

 

Here's a minimal amount of code that demonstrates the problem. The important part is the last line where Fusion blows up. Change move() to copy() in the last line and it works fine.

 

Any ideas for a workaround? I'd really like to move some dataFiles.

 

Thanks, -Dave

 

p.s. Wouldn't it be nice to have a itemByName() method on the dataFolders and dataProjects objects?

 
app = adsk.core.Application.get()
ui = app.userInterface

projectName = 'Test'
project = None
for checkProj in app.data.dataProjects:
    if checkProj.name == projectName:
        project = checkProj
        break
if project is None:
    ui.messageBox("Project '{}' not found".format(projectName), '', adsk.core.MessageBoxButtonTypes.OKButtonType,    adsk.core.MessageBoxIconTypes.InformationIconType)
    return

testFileName = 'TestFile'
testFile = None
for checkFile in project.rootFolder.dataFiles:
    if checkFile.name == testFileName:
        testFile = checkFile
if testFile is None:
    ui.messageBox("File '{}' not found".format(testFileName), '', adsk.core.MessageBoxButtonTypes.OKButtonType, adsk.core.MessageBoxIconTypes.InformationIconType)
    return

testFolderName = 'TestFolder'
testFolder = project.rootFolder.dataFolders.itemByName( testFolderName )
if testFolder is None:
    ui.messageBox("Folder '{}' not found".format(testFolderName), '', adsk.core.MessageBoxButtonTypes.OKButtonType, adsk.core.MessageBoxIconTypes.InformationIconType)
    return
 
testFile.move( testFolder )

 

0 Likes
Accepted solutions (1)
505 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

Hi @SendItCNC .

 

I tried it and the move method crashed Fusion360 for me too.
I think it is probably a bug.

Message 3 of 5

BrianEkins
Mentor
Mentor
Accepted solution

I can reproduce this and will make sure a bug gets filed.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 4 of 5

Dave.SendItCNC
Contributor
Contributor

@BrianEkins 

 

Interesting update on this...

 

dataFile.move() is now much improved and works... mostly.

If the file to be moved has been saved by Fusion, it seems to work perfectly.

 

However, in the case of files that were just uploaded (from .f3d's), move() throws an exception: Run time error 2, validation, res. The move is actually completed, despite the exception.

 

Interestingly, copy works fine on such files. 

 

-Dave

Message 5 of 5

Dave.SendItCNC
Contributor
Contributor

Actually, I'll withdraw this pending further investigation.

 

It appears that the explanation may be that  since the move() is on a file which is the subject of an iterator, the iterator becomes invalid as a result of the move(). I'm seeing it work in cases where the iterator  is over dataFiles.asArray() rather than dataFiles.

0 Likes