Previous Thread  Next Thread

chat icon Nothing happens when I run a .py script

Lilliepad

Posted: Tue Sep 20, 2011 3:57 pm
Joined: 20 Sep 2011
Posts: 3
[img]http://www.facebook.com/photo.php?fbid=10150803187630346&set=a.10150803187510346.725984.735700345&type=1&theater[/img]

I am doing a tutorial that has not specified any blender version, however the book was published mars 2011 and I am using Blender 2.59.
The script is supposed to give me access to more option in 3D view under the N menu when I am in pose mode. I appended the script from an other file and in the text editor I selected it an the pressed run script and nothing happen. I tried installing python 3.2.2 but it did not help. I also add Python path to System Properties, with no luck. When I looked at the Python Console I got the message that is shown in the pic above.

do not know what I am missing.

Here is the script


import bpy
import re

fk_arm_l = ["UpperArm.L", "ForeArm.L", "Hand.L"]
fk_arm_r = ["UpperArm.R", "ForeArm.R", "Hand.R"]
fk_leg_l = ["UpperLeg.L", "LowerLeg.L", "Foot.L", "Toes.R"]
fk_leg_r = ["UpperLeg.R", "LowerLeg.R", "Foot.R", "Toes.L"]

ik_arm_l = ["IK_Hand.L", "Elbow.L"]
ik_arm_r = ["IK_Hand.R", "Elbow.R"]
ik_leg_l = ["IK_Foot.L", "Knee.L", "RollFoot.L", "RollToes.L"]
ik_leg_r = ["IK_Foot.R", "Knee.R", "RollFoot.R", "RollToes.R"]

drv_fing = ["DRV_Fing1.L", "DRV_Fing2.L", "DRV_Fing3.L", "DRV_Fing1.R", "DRV_Fing2.R", "DRV_Fing3.R"]
drv_thumb = ["DRV_Thumb.L", "DRV_Thumb.R"]

eyes = ["Head", "IK_Head", "Neck"]


