# How, from python-scritps, to trigger the click-function of "center of the 3D view on the scene"?

**URL:** <https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181>\
**Category:** Support\
**Created:** [August 26, 2019, 6:34pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181 "2019-08-26T18:34:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 26, 2019, 6:34pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/1 "2019-08-26T18:34:44Z")

</div>

Hi all,  
I am lazy to try to click on the “Center of the 3D view on the scene” each time after I have a 3D-view there. So based on python codes, how to trigger the click-function to get “Center of the 3D view on the scene”?  
Thanks in advance!

---

<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:** [August 26, 2019, 6:55pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/2 "2019-08-26T18:55:02Z")

</div>

This should help: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Center\_the\_3D\_View\_on\_the\_Scene](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Center_the_3D_View_on_the_Scene)

What is your workflow? Would you re-center the 3D view the first time you show something in the 3D view or each time you load some data, each time you show/hide something, …?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 26, 2019, 7:04pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/3 "2019-08-26T19:04:03Z")

</div>

This kind of question comes up from time to time and it can be a good way for ne developers to learn about the architecture of Slicer by looking through the source code. One way is to look for the tooltip (e.g. use `git grep`) and find either the code or `.ui` file where the GUI element is declared. From there you can get the name of the widget (in this case `CenterButton`) and find where it is used in the code. Here the `triggered()` signal is connected to the `resetFocalPoint()` slot. As you look at the code you can get an appreciation of the separation of GUI from Logic and MRML operations that support the scriptability.

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 26, 2019, 7:16pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/4 "2019-08-26T19:16:22Z")

</div>

Hi Andras, Thanks a lot.  
What I do is that, load a grey image and a labeled-like image, then convert the label-like image to be segments, then those selected segments shown in 3D view to take a movie. So each time I do not want to click it again and again to adjust all those properties/features, that means, I would set all same settings for my movie.  
I will follow your instruction site to go ahead. Thanks again.  
Aiden

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 26, 2019, 7:34pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/5 "2019-08-26T19:34:42Z")

</div>

@pieper Thank you. You are right about the point you mentioned. As a new (potential) developer, I was always confused by how to control the scene/slice stuff existing there now, a good starting line for me at least. So if you guys may get a better summarized tutorial focusing on how to control the settings (existing there as we see while we open slicer), that will be really helpful for us to get started on Slicer development/application.  
Thanks again.  
Aiden

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 26, 2019, 8:29pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/6 "2019-08-26T20:29:41Z")

</div>

@lassoan Thanks a lot. It works while I use this resetFocalPoint().

In my mind if inside slicer.qMRMLSegmentEditorWidget() there might be a signal emitted out while we click “Show 3D”, that will be more helpful since from there I could right away set up the 3D-view and observe the 3D-view before I may take a movie.

Now since I canNOT get to “Show 3D” in the segment-editor, so after I click “Show 3D”, I have to do the settings on the time I open the new module of “Screen Capture” where I add the following there. It works!

layoutManager = slicer.app.layoutManager()  
threeDWidget = layoutManager.threeDWidget(0)  
threeDView = threeDWidget.threeDView()  
threeDView.resetFocalPoint()

Thanks a lot again.

---

<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:** [August 26, 2019, 11:55pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/7 "2019-08-26T23:55:04Z")

</div>

> [@aiden.zhu](#):
>
> Now since I canNOT get to “Show 3D” in the segment-editor

What do you mean? You would like to know how to create 3D representation for a segmentation node? There are examples in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository) for most commonly raised questions, including this one.

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 27, 2019, 12:44pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/8 "2019-08-27T12:44:06Z")

</div>

Hi Good morning, @lassoan  
Here I show what I do using screen shots:

1. load a grey image and its label-like image  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/e/7e46f825ab591d1d82303d813f279bf98824239c.png)
2. With a modified “segment Editor”, I use “threshold” to have segments from the label-like image.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/7/07d225eaf45560074875dddcc265c9d7a9fff2df.png)
3. Click “Show 3D”  
for the Step-3, I would like to see 3D-view ready for my movie right away after my clicking, but right now I do not see anything inside the view1 (3D). So have to (A) click that “Center the 3D view on the scene”  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/d/0d11786b8dfbd99e99452de4e5d4333e6cb53354.png)  
and then I have to (B) scroll the mouse middle-button to zoom-in to see my segments  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/b/0b2037f3b4bc1e94f509cf8f6ec67bbebf9f2dad.jpeg)  
So in my mind I would like to get (A) and (B) done by scripts. My question is how to get (A) and (B) using python codes.  
Thanks a lot.  
Best,  
Aiden

---

<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:** [August 27, 2019, 1:15pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/9 "2019-08-27T13:15:23Z")

</div>

Posts above should have answered these questions. If you would like us to write parts of your script then please upload your current script to github and post the link here so that we can work on it together (and we may put the end result into the the script repository)

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 27, 2019, 1:41pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/10 "2019-08-27T13:41:15Z")

</div>

Please let me have some time to get to know how to use github. 😅

---

<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:** [August 27, 2019, 1:41pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/11 "2019-08-27T13:41:50Z")

</div>

This should help: [https://guides.github.com/activities/hello-world/](https://guides.github.com/activities/hello-world/)

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 27, 2019, 4:54pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/12 "2019-08-27T16:54:52Z")

</div>

Thanks a lot. It really helps.

Here is my file loaded here:

> <https://github.com/AidenZhu186/fromSegmentEditor2Set3DView/blob/master/SegmentEditorAiden.py>

---

<div class="post-metadata">

**Author:** ![rimaaaak](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rimaaaak](https://discourse.slicer.org/u/rimaaaak)\
**Post date:** [December 14, 2023, 8:03pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/13 "2023-12-14T20:03:37Z")

</div>

Hi. I wanted to create a button to bring the 3D view back to its original position. How can I do that?

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [January 19, 2024, 4:52pm UTC](https://discourse.slicer.org/t/how-from-python-scritps-to-trigger-the-click-function-of-center-of-the-3d-view-on-the-scene/8181/14 "2024-01-19T16:52:59Z")

</div>

you need a have module (class ScriptedLoadableModule) and then inside its widget pat to add your button.

You may start with how to create a GUI module.
