duckbad.blogg.se

Blender python 3
Blender python 3






However, I want to add an addi­tion­al fea­ture to the class. I’m using the ExportHelper class to export 3D objects. There’s also an ExportHelper class that includes some util­i­ties to check for exist­ing files and set­ting a default unti­tled file­name in the browser.ĭid I miss some­thing? Let me know in the comments! Print('Some Boolean:', self.some_boolean)īpy.utils.register_class(OT_TestOpenFilebrowser)īpy.utils.unregister_class(OT_TestOpenFilebrowser)īpy._filebrowser('INVOKE_DEFAULT') You can take care of that with good old spli­text().įilename, extension = os.path.splitext(self.filepath)Īnd what about adding set­tings to the file­brows­er screen? All you have to do is add prop­er­ties to the oper­a­tor as usu­al and they will show up in the browser.ĭescription='Do a thing with the file you\'ve selected',įrom bpy.props import StringProperty, BoolPropertyĬlass OT_TestOpenFilebrowser(Operator, ImportHelper): You might want to reject a file or do some­thing dif­fer­ent depend­ing on the exten­sion you receive. Note that strings longer that 255 could be cut (since that’s the inter­nal buffer size).ĭefault='*.jpg *.jpeg *.png *.tif *.tiff *.bmp',Īlso keep in mind that users can dis­able fil­ter­ing in the UI and select any kind of file. Each exten­sion is writ­ten in wild­card style and is sep­a­rat­ed by a semi-colon. This is a StringProperty with the list of exten­sions we want to show. To fil­ter the types of files shown to the user we have to add a filter_glob prop­er­ty to our class. Note that this is a reg­u­lar StringProperty inside ImportHelper that we inher­it­ed when we sub­classed it. Our new oper­a­tor already has an invoke() func­tion that calls the file­brows­er and when a user selects a file, it stores the file’s path in self.filepath. """Do something with the selected file(s)."""

blender python 3

Now we can go ahead and cre­ate the operator: class OT_TestOpenFilebrowser(Operator, ImportHelper): Let’s start by import­ing both ImportHelper and Operator.įrom bpy_extras.io_utils import ImportHelper To use it all we have to do is extend it in our oper­a­tor.

blender python 3

It includes an invoke() func­tion that calls the file­brows­er and a few helper func­tions used in Blender’s importer addons. Importhelper is a mix-in class found in the bpy_extras sub­mod­ule.

blender python 3

Luckily Blender pro­vides a handy class that does almost every­thing for us. Sure, you could just give users a sim­ple string input and let them copy/paste into it but how much cool­er would it be to let them pick a file from the filebrowser?

blender python 3

Every now and then an addon requires that the user selects a spe­cif­ic file or path.








Blender python 3