Coder Social home page Coder Social logo

python script? about blender3mfformat HOT 11 CLOSED

ghostkeeper avatar ghostkeeper commented on June 26, 2024
python script?

from blender3mfformat.

Comments (11)

Ghostkeeper avatar Ghostkeeper commented on June 26, 2024 1

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

from blender3mfformat.

Ghostkeeper avatar Ghostkeeper commented on June 26, 2024

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.

from blender3mfformat.

eskeyaar avatar eskeyaar commented on June 26, 2024

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

Cheers

from blender3mfformat.

eskeyaar avatar eskeyaar commented on June 26, 2024

@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!

from blender3mfformat.

Ghostkeeper avatar Ghostkeeper commented on June 26, 2024

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.

from blender3mfformat.

eskeyaar avatar eskeyaar commented on June 26, 2024

Awesome, Thanks Works!

from blender3mfformat.

Deuracell avatar Deuracell commented on June 26, 2024

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

from blender3mfformat.

Ghostkeeper avatar Ghostkeeper commented on June 26, 2024

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.

from blender3mfformat.

Deuracell avatar Deuracell commented on June 26, 2024

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

from blender3mfformat.

Deuracell avatar Deuracell commented on June 26, 2024

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.

from blender3mfformat.

SourceCodeZone avatar SourceCodeZone commented on June 26, 2024

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.

from blender3mfformat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.