Nonetype obj has no attr - rebinding it?

Discussions concerning programming of SOFTIMAGE©
bergj
Posts: 36
Joined: 06 May 2012, 03:58

Nonetype obj has no attr - rebinding it?

Post by bergj » 09 May 2012, 02:30

I've been trying to get the PyQtSI addon to work and have been in touch with the author but we have been unable to pinpoint the solution. The problem I'm having is that when I try to run a command from a button on a window, I get the following error. I have been trying to fix this for a few days.

Code: Select all

# Traceback (most recent call last):
#   File "<Script Block >", line 38, in logText
#   File "C:\Program Files\Autodesk\Softimage 2013\Application\python\Lib\site-packages\win32comext\axscript\client\pyscript.py", line 138, in __getattr__
#     return self._scriptItem_.subItems[attr.lower()].attributeObject
# AttributeError: 'NoneType' object has no attribute 'subItems'
And the corresponding lines 125-143 from pyscript.py are

Code: Select all

class NamedScriptAttribute:
	"An explicitely named object in an objects namespace"
	# Each named object holds a reference to one of these.
	# Whenever a sub-item appears in a namespace, it is really one of these
	# objects.  Has a circular reference back to the item itself, which is
	# closed via _Close_()
	def __init__(self, scriptItem):
		self.__dict__['_scriptItem_'] = scriptItem
	def __repr__(self):
		return "<NamedItemAttribute" + repr(self._scriptItem_) + ">"
	def __getattr__(self, attr):
		# If a known subitem, return it.
		try:
			return self._scriptItem_.subItems[attr.lower()].attributeObject
		except KeyError:
			# Otherwise see if the dispatch can give it to us
			if self._scriptItem_.dispatchContainer:
				return getattr(self._scriptItem_.dispatchContainer,attr)
		raise AttributeError, attr



I've tried dynamic dispatch but it made no difference. I recently saw a post http://www.softimageblog.com/archives/245 which talks about "rebinding" a variable but I'm not sure how to go about this or if this is what i want to do.

Code: Select all

oDiffuse.disconnect()
xsi.logmessage( oDiffuse.parameters( 'red' ).value )
Output:
# ERROR : Traceback (most recent call last):
# File "", line 14, in ?
# xsi.logmessage( oDiffuse.parameters( 'red' ).value )
# AttributeError: 'NoneType' object has no attribute 'value'
# - [line 14]

Code: Select all

oDiffuse.disconnect()

# Rebind parameter and variable
oDiffuse = oDiffuse.parent.parameters( 'diffuse' )
 
xsi.logmessage( oDiffuse.parameters( 'red' ).value )
____________________________________________

This is the script. I downloaded PyQt26 compiled against python 2.6, and the PyQtSI addon. It makes a window with a button on it and I get the error when I press the button.

http://www.riverbankcomputing.co.uk/sta ... .9.1-1.exe

https://github.com/caron/PyQtForSoftimage


I put the PyQt module and sip into "C:\Program Files\Autodesk\Softimage 2013\Application\python\Lib\site-packages"
http://pastebin.com/2YraLBtc

Code: Select all


from PyQt4.QtCore import Qt
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4.QtCore import pyqtSignal
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import QDialog
from PyQt4.QtGui import QWidget
from PyQt4.QtGui import QPushButton
from PyQt4.QtGui import QLineEdit
from PyQt4.QtGui import QVBoxLayout
from PyQt4.QtGui import QMenu
from PyQt4.QtGui import QCursor

import sip

anchor = sip.wrapinstance(long(Application.getQtSoftimageAnchor()), QWidget)

class ExampleDialog(QDialog):
	def __init__(self, parent):
		QDialog.__init__(self, parent)

		self.setGeometry( 100, 100, 200, 100 )
		
		self.btn = QPushButton("Make Cube", self)
		firstButton = self.btn
		
		firstButton.clicked.connect(self.cubeMaker)
				
		layout = QVBoxLayout(self)
		layout.addWidget(self.btn)
        
	def cubeMaker(self):

		Application.CreatePrim("Cube", "MeshSurface", "", "")

	def showAtMouse(self):
		self.show()
		pos = QtGui.QCursor.pos()
		self.move(pos.x(), pos.y())


def ExampleDialog_Execute():
    dialog = ExampleDialog(anchor)
    dialog.showAtMouse()

ExampleDialog_Execute()


bergj
Posts: 36
Joined: 06 May 2012, 03:58

Re: Nonetype obj has no attr - rebinding it?

Post by bergj » 11 May 2012, 22:20

OK I solved the problem by using a different pyQt solution by Blur studios. I still have an issue that I need to bind commands to the release command on the keyboard.

For example = I press F1 and launch a window and then delete it when I release F1 by having another script run that does window.close()

Surely this can be done someway? You can only partially do it in pyQt meaning that it only picks up the release command after a certain number of milliseconds

scaron
Posts: 119
Joined: 08 Jul 2009, 03:16

Re: Nonetype obj has no attr - rebinding it?

Post by scaron » 15 May 2012, 02:10

for those interested in this discussion and want to understand what transpired...

https://github.com/caron/PyQtForSoftimage/issues/2

to review, PyQtForSoftimage needs to use a registered command to create a PyQt dialog. i think it has to do with persistence of objects when run from the script editor, you can't do this! i will look into matching blur's functionality in the future but for now create a command to instance your dialog. you shouldn't need to make a command for every window you want to make. for instance, you might make one command which as arguments to launch a specific dialog which you have created else where.