# Show DICOM browser's folder import dialog

**URL:** https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347
**Category:** Development
**Tags:** dicom
**Created:** [December 1, 2019, 9:13pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347 "2019-12-01T21:13:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 1, 2019, 9:13pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/1 "2019-12-01T21:13:08Z")

</div>

How Can i directly Call(or popup) DICOM Browser → Import

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/c/4c5e4976c585042b0086bddfef1d5f3d477f2b97.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8add91ed4ff4381938dc82ae3cd5317518fd7e76.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 1, 2019, 9:20pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/2 "2019-12-01T21:20:15Z")

</div>

In recent Slicer Preview releases, you can do this to show folder selector for DICOM import:

```python
slicer.util.selectModule('DICOM')
slicer.modules.DICOMInstance.browserWidget.dicomBrowser.openImportDialog()

```

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 3, 2019, 12:29am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/3 "2019-12-03T00:29:46Z")

</div>

Thank you very much. Have a Nice Day 🙂

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 3, 2019, 12:49am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/4 "2019-12-03T00:49:09Z")

</div>

But i want to call in my qSlicerMainWindow.cxx file.

in other words.

i want to call python script in my c++ code

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 3, 2019, 3:55am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/5 "2019-12-03T03:55:22Z")

</div>

You can run Python code from C++ using [`pythonManager->executeString`](http://pythonManager-%3EexecuteString).

If you want to import DICOM files from a folder then you can create ctkDICOMIndexer independent from the one in the DICOM browser as shown in [this example](https://github.com/commontk/CTK/blob/master/Libs/DICOM/Core/Testing/Cpp/ctkDICOMIndexerTest1.cpp#L36-L51).

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 3, 2019, 11:35am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/6 "2019-12-03T11:35:03Z")

</div>

Thank you. i will do it ^^

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 6, 2019, 1:19pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/7 "2019-12-06T13:19:25Z")

</div>

> [@lassoan](#):
>
> slicer.util.selectModule(‘DICOM’) slicer.modules.DICOMInstance.browserWidget.dicomBrowser.openImportDialog()

I am making the source code but it is very hard to me to call python code in my c++ in slicer  
for showing DICOM browser’s folder import dialog

[`pythonManager->executeString`](http://pythonmanager-%3Eexecutestring/).

slicer.util.selectModule(‘DICOM’)  
slicer.modules.DICOMInstance.browserWidget.dicomBrowser.openImportDialog()

i found similar code but not work for me  
[Show DICOM browser’s folder import dialog](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 6, 2019, 3:05pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/8 "2019-12-06T15:05:07Z")

</div>

> [@lausiv](#):
>
> it is very hard to me to call python code in my c++

If you have any specific issue with calling Python from C++ then let us know. If you prefer staying in C++ then you can follow the example in CTK that I referred to [above](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/5).

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 7, 2019, 5:06am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/9 "2019-12-07T05:06:26Z")

</div>

I will do it at Slicer Preview releases^^

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/f/efbe7a5d82c650cef334fbe523aea994845ebbf2.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 7, 2019, 11:53am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/10 "2019-12-07T11:53:22Z")

</div>

DICOM browser changed recently, so the code to show the it may be slightly different for the stable release.

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 8, 2019, 1:53pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/11 "2019-12-08T13:53:59Z")

</div>

> [@lassoan](#):
>
> w the it may be slightly different for the stable release.

i saw the source code but i think there’s many changes between stable vs. preview release.

it is now working for me;

similar situation,

i want to show DICOM browser’s folder export dialog  
preview release doesn’t support this.

would show me the sample code?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/84ff73fc90748404ccbc0d50b7320b1789437972.png)

seconde question 🙂  
after exporting DICOM Data, i want to delete previous data which is used for exporting. i want python script code example.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/df94d5b926b279c1b2b0f3f4aa73e425eecc26c8.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 9, 2019, 5:32am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/12 "2019-12-09T05:32:57Z")

</div>

