Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python script? #34

Closed
eskeyaar opened this issue Dec 29, 2020 · 11 comments
Closed

python script? #34

eskeyaar opened this issue Dec 29, 2020 · 11 comments
Labels
Blender Integration About integrating correctly with Blender. Enhancement New functionality or improvement to existing functionality.
Milestone

Comments

@eskeyaar
Copy link

Hi,
Thanks for this add on.
What will be its python script to call? will it be like normal method to import and export as stl? like below?
import bpy
import os
bpy.ops.import_scene.3mf(filepath='xx/xxx/1.3mf')
bpy.ops.export_mesh.stl(filepath='1.stl')

Cheers,

@Ghostkeeper
Copy link
Owner

I'm not really familiar with conventions within Blender in that regard.

From my point of view, the main entry point of importing 3MF is this function:

def execute(self, context):

That function reads these three attributes of the class:

files: bpy.props.CollectionProperty(name="File Path", type=bpy.types.OperatorFileListElement)
directory: bpy.props.StringProperty(subtype='DIR_PATH')
global_scale: bpy.props.FloatProperty(name="Scale", default=1.0, soft_min=0.001, soft_max=1000.0, min=1e-6, max=1e6)

This was taken from the examples of the STL import and PLY import scripts. Perhaps those import scripts have some helper functions that make it easier to use them from a script that I have overlooked. If so, such helper functions should be added to this Import/Export add-on as well.

@Ghostkeeper Ghostkeeper added this to the v1.1 milestone Dec 30, 2020
@Ghostkeeper Ghostkeeper added Blender Integration About integrating correctly with Blender. Enhancement New functionality or improvement to existing functionality. labels Dec 30, 2020
@eskeyaar
Copy link
Author

Thanks, am not well versed with python, but I will try and see.

Cheers

@eskeyaar
Copy link
Author

@Ghostkeeper
i tried to do run similar to which stl gets import? like using import_scene.3mf, am getting
SyntaxError: invalid syntax

location: :-1

Thanks!

@Ghostkeeper
Copy link
Owner

I've never implemented any method to make it work from the Python command line in Blender. I hadn't considered that until you mentioned it. So most likely it's not going to work (yet).

However the SyntaxError you're getting signifies that you made a mistake in the command you typed in. Possibly a typo, unmatched brackets, etc.

@Ghostkeeper
Copy link
Owner

Ghostkeeper commented Feb 7, 2021

So it turns out that by registering the operator, it was already accessible from the Python scripting environment in Blender automatically. You could discover this by running:

>>> dir(bpy.ops.import_mesh)
['3mf', 'ply', 'stl']

However if you try to call it that way (bpy.ops.import_mesh.3mf(filepath="/path/to/file.3mf")), Python gives a syntax error. This is because names in Python may not start with a number.

So I've changed the operator's ID to be import_mesh.threemf. This avoids the problem. The import operator is now in bpy.ops.import_mesh.threemf and the export operator in bpy.ops.export_mesh.threemf.

I've documented how to call these operators from a scripting environment here: https://github.com/Ghostkeeper/Blender3mfFormat#scripting

@eskeyaar
Copy link
Author

eskeyaar commented Feb 8, 2021

Awesome, Thanks Works!

@Deuracell
Copy link
Contributor

Hi,

There still seems to be an error with the python integration.
Regardles of which version of Blender, I get the following error:

bpy.ops.import_mesh.threemf(filepath="F:\Nextcloud\Deventus\3mf-test\microvred.3mf")
Traceback (most recent call last):
File "<blender_console>", line 1, in
File "C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\modules\bpy\ops.py", line 201, in call
ret = op_call(self.idname_py(), None, kw)
AttributeError: Calling operator "bpy.ops.import_mesh.threemf" error, could not be found

@Ghostkeeper
Copy link
Owner

That there is Blender calling an operator that doesn't exist. This add-on registers itself and then waits to be called. Apparently Blender kind of semi-registered it with you, where it knows that it exists but then doesn't find the operator any more, and never calls the code in this add-on. So the add-on itself could never do anything about this error.

This could be the result of something like a syntax error upon registering, but then the rest of us would have the same issue (unless you edited these files yourself). More likely it is somehow not installed correctly.

@Deuracell
Copy link
Contributor

Deuracell commented Apr 20, 2022

Hi,

Late reply and all but here we are.
I have tried redownloading and installing again on different versions of Blender and on three different computers, but the result is the same.
I've made no changes to the source.
The following pops up when i type so it's defenetly loaded, i guess "threemf" is suposed to be there as well, rigth? Or should it replace "3mf"?

>>> dir(bpy.ops.import_mesh)
['3mf', 'ply', 'stl']

Regards
Simon

@Deuracell
Copy link
Contributor

Deuracell commented Apr 20, 2022

Never mind, I now changed the bl_idname to "import_mesh.threemf" and with that it works!
I assumed this whas already in the 1.0.1 release but apparently not.

@SourceCodeZone
Copy link

If anyone having the issue again, it's because the commit f4319b3 seem not updated in release package here https://github.com/Ghostkeeper/Blender3mfFormat/releases/tag/v1.0.1 Manually replacing the file in plugin directory from here https://github.com/Ghostkeeper/Blender3mfFormat/tree/master/io_mesh_3mf will fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blender Integration About integrating correctly with Blender. Enhancement New functionality or improvement to existing functionality.
Projects
None yet
Development

No branches or pull requests

4 participants