# Strange Behaviour Scripting with Curve Maker Extension \[Solved\]

**URL:** <https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575>\
**Category:** Development\
**Tags:** extensions-manager, python\
**Created:** [June 26, 2017, 9:23pm UTC](https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575 "2017-06-26T21:23:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_jmichael](https://avatars.discourse-cdn.com/v4/letter/_/ce7236/32.png) [@\_jmichael](https://discourse.slicer.org/u/_jmichael)\
**Post date:** [June 26, 2017, 9:23pm UTC](https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575/1 "2017-06-26T21:23:33Z")

</div>

I’m working with the 3D slicer extension [CurveMaker](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/CurveMaker) that makes line/curve models based on fiducials. I wrote a simple convenience function (below) in python that sends all of the sets of MarkupsFiducial in the scene to CurveMaker and the function works **but** only if, since opening Slicer, I have first navigated to the CurveMaker module. If I haven’t, attempting to access ‘slicer.modules.CurveMakerWidget’ returns, "object has no attribute ‘CurveMakerWidget’ ".

How do I avoid this problem without requiring user interaction? Am I breaking best-practices by trying to access the logic through the widget? or is this simply a bug/shortcoming in the module?

```
def sendAllFiducialsToCurveMaker():
  N = slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsFiducialNode')
  ####
  #line below returns "AttributeError: 'module' object has no attribute 'CurveMakerWidget' " 
  #unless I have first navigated to the Curve Maker module
  cml = slicer.modules.CurveMakerWidget.logic 
  ####
  for i in xrange(N):
    cml.SourceNode = slicer.mrmlScene.GetNthNodeByClass(i,'vtkMRMLMarkupsFiducialNode')
    outputModel = slicer.vtkMRMLModelNode()
    slicer.mrmlScene.AddNode(outputModel)
    cml.DestinationNode = outputModel
    cml.generateCurveOnce()
```

---

<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:** [June 26, 2017, 9:50pm UTC](https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575/2 "2017-06-26T21:50:10Z")

</div>

The module widget is created “lazily” so as you saw it only exists after visiting the module once.

You can do this programmatically with something like this:

```auto
mainWindow = slicer.util.mainWindow()
mainWindow.moduleSelector().selectModule('CurveMaker')

```

HTH,  
Steve

---

<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:** [June 26, 2017, 10:01pm UTC](https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575/3 "2017-06-26T22:01:52Z")

</div>

I would recommend to use “Markups to model” module in SlicerIGT extension.

It does everything that CurveMaker but much more (for example it can handle any number of models, not just one; it can also generate surfaces) and it is a full-featured module: saving/reloading state to the scene works well, initialization is done properly (no need to open the module GUI), it is faster (fully implemented in C++), etc.

---

<div class="post-metadata">

**Author:** ![\_jmichael](https://avatars.discourse-cdn.com/v4/letter/_/ce7236/32.png) [@\_jmichael](https://discourse.slicer.org/u/_jmichael)\
**Post date:** [June 27, 2017, 1:53pm UTC](https://discourse.slicer.org/t/strange-behaviour-scripting-with-curve-maker-extension-solved/575/4 "2017-06-27T13:53:35Z")

</div>

@pieper and @lassoan, both excellent solutions. Also re-assuring to know I hadn’t missed something obvious.

Thanks for your help!