> [@lausiv](#):
>
> i want to show DICOM browser’s folder export dialog  
> preview release doesn’t support this.

Everything that the old DICOM browser could do, the new one can do, too. What code did you use previously to show the export dialog?

> [@lausiv](#):
>
> i want to delete previous data which is used for exporting

You can use [removePatient](http://www.commontk.org/docs/html/classctkDICOMDatabase.html#a817e5e86cf586de30300857342d778a2)/removeStudy/removeSeries to delete selected items or [cleanup](http://www.commontk.org/docs/html/classctkDICOMDatabase.html#a6dee54db9ca85225bb495815851eb10e) to remove all database content. But a more common approach is to create a temporary DICOM database and then remove it completely (using openTemporaryDatabase/closeTemporaryDatabase - see [example](https://github.com/Slicer/Slicer/blob/0abd1fa219628f0dfd5166e430afeb1598b6fcf8/Applications/SlicerApp/Testing/Python/RSNAVisTutorial.py#L194-L292)).

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 9, 2019, 5:42am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/13 "2019-12-09T05:42:49Z")

</div>

> i want to show DICOM browser’s folder export dialog  
> preview release doesn’t support this.

Everything that the old DICOM browser could do, the new one can do, too. What code did you use previously to show the export dialog?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/d/6d6fc78308efa02b3fa2c69d1d2a7eb9e61f84c5.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8ab2242fa5b2d15c6ddda26714565bdfd801cd51.png)

I just execute below python script.  
slicer.util.selectModule(‘DICOM’)  
slicer.modules.DICOMInstance.browserWidget.dicomBrowser.openExportDialog()

**i want to call directly export dialog like import dialog**  
ex)  
slicer.util.selectModule(‘DICOM’)  
slicer.modules.DICOMInstance.browserWidget.dicomBrowser.openImportDialog()

Thank you for your concern and effort^^

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 9, 2019, 6:21pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/14 "2019-12-09T18:21:11Z")

</div>

You can show export dialog in recent Slicer versions like this:

```python
exportDialog = slicer.qSlicerDICOMExportDialog()
exportDialog.setMRMLScene(slicer.mrmlScene)
exportDialog.execDialog()

```

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 10, 2019, 2:50am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/15 "2019-12-10T02:50:55Z")

</div>

Thanks Lasso^^, It workd now.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c118ed846b9245e93be0e1ff180e29f4c40439a.png)

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 10, 2019, 10:37am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/16 "2019-12-10T10:37:53Z")

</div>

I can’t find exact script code for this issue. in other words, exact function or call flow  
i already examine your related sample code and source code in slicer DICOMUtil.py  
Would you plz share sample script code to delete previous data which is used for exporting^^.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/3/c3357ddae00050ae5a1a68f191b7a3ca5911b78d.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e32e20b8bdeb9757fbe93c9d7c9885f20139ec0e.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/bae2d72ca8563bee7427dc1c2f1d0029b0744b03.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 10, 2019, 8:04pm UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/17 "2019-12-10T20:04:47Z")

</div>

If you want to add series to the database temporarily (only to allow loading), then I would recommend to create a temporary database as I described above.

Using `dicomDatabase.remove...` methods is more complicated: first you need to store all previously existing series in the database in a variable, then import data that you need, get all series in the database, remove all the series that did not exist previously, and finally remove all orphan studies and patients.

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 11, 2019, 12:12am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/18 "2019-12-11T00:12:22Z")

</div>

If you want to add series to the database temporarily (only to allow loading), then I would recommend to create a temporary database as I described above.  
==\> I understand now. this approach is simple for my issue. just create database and add it to new database and delete existing old database.  
I will do it and let it shared in this page^^

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 17, 2019, 2:11am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/21 "2019-12-17T02:11:55Z")

</div>

when i call pythonManager() in C++  
I found compiler can’t find pythonManager()  
(i already investigate related source codes)

in other words,  
qSlicerApplication::application()-\>layoutManager() \<== it is OK.  
**qSlicerApplication::application()-\>pythonManager() \<== it is NO**

A type cannot be used until it is defined. To resolve the error, be sure the type is fully defined before referencing it.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/d/bdf3a4916ba0e5a96b8ab815004634bc2f3637bb.png)

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/0/50889c89d3d560e19bc52fac6c42322ef84720ce.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/6/d6c7a1faafd6acb7aad1b6ef0e0399bbaaac8b26.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 17, 2019, 2:45am UTC](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347/22 "2019-12-17T02:45:07Z")

</div>

In C++, to use a class that is implemented in another library, you need to `#include` the corresponding header file and add the include directory and library to the CMakeLists.txt file of the component that you are building. There are thousands of examples for this in Slicer source code (all classes are used like this).

[Next page](https://discourse.slicer.org/t/show-dicom-browsers-folder-import-dialog/9347.md?page=2)