class RigProperties(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Rig Properties"

@classmethod
def poll(self, context):
try:
ob = context.active_object
return ("Rig" in ob.name)
except AttributeError:
return 0

def draw(self, context):
pose_bones = context.active_object.pose.bones

layout = self.layout
col = layout.column()

if is_selected(context, ik_arm_l + fk_arm_l):
col.prop(pose_bones["IK_Hand.L"], '["IKFK"]', text="IK Arm.L")
if is_selected(context, ik_arm_r + fk_arm_r):
col.prop(pose_bones["IK_Hand.R"], '["IKFK"]', text="IK Arm.R")


col.separator()
col.operator("rst", text="Clear Transform")
col.separator()

if is_selected(context, ["IK_Foot.R"]):
col.prop(pose_bones["LegTwist.R"], 'rotation_euler', index=1, slider = False, text="Leg Twist.R")
col.prop(pose_bones["RollFoot.R"], 'rotation_euler', index=0, slider = False, text="Foot Roll.R")
col.prop(pose_bones["DEF_Toes.R"], 'rotation_euler', index=0, slider = False, text="Toes.R")
col.prop(pose_bones["IK_Foot.R"], '["Pole"]', text="Knee Pos.R")

if is_selected(context, ["IK_Foot.L"]):
col.prop(pose_bones["LegTwist.L"], 'rotation_euler', index=1, slider = False, text="Leg Twist.L")
col.prop(pose_bones["RollFoot.L"], 'rotation_euler', index=0, slider = False, text="Foot Roll.L")
col.prop(pose_bones["DEF_Toes.L"], 'rotation_euler', index=0, slider = False, text="Toes.L")
col.prop(pose_bones["IK_Foot.L"], '["Pole"]', text="Knee Pos.L")

if is_selected(context, ik_arm_l):
col.prop(pose_bones["ArmTwist.L"], 'rotation_euler', index=1, slider = False, text="Arm Twist.L")
col.prop(pose_bones["IK_Hand.L"], '["Pole"]', text="Elbow Pos.L")

if is_selected(context, ik_arm_r):
col.prop(pose_bones["ArmTwist.R"], 'rotation_euler', index=1, slider = False, text="Arm Twist.R")
col.prop(pose_bones["IK_Hand.R"], '["Pole"]', text="Elbow Pos.R")

for name in drv_fing:
if is_selected(context, [name]):
sid = name[-1]
ext = name[8:11]
num = name[8]
col.prop(pose_bones["DRV_Hand."+sid], 'rotation_euler', index=0, slider = False, text="Relax Hand")
col.prop(pose_bones["DRV_Fing"+ext], 'rotation_euler', index=2, slider = False, text="Spread")
col.prop(pose_bones["DRV_Fing"+ext], 'rotation_euler', index=1, slider = False, text="Roll")
col.prop(pose_bones["DRV_Fing"+ext], 'rotation_euler', index=0, slider = False, text="Base")
col.prop(pose_bones["Fing"+num+"_Mid."+sid], 'rotation_euler', index=0, slider = False, text="Mid")
col.prop(pose_bones["Fing"+num+"_Tip."+sid], 'rotation_euler', index=0, slider = False, text="Tip")

for name in drv_thumb:
if is_selected(context, [name]):
sid = name[-1]
col.prop(pose_bones["DRV_Hand."+sid], 'rotation_euler', index=0, slider = False, text="Relax Hand")
col.prop(pose_bones["DRV_Thumb."+sid], 'rotation_euler', index=2, slider = False, text="Spread")
col.prop(pose_bones["DRV_Thumb."+sid], 'rotation_euler', index=1, slider = False, text="Roll")
col.prop(pose_bones["DRV_Thumb."+sid], 'rotation_euler', index=0, slider = False, text="Base")
col.prop(pose_bones["Thumb_Mid."+sid], 'rotation_euler', index=0, slider = False, text="Mid")
col.prop(pose_bones["Thumb_Tip."+sid], 'rotation_euler', index=0, slider = False, text="Tip")

if is_selected(context, ['DRV_Hand.L']):
col.prop(pose_bones["DRV_Hand.L"], 'rotation_euler', index=0, slider = False, text="Relax Hand")

if is_selected(context, ['DRV_Hand.R']):
col.prop(pose_bones["DRV_Hand.R"], 'rotation_euler', index=0, slider = False, text="Relax Hand")



class RigLayers(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Rig Layers"

@classmethod
def poll(self, context):
try:
ob = context.active_object
return ("Rig" in ob.name)
except AttributeError:
return 0

def draw(self, context):
layout = self.layout
col = layout.column()

# Layers
row = col.row()
row.label(text="Main:")
row.prop(context.active_object.data, "layers", index=0, toggle=True, text="Body")
row.prop(context.active_object.data, "layers", index=5, toggle=True, text="Root")

row = col.row()
row.label(text="Arm.L:")
row.prop(context.active_object.data, "layers", index=1, toggle=True, text="FK")
row.prop(context.active_object.data, "layers", index=2, toggle=True, text="IK")

row = col.row()
row.label(text="Arm.R:")
row.prop(context.active_object.data, "layers", index=3, toggle=True, text="FK")
row.prop(context.active_object.data, "layers", index=4, toggle=True, text="IK")


def is_selected(context, names):
try:
for name in names:
if context.active_pose_bone.name == name:
return True
for bone in context.selected_pose_bones:
for name in names:
if bone.name == name:
return True
except AttributeError:
pass
return False

def reset_bone (context, name):
pose_bones = context.active_object.pose.bones

sid = name[-1]

if 'IK_Foot' in name:
pose_bones[name]['Pole'] = 1.0
pose_bones["LegTwist."+sid].rotation_euler[1] = 0.0
pose_bones["DEF_Toes."+sid].rotation_euler[0] = 0.0
pose_bones["RollFoot."+sid].rotation_euler[0] = 0.0

if 'IK_Hand' in name:
pose_bones[name]['Pole'] = 1.0
pose_bones["ArmTwist."+sid].rotation_euler[1] = 0.0

if 'DRV_Fing' in name:
num = name[8]
pose_bones["Fing"+num+"_Mid."+sid].rotation_euler[0] = 0.0
pose_bones["Fing"+num+"_Tip."+sid].rotation_euler[0] = 0.0

if 'DRV_Thumb' in name:
pose_bones["Thumb_Mid."+sid].rotation_euler[0] = 0.0
pose_bones["Thumb_Tip."+sid].rotation_euler[0] = 0.0


class OBJECT_OT_Reset(bpy.types.Operator):
bl_label = "Reset"
bl_idname = "rst"

def invoke(self, context, event):
active_bone = context.active_pose_bone.name
reset_bone(context, active_bone)

for bone in context.selected_pose_bones:
reset_bone(context, bone.name)

bpy.ops.pose.loc_clear()
bpy.ops.pose.rot_clear()
bpy.ops.pose.scale_clear()

return{'FINISHED'}
Reply with quote


stiv

Posted: Tue Sep 20, 2011 6:26 pm
Joined: 05 Aug 2003
Posts: 3645
Quote:
When I looked at the Python Console I got the message that is shown in the pic above.


Maybe you could just tell us the text of the message. The font does not really matter much.
Reply with quote


Lilliepad

Posted: Tue Sep 20, 2011 8:44 pm
Joined: 20 Sep 2011
Posts: 3
ImportError: No module named console_
location: unknown location

how ever I have tried more stuff and it still not work and now it say
>>> import sys
>>> print sys.path
File "<blender_console>", line 1
print sys.path
^
SyntaxError: invalid syntax
Reply with quote


stiv

Posted: Tue Sep 20, 2011 9:03 pm
Joined: 05 Aug 2003
Posts: 3645
Quote:
ImportError: No module named console_


I am not sure where this is coming from exactly, but the name is wrong. You want 'console' without the underscore.

Quote:
print sys.path


For Python 3, which Blender uses now, this should be
print( sys.path)

One of the most noticeable Python 3 changes is that the print command is not a function, print().
Reply with quote


Lilliepad

Posted: Tue Sep 20, 2011 9:28 pm
Joined: 20 Sep 2011
Posts: 3
I feel like I am not getting anywere closer to solving it.

I just know it does not work and have no clue why at all.

when i run it is say: bpy.ops.text.run_script() and that does not do anything.

Maybe I messing stuff up more by trying to fix it with out knowing what I am really doing

Atleast python seem to work and I have the latest version of both python and Blender
Reply with quote


FaerieTree

Posted: Tue Jun 19, 2012 12:41 am
Joined: 18 Jun 2012
Posts: 2
Lilliepad wrote:
I feel like I am not getting anywere closer to solving it.

I just know it does not work and have no clue why at all.

when i run it is say: bpy.ops.text.run_script() and that does not do anything.

Maybe I messing stuff up more by trying to fix it with out knowing what I am really doing

Atleast python seem to work and I have the latest version of both python and Blender



Hey Lilli,

it's the same with me. That's no fun. But at least i figured out how to get rid of these import error messages.

Relative import somehow does not work - sometimes at least, i'm not really sure myself if it's really tipping the scales. (okay, it's not, what virtual other than art should be somehow related to tipping scales of a real animal like a dragon, somehow fantastic imagination to have a gentle dragon jut like in never ending story as a friend. Smile i alway wish animals could talk. :. )
Oh man, i'm drifting off the topic. Beg your merci, Mylady.
Where i was?

Ah. Yes.
I'm convinced it's not your fault.

Rather it's an import issue. So if you replace the
Code:

import ... from ...

by
Code:
import imp
pathToDxfExport = 'path goes here, okay maybe one should rename the variable, do it at your desire'
thefile, pathname, descriptionTriple = imp.find_module()
#import functions
thefile, pathname, description = imp.find_module('functions', [pathToDxfExport + ''])
art = imp.load_module('functions', thefile, pathname, description)


Now the import function is available. I wrote it on my own, but it's quite messy, please don't be angry. If you wish, you may also put the import function "loadModule" directly in every file where there is something to import.

Code:

#from .export_dxf import exportDXF

then for example becomes:
exportDXFpy = art.loadModule('export_dxf', pathToDxfExport)
[/code]

Note that you don't need the "art." prefix if it (the helper - i always have to think of harry potter, i'd better say Dobby Smile - function) is located, i mean declared, in the same file.


The function itself works as follows: (again using imp import-module)
Code:

#############################################
# Some helper functions due to import mess. #
#-------------------------------------------#


#*
#IMPORT FILE
#with m = module
def importFile(fullPathToModule):
#    try:
        import os
        moduleDir, moduleFile = os.path.split(fullPathToModule)
        moduleName, moduleExt = os.path.splitext(moduleFile)
       
        savedCwd = os.getcwd() #we want to return to it later
        os.chdir(moduleDir)
       
        moduleObj = __import__(moduleName)
        moduleObj.__file__ = fullPathToModule
        globals() [moduleName] = moduleObj #so that it can be reached
       
        os.chdir(savedCwd)    #return to initial path
#    except:
#        raise ImportError("something went wrong")# + self.__LINE__)
       
       
       
#*
#IMPORT MODULE
#@pathToModule -- either relative or absolute (full) path
def importModule(pathToModule, ext = '*.py'):
    import os
    import glob
    import imp
    path = os.path.join(pathToModule, ext)
    #iterate all files
    for infile in glob.glob(path):
        basename = os.path.basename(infile)
        basenameWithoutExtension = basename[0:-3]
       
        imp.load_source(basenameWithoutExtension, infile)
       
   
#*
#LOAD MODULE
#TODO NOT WORKING YET
#def loadModule(submodule, pathTo):
#    import imp

    #preparation   
#    parts = pathTo.split('/')
#    moduleDir  = parts[len(parts) - 2]
#    moduleFile = parts[len(parts) - 1]
#   
#    filenameParts = moduleFile.split('.')
#    fileName = filenameParts[0]
#   
    #moduleExt  = filenameParts[len(filenameParts) - 1]
    #first load parent module
#    pathToDir = '/'.join(parts[0:len(parts) - 3])
#    thefile, pathname, description = imp.find_module(
#        moduleDir, [pathToDir + '']
#    )
#    moduleDirObj = imp.load_module(moduleDir, thefile, pathname, description)
#    globals() [moduleDir] = moduleDirObj

    #now load the module to be loaded
#    thefile, pathname, description = imp.find_module(
#        fileName, [moduleDir]
#    )
    #moduleObj = imp.load_source(module, thefile, pathname, description)
#    moduleObj = imp.load_module(submodule, thefile, pathname, description)
#    globals() [submodule] = moduleObj #so that it can be reached
   
   

#TODO NOT WORKING YET (perhaps the above approach is better)
def loadClass(className, pathToWithFile):
    import imp
    #two modi:
    # (1) path includes file => load
    # (2) file is first argument, path includes no file
    parts = pathToWithFile.split('.')
    partsL = len(parts)
    ext = parts[partsL - 1]
   
    parts = parts[0].split('/')
    partsL = len(parts) #refresh!
    pathToFile = '/'.join(parts[0:partsL - 2])
    fileDir = parts[partsL - 2]
    fileName = parts[partsL - 1]
   
    #par = loadModule(fileName, pathToFile)
    thefile, pathname, description = imp.find_module(
        className, [pathToFile + '/' + fileDir + '.' + ext]
    )
    return imp.load_module(className, thefile, pathname, description)
   
   


#LOAD MODULE
def loadModule(fileName, pathTo, globalIndex = ''):
    import imp

    thefile, pathname, description = imp.find_module(
        fileName, [pathTo]
    )
    #moduleObj = imp.load_source(module, thefile, pathname, description)
    moduleObj = imp.load_module(globalIndex, thefile, pathname, description)
   
    if (globalIndex != ''):
        globals() [globalIndex] = moduleObj #so that it can be reached
       
    return moduleObj
   
   


Oh yes, and please don't forget, that only the first two and the last one kind a do what they are expected to - but they are far from being as nice as fairytales.

Hope i didn't confuse you,
yours,
Jan
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group