Can't export segmentation as Dicom RTStruct in Python Script

Operating system: Python Script
Slicer version: 4.11.20210226
Dear authors,
Everything seems to be really good when i exported it by hand and I’ve followed your instructions video of exporting RT-STRUCT file by right click at Study and choose Export to DICOM then click in RT struct and got the result as i want.


But when i was doing it in python script by the following code, after passing the studyID as parameter, i got the result return ‘Exportable list contains no exportables’. Then, i have also tried to pass the segmentationID, but got another warning : ‘Must export the primary anatomical (CT/MR) image’. How can i fix this problem ?

Hope you reply me soon. Thank you so much.

This is a duplicate of this issue:

@Namng1210 Please do not duplicate threads especially without mentioning the other one as the community members helping you will duplicate work that others did in other threads.

Also I just see an email about your comment to that GitHub issue that it worked, but then you seem to have removed that comment. Then you post the original question here without any of the suggestions, and there is no trace about any information why that solution that seemed to work, finally (apparently) didn’t.

Now that we have a thread about this on GitHub let’s keep the discussion there, and a good start would be to react to the last suggestion. Thank you

Dear author,
This question was actually posted at the same time as my post on github.I’m so sorry because at that time, i really wanted to solve the problem and this is the first time that I joined this community.
Thanks a lot for your help and i’ll learn from my mistakes next time.
Best regards,
Nguyen Phuong Nam

Hello,
I am kinda new with python. Can you explain to me how you manage to solve this issue? (the github post is closed so I am asking here sorry…).

I tried to run the ExamineForExport function on the volume and the segmentations, then past them in a list for the export function, but it did not worked:

exporter = DicomRtImportExportPlugin.DicomRtImportExportPluginClass()
exportable1 = exporter.examineForExport(segmentationShItem)
exportable2 = exporter.examineForExport(referenceVolumeShItem)

for exp in exportable1:
exp.directory=outputFolder
for exp in exportable2:
exp.directory=outputFolder

exportables = [exportable1,exportable2]

exporter.export(exportables)
Traceback (most recent call last):
File “”, line 1, in
File “C:/Users/tmp/AppData/Roaming/NA-MIC/Extensions-29402/SlicerRT/lib/Slicer-4.11/qt-scripted-modules/DicomRtImportExportPlugin.py”, line 122, in export
exportable.copyToVtkExportable(vtkExportable)
AttributeError: ‘list’ object has no attribute ‘copyToVtkExportable’

thanks !