PDA

View Full Version : Python errors: references? // SWIG errors



jeric_synergy
09-22-2015, 10:48 PM
I took a very simple lscript, ran it thru LScript>Python (which I have now been advised to avoid as pointless) and attempted to run it in Layout.

It throws an error, to whit:

TypeError: SWIG director type mismatch in output value of type 'int'

Which is odd (to me) because SWIG seems to be some sort of C/C++ utility. ANYWAY, I guess it might be helpful to have a reference of what errors mean-- I'm not sure why 'output' is even an issue here, unless it refers to a return value from a command.

Here's the code:

# -*- Mode: Python -*-
# -*- coding: ascii -*-

import os, sys, math
import lwsdk

__author__ = "J Eric Chard"
__copyright__ = "Copyright (C) 2015 J Eric Chard"
__maintainer__ = "J. Eric Chard"
__version__ = "1.0"
__email__ = "[email protected]"
__status__ = "Production"
__lwver__ = "11"


class Toggle_All_Chnnls(lwsdk.IGeneric):
def __init__(self, context):
super(Toggle_All_Chnnls, self).__init__()


def process(self, ga):
lwsdk.command("MoveTool")
lwsdk.command("EnableXH")
lwsdk.command("EnableYP")
lwsdk.command("EnableZB")
lwsdk.command("RotateTool")
lwsdk.command("EnableXH")
lwsdk.command("EnableYP")
lwsdk.command("EnableZB")
lwsdk.command("StretchTool")
lwsdk.command("EnableXH")
lwsdk.command("EnableYP")
lwsdk.command("EnableZB")


ServerTagInfo = [
( "Python ToggleAll Chnnls", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "ToggleAll Chnnls", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("LW_PyToggle_All_Chnnls", Toggle_All_Chnnls) : ServerTagInfo }

ernpchan
09-22-2015, 10:54 PM
Try adding this at the end.


return lwsdk.AFUNC_OK

Not sure the technical reason why but it should get rid of that error.

jeric_synergy
09-22-2015, 11:01 PM
Not getting it to work. Hitting the books some more, thanks......

ernpchan
09-23-2015, 01:04 AM
Works for me ok. Not seeing that SWIG error in the console.

129860

RebelHill
09-23-2015, 03:01 AM
it needs to go at the end of the process function, not the end of the file.

jeric_synergy
09-23-2015, 07:07 AM
it needs to go at the end of the process function, not the end of the file.
Huh. I tried it there, and still got errors. I think it was pilot error with something within Notepad++. After some twiddling (undesired+invisible indentation-???) Working now, thanks RH and ernpchan.

Current shortcomings: Doesn't work with Lights or Camera (probably due to StretchTool), leaves MoveTool active no matter what it started with.

Will continue to tinker.

ernpchan
09-23-2015, 08:52 AM
Current shortcomings: Doesn't work with Lights or Camera (probably due to StretchTool), leaves MoveTool active no matter what it started with.



Yes, add an item type check.