# Sphere brush via script

**URL:** <https://discourse.slicer.org/t/sphere-brush-via-script/9066>\
**Category:** Development\
**Created:** [November 7, 2019, 6:20pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066 "2019-11-07T18:20:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [November 7, 2019, 6:20pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066/1 "2019-11-07T18:20:02Z")

</div>

Hi, i can’t find the script to switch to sphere brush (or edit in 3d views as well),  
i tried this but it doesen’t seem to work:

> ```
> import EditorLib
> paramnode = EditorLib.EditUtil.EditUtil().getParameterNode()
> paramnode.SetParameter('PaintEffect,sphere', '1')
> 
> ```

Thanks for any inputs

---

<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:** [November 7, 2019, 7:00pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066/2 "2019-11-07T19:00:22Z")

</div>

Please do not use the legacy Editor module but switch to Segment Editor module. Parameter names controlling paint effect are described [here](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/EditorEffects/qSlicerSegmentEditorPaintEffect.cxx#L1478-L1487). Examples of scripting Segment Editor effects are available [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script).

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [November 7, 2019, 9:02pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066/3 "2019-11-07T21:02:19Z")

</div>

Thanks, that worked well, however i got another problem while using this to enable sphere brush; the checkbox on Segment Editor gets “stuck” and doesen’t work as a switch anymore:

> ```
> editor = slicer.modules.segmenteditor.widgetRepresentation().self().editor
> paint = editor.effectByName("Paint")
> paint.setParameter("BrushSphere", 1)
> 
> ```

---

<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:** [November 7, 2019, 9:05pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066/4 "2019-11-07T21:05:17Z")

</div>

As you can see in the code that I linked above, BrushSphere is a “common” parameter (so that the same setting can be used in paint and erase effects) and has to be set accordingly using `setCommonParameter`. Using `setParameter` would override the parameter value for a particular effect and so Segment Editor module GUI (that adjusts the common parameter value) would not have an effect anymore.

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [November 7, 2019, 9:09pm UTC](https://discourse.slicer.org/t/sphere-brush-via-script/9066/5 "2019-11-07T21:09:04Z")

</div>

Thanks a lot, it works fine.
