Skip to content

Instantly share code, notes, and snippets.

@talmazov
Created June 19, 2022 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talmazov/b294c11c0a6a25fe3c8889cc57419b3a to your computer and use it in GitHub Desktop.
Save talmazov/b294c11c0a6a25fe3c8889cc57419b3a to your computer and use it in GitHub Desktop.
3d slicer - passing/setting a variable in a python module at startup
"""
@author: Patrick R. Moore, Georgi Talmazov
"""
from __main__ import vtk, qt, ctk, slicer
class BlenderTest:
def __init__(self, parent):
parent.title = "blender_test"
parent.categories = ["Dentistry"]
parent.dependencies = []
parent.contributors = ["Patrick Moore", "Georgi Talmazov (Dental Software Foundation)"] # replace with "Firstname Lastname (Org)"
parent.helpText = """
Example of scripted loadable extension for the HelloPython tutorial that monitors a directory for file changes.
"""
parent.acknowledgementText = """Independently developed for the good of the world""" # replace with organization, grant and thanks.
self.parent = parent
#
# qHelloPythonWidget
#
class BlenderTestWidget:
def __init__(self, parent = None):
if not parent:
self.parent = slicer.qMRMLWidget()
self.parent.setLayout(qt.QVBoxLayout())
self.parent.setMRMLScene(slicer.mrmlScene)
else:
self.parent = parent
self.layout = self.parent.layout()
if not parent:
self.setup()
self.parent.show()
self.host_port = 5959
def setup(self):
# Instantiate and connect widgets ...
# Collapsible button
sampleCollapsibleButton = ctk.ctkCollapsibleButton()
sampleCollapsibleButton.text = "Configuration:"
self.layout.addWidget(sampleCollapsibleButton)
# Layout within the sample collapsible button
self.sampleFormLayout = qt.QFormLayout(sampleCollapsibleButton)
#Models list
addModelButton = qt.QPushButton("Add Model")
addModelButton.toolTip = "Add a model to the list to sync with Blender."
self.sampleFormLayout.addRow(addModelButton)
#addModelButton.connect('clicked()', self.onaddModelButtonToggled)
def connect_to_blender(self, port):
self.host_port = port
print(self.host_port)
import subprocess
slicer_startup_parameters = ''.join(("slicer.util.selectModule('BlenderTest')\n",
"slicer.util.getModule('BlenderTest').widgetRepresentation().self().connect_to_blender(55)"))
subprocess.Popen(["C:\\ProgramData\\NA-MIC\\Slicer 5.0.2\\Slicer.exe", "--python-code", slicer_startup_parameters])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment