Need help for a basic coding to make extension

Hi, I’m using 3d slicer for repeated works so I want to make my own menu to do it faster.
I have only a basic knowledge of a python language and don’t understand the structure of 3d slicer.
I’m trying to learn through searching but if someone gives me an example, it would be really helpful to understand the basic structure of coding.
image
Let’s say I want to make a menu like the image above.
Please show me a code and where to put that code.
(Of course not only a button or a tap for a visual thing but also need a code for functions(making point list, placing a point and linking the functions to the buttons…etc)

Thanks.

Hi telomere,

these are good starting points:

https://slicer.readthedocs.io/en/latest/developer_guide/index.html

https://www.slicer.org/w/index.php?title=Documentation/Nightly/Developers

Cheers

Kambiz

Particularly these parts:
Extensions section of developer guide
FAQ section
User guide for exensions

The extension wizard is the way to start. You can use it to just make an extension with one scripted module, no C++. Then the extension would be distributed as python source files only and there’s no building process for it.

You can see the scripted modules that come with Slicer for examples: https://github.com/Slicer/Slicer/tree/main/Modules/Scripted
E.g. the endoscopy module is a nice example: https://github.com/Slicer/Slicer/tree/main/Modules/Scripted/Endoscopy
And the script repository has lots of useful sippets: Script repository — 3D Slicer documentation

Thanks for the answer.
As you said Endoscopy module is a nice example to study.
And the github link is also very helpful.

Would you mind if i ask some more…
Scripts of some modules like endoscopy are shown in the link but many built-in modules like Volume rendering, Segmentation or Markups are not given as scripts but as a more complicated way…

If it’s very easy for you, could you tell me what should I do, for example, to take volume rendering into my own extension?

many built-in modules like Volume rendering, Segmentation or Markups are not given as scripts but as a more complicated way

Right, see the difference between scripted and loadable modules here: Module Overview — 3D Slicer documentation

take volume rendering into my own extension

What does this mean exactly?

Do you mean you want to include the volume rendering module widgets as part of your own module?
I think that’s not advisable – the Slicer way of doing things is to split things across individual modules that each do their own thing well, and to have the user switching between those modules for their overall workflow.

Ah…okay. As you guessed, I wanted to include the volume rendering module widgets as a part of my own module, because I’m doing repeated works so I have to switch modules to often and it makes me too tired…
I think making buttons that go to the modules needed and making a shortcut that comes back to my modules is the most possible solution in my situation.
Thanks.

1 Like