DataFile.hasChildReferences in History
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey there everyone.
In the Japanese forum, there are sometimes posts saying "I can't delete a document in the Data Panel".
I think there is more than one cause, but recently I found out that one of the causes is the History of the document.
In order to delete a document, you need to find the document you are referring to.
The attached f3z file looks like this
If you press the pull-down button showing the version of "Part_A" in the data panel, the information will be displayed, and if you look at "Used In", you can see which document it is used in.
The following script will log the ID of the active document, access the DataFiles in the same DataFolder as the active document, and log the ID, name, and version.
DataFile accesses not only the latest version, but all versions, and does the same for the DataFile in the hasChildReferences Property.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-E3934C16-05D5-46D2-A4FF-068786F93C17
# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
# datafile
datafile: adsk.core.DataFile = getActiveDocDataFile()
if not datafile:
msg = 'No active documents are saved.'
ui.messageBox(msg)
return
targetId = datafile.id
# folder
datafolder: adsk.core.DataFolder = datafile.parentFolder
# version files
files = []
f: adsk.core.DataFile
for f in datafolder.dataFiles.asArray():
files.extend(f.versions)
app.log(f'- Target<ID>{targetId} -')
for file in files:
app.log(
f'\n*Document<ID>{file.id} <Name>{file.name} <Ver>{file.versionNumber}')
if len(file.childReferences) < 1:
continue
app.log('-Child References-')
for refFile in file.childReferences:
app.log(
f' <ID>{refFile.id} <Name>{refFile.name} <Ver>{refFile.versionNumber}')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
If you run the script with the attached file, Part_A, open, you will get this result.
- Target<ID>urn:adsk.wipprod:dm.lineage:NrhoPG0NSKGv4cPrCK4qKg -
*Document<ID>urn:adsk.wipprod:dm.lineage:yhUbUYc8ScGNuDe_mfyCMw <Name>Assy <Ver>1
-Child References-
<ID>urn:adsk.wipprod:dm.lineage:NrhoPG0NSKGv4cPrCK4qKg <Name>Part_A <Ver>1
*Document<ID>urn:adsk.wipprod:dm.lineage:NrhoPG0NSKGv4cPrCK4qKg <Name>Part_A <Ver>1
Documents that cannot be deleted can be created by doing the following.
Open the "Assy" documentation, delete the "Part_A" component (Occurrence) and save it.
If you check "Part_A" in the Data Panel, you will see that it is not referenced.
Now, if you try to close "Part_A" and delete it from the Data Panel, you will not be able to do so.
The reason you can't delete it is the history of "Assy". This is because the history holds Part_A.
I thought I could access "Part_A" if it was a childReferences in the Datafile of an older version of "Assy".
If this is possible, I thought it would be useful to find the document that holds the Link to delete.
Open Part_A again and run the previous script.
- Target<ID>urn:adsk.wipprod:dm.lineage:NrhoPG0NSKGv4cPrCK4qKg -
*Document<ID>urn:adsk.wipprod:dm.lineage:yhUbUYc8ScGNuDe_mfyCMw <Name>Assy <Ver>2
*Document<ID>urn:adsk.wipprod:dm.lineage:yhUbUYc8ScGNuDe_mfyCMw <Name>Assy <Ver>1
*Document<ID>urn:adsk.wipprod:dm.lineage:NrhoPG0NSKGv4cPrCK4qKg <Name>Part_A <Ver>1
Unfortunately, the childReferences in the old Datafile for "Assy" did not have "Part_A".
However, if you open the old "Assy" in the GUI, you will definitely see that "Part_A" is linked.
I am not going to discuss in the API forum how to remove such documents or how to manage the links.
Is it not possible to get the linked documents from an older version of Datafile?
If a user performs this operation, there is virtually no way to find the document that is causing the deletion failure.