# Create a cylinder based on user input

**URL:** <https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911>\
**Category:** Development\
**Created:** [October 26, 2019, 12:47am UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911 "2019-10-26T00:47:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpontin](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mpontin](https://discourse.slicer.org/u/mpontin)\
**Post date:** [October 26, 2019, 12:47am UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/1 "2019-10-26T00:47:45Z")

</div>

Hi everybody,  
I’m new to 3DSlicer so I don’t really know where to begin.  
I’m trying to develop a module in order to automatically create a cylinder based on user input.  
The idea is that the user selects a radius, then clicks on the point which will be the axis of the cylinder. Once the cylinder is created I want to show it and finally merge it with the previously loaded data.  
Any suggestion is greatly appreciated.  
Thank you!  
Marco

---

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [October 26, 2019, 1:27am UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/2 "2019-10-26T01:27:53Z")

</div>

I recently needed to do this and I found the easiest method was to use the Markups to Models module included in the slicerIGT extension. This let’s you create a cylinder with at least 2 markup fiducials.

---

<div class="post-metadata">

**Author:** ![mpontin](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mpontin](https://discourse.slicer.org/u/mpontin)\
**Post date:** [October 27, 2019, 4:33pm UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/3 "2019-10-27T16:33:44Z")

</div>

Thanks a lot for the info Prashant\_Pandey!  
One more question: is it possible to call the Markups to Models module from the python interactor?  
Based on the user input I created some fiducials in a python script. Now I would like to use these to create a closed surface automatically.  
Thanks

---

<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:** [October 27, 2019, 4:58pm UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/4 "2019-10-27T16:58:43Z")

</div>

You may also use markups lines or SegmentEditorExtraEffects extension’s Draw Tube effect. What would you like to achieve?

---

<div class="post-metadata">

**Author:** ![mpontin](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mpontin](https://discourse.slicer.org/u/mpontin)\
**Post date:** [October 27, 2019, 5:05pm UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/5 "2019-10-27T17:05:12Z")

</div>

Hello lassoan,  
The idea is that the user inserts a fiducial point in the center of the base of the cylinder and chooses a radius. Based on this information I want to automatically create a cylinder so that then I can merge the cylinder with the original volume and export as .stl  
Thanks

---

<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:** [October 27, 2019, 5:14pm UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/6 "2019-10-27T17:14:38Z")

</div>

How do you merge a cylinder (surface mesh) with a volume? If you do it in Segment Editor for that then Draw Tube effect may be the simplest method.

---

<div class="post-metadata">

**Author:** ![mpontin](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mpontin](https://discourse.slicer.org/u/mpontin)\
**Post date:** [October 27, 2019, 5:21pm UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/7 "2019-10-27T17:21:32Z")

</div>

I’m sorry, I’m new to Slicer and it’s not clear to me what is the simplest way forward.  
Based on the fact that I’d like to merge the cylinder (either obtained as surface or volume) with the existing volume in order to 3Dprint the two together, what would you suggest?  
Right now I have fiducials placed in a circle on two different levels on the z axis. Is it possible to create a solid cylinder starting from this configuration?  
Thank you very much for the patience.

---

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [October 28, 2019, 3:17am UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/8 "2019-10-28T03:17:03Z")

</div>

I am sure you can access and use the logic of the Markups To Models in a python script, but I am not sure what the exact function calls are.

For combining the two, I would recommend converting the pertinent structure in your medical volume into a segment using a the ‘segment editor’ module and converting your cylinder model into a segment by importing it as a label map from the ‘segmentations’ module. You can then combine the two label maps and export as a surface model, which you can save as an .stl file to be used with your printer.

---

<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:** [October 28, 2019, 11:38am UTC](https://discourse.slicer.org/t/create-a-cylinder-based-on-user-input/8911/9 "2019-10-28T11:38:29Z")

</div>

Draw tube effect creates a cylinder-shape segment from input markup points, so this seems to be the most direct solution. There are also many examples of running segment editor effects from scripts in the script repository: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How\_to\_run\_segment\_editor\_effects\_from\_a\_script](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script)
