STEAM 组
Blender Source Tools BleST
STEAM 组
Blender Source Tools BleST
362
游戏中
2,175
在线
成立于
2013 年 11 月 8 日
所有讨论 > Help > 主题详情
Shoob 2017 年 3 月 20 日 下午 6:30
Having difficulty scripting with bpy.ops.import_scene.smd()
So I am trying to create an import script to import a large amount of animations. I'm looking for the proper syntax to use import_scene.smd, more specifically since I am trying to create a new armature each time, i.e. setting Bone Append Mode to "Make New Armature". I'm rather new with blender scripting, is there any reference that I can use to make this work? I am not 100% sure on how to use the correct parameters.
最后由 Shoob 编辑于; 2017 年 3 月 20 日 下午 6:52
< >
正在显示第 1 - 11 条,共 11 条留言
Artfunkel 2017 年 3 月 21 日 上午 2:46 
The parameters are keywords. I forget the exact arguments but you will want to do something like bpy.ops.import_scene.smd(mode="NEWARMATURE"). Check the definition of the importer class to get the full list of what's available, or run the importer through the UI then check Blender's command history and see what it executed.
最后由 Artfunkel 编辑于; 2017 年 3 月 21 日 上午 2:47
Shoob 2017 年 3 月 21 日 下午 5:20 
Seems like "Mode" is unrecognized. And I don't see any mode in the only manual it refers to[docs.blender.org], which doesn't even have the listing for smd or bone append modes.
最后由 Shoob 编辑于; 2017 年 3 月 21 日 下午 6:08
Shoob 2017 年 3 月 21 日 下午 5:31 
And how do I view the command history? The console doesn't seem to show commands that I have chosen through the UI. I can't even get the export to run by itself through the API. If I only include the smd path, I just get this error.

>>> bpy.ops.import_scene.smd(filepath='I:\\Libraries\\Documents\\Exported\\Hero\\Pharah\\Skin\\STANDARD_COMMON\\Classic\\anim_mess\\000000000037.smd')
Error: Traceback (most recent call last):
File "C:\Users\me\AppData\Roaming\Blender Foundation\Blender\2.77\scripts\addons\io_scene_valvesource\import_smd.py", line 73, in execute
self.num_files_imported = self.readSMD(filepath, self.properties.upAxis, self.properties.rotMode)
File "C:\Users\me\AppData\Roaming\Blender Foundation\Blender\2.77\scripts\addons\io_scene_valvesource\import_smd.py", line 1267, in readSMD
print("\nSMD IMPORTER: now working on",smd.jobName)
File "C:\Users\me\AppData\Roaming\Blender Foundation\Blender\2.77\scripts\addons\io_scene_valvesource\utils.py", line 90, in print
builtins.print(" ".join([str(a) for a in args]).encode(sys.getdefaultencoding()).decode(sys.stdout.encoding), end= "\n" if newline else "", flush=True)
TypeError: decode() argument 1 must be str, not None

location: C:\Program Files\Blender Foundation\Blender\2.77\scripts\modules\bpy\ops.py:189

From what I can tell, the filename isn't being set when I call it directly from the API. They must have some different input method in import_scene.

最后由 Shoob 编辑于; 2017 年 3 月 21 日 下午 5:56
Shoob 2017 年 3 月 21 日 下午 6:09 
Also, I figured out where the commands are outputted (in the info bar), but it does not provide any direct command usage[puu.sh].
Artfunkel 2017 年 3 月 22 日 上午 2:01 
If you run an import and look at the info bar command history, you will see what you need to do.
Shoob 2017 年 3 月 22 日 上午 6:19 
All I see is this[puu.sh]. Nowhere is the import_scene method called.
最后由 Shoob 编辑于; 2017 年 3 月 22 日 上午 6:19
Artfunkel 2017 年 3 月 22 日 上午 8:20 
Oh, sorry! I'm pretty sure that used to work.

You can find the keywords and their values in the source code.[github.com]
Shoob 2017 年 3 月 22 日 下午 6:57 
Awesome, we're making progress.

The proper command format (with valid args) is:

>> bpy.ops.import_scene.smd(filepath="I:\\foo.smd", append="NEW_ARMATURE")

It isn't saying I have unrecognized parameters anymore, so that's nice.

But when I am calling this method, I get the same exception shown above. From what I could tell, the filepath isn't being passed into import_smd.py. Any idea why that could be the case?
Artfunkel 2017 年 3 月 23 日 上午 1:23 
It possibly needs to use forward slashes instead of backslashes.
This is how I run the importer in unit tests.[github.com]

Try attaching to Blender with Visual Studio and PTVS[github.com]. Then you'll be able to debug any Python running within the process.
Shoob 2017 年 3 月 23 日 下午 5:43 
I got the same error with forward slashes. Hell, your testcases even mix forward and backslashes, so that wouldn't be an issue.

I can see if I am able to debug this in visual studio, but I don't know if I have the time.

I just don't know if it is an actual bug, or if it is just my setup. Can anyone else get this command to run in a script on their end?
最后由 Shoob 编辑于; 2017 年 3 月 23 日 下午 10:08
Artfunkel 2017 年 3 月 24 日 下午 2:04 
I ran the command from the text editor instead of the console and it worked correctly. Looks like a bug with Blender's built-in Python console.
< >
正在显示第 1 - 11 条,共 11 条留言
每页显示数: 1530 50

所有讨论 > Help > 主题详情
发帖日期: 2017 年 3 月 20 日 下午 6:30
回复数: 11