Activity
Mon
Wed
Fri
Sun
Oct
Nov
Dec
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
What is this?
Less
More

Memberships

CG Python Academy (Free)

907 members • Free

33 contributions to CG Python Academy (Free)
Heed help with Export FBX operator
I'm trying to build an operator that moves selected objects to world origin (ignoring Z axis), runs 'Export FBX' operator and after execution (either finished or cancelled) the objects should move back to their original locations. The problem that 'Export FBX' is a modal operator and if I write 'move objects back' code after bpy.ops.export_scene.fbx('INVOKE_DEFAULT') , it executes right after the operator was called even if user haven't exported objects yet. So pretty much the objects should stay at world center until user clicks 'Export FBX' or 'Cancel' button because objects need to have their pivot points at the center when I import them to other programs such as Unreal. I can't wrap my head around how to do it. I was thinking of something like "if bpy.ops.export_scene.fbx('INVOKE_DEFAULT') returns {"FINISHED"} or {"CANCELLED"} -> do the thing", but it returns {"RUNNING_MODAL"} on call. Hope it makes sense :D Help please! I'll try to attach the code in comments as it says 'failed to upload an image' when I try to attach .py file here.
1 like • 2d
I haven't looked into your code, but if "Export FBX" is your own operator you could set a global flag variable in the modal operator indicating that it started. In the calling procedure you could write a loop to wait that the modal operator resets the flag when it ends and then move the object back. It's just an idea, don't know if that works for you or if I understood the problem right.
Help debugging my addon
Hey its been a while, but I have been spending that time modifying my add-on a lot. I would like for you guys to download the add-on and see if there are any bugs or any other funny stuff going on. V-------------------------------------------------------------------------------------------------------------------------------------------------------------- What is the addon? The addon is an attribute editor menu, making it so that you can edit attribute values all in one place without going to Mesh > SetAttribute every time you want to edit a single attribute value. Saves time and reduces clicks. How to download it: Download the attached ZIP file, once you have done so go into blender Preferences > Get Extensions and in the top right hand corner there should be a down arrow. Click it then click on "Install from Disk" and select the addon zip and restart Blender. How to use it: - Once installed open the side bar or press N and you should see a tab called "AttributeMenu". - In "Attribute Props Panel" click on "add new attribute". - There you can select from a list of attributes. If you don't have any attributes, go to the properties panel and go to Data > Attribute and create a new attribute. - When you select an attribute from the list of attributes, you'll be able to see and edit it in the "Attribute Props Panel" Make sure that the attribute data type is either an int or bool or float data type, otherwise it wont work (I am planning to add support for different data types in the future). If you don't see the attribute in the property panel then its is likely in a different domain. So if you add an attribute, which domain is in face, but you are in vertex mode, just make sure to go to face select mode, and you should see the attribute in the panel. ----------------------------------------------------------------------------------------------------------------------------------------------------------------- Like I said I would like help debugging and finding errors and bugs n stuff, also new ideas on how to improve the addon would be greatly appreciated as well!
0 likes • Aug 12
As I wrote in the code example above: You can either use a poll parameter which returns itself a true/false state, you can create a function for that in the class of the property and call it with lambda or you can define an independent function outside of the property class and specify it's name only in the "poll"-parameter. This only want to have a bool decision back. If poll=True then it is enabled, otherwise not. So you need to compare the selection mode with the attribute you want to display and with the variable which checks if it is visible or not currently - same logic.
1 like • Aug 12
Seems that the poll function does only work for PointerProperties - sorry. https://docs.blender.org/api/current/bpy.props.html#bpy.props.FloatProperty (search for "poll" here) I only used it here so I only expected that the other props have this, too... :) You could do that using the "enabled" property of layout/row in the "draw" method, like so: def draw(self, context): layout = self.layout # define condition is_enabled = context.object is not None # example # Draw Property row = layout.row() row.enabled = is_enabled row.prop(context.scene, "my_float_property") I have asked Claude to generate a quick example and it returned this one (see attachment): Copy that into the script window in Blender and start it. It will create three selection mode icons in a new panel named "misc". Depending on which you select it shows all you have selected. It is independent of the selection mode of the 3D editor. So if you are in face mode and select one face of a cube, and in the panel in vertex mode it also shows that 4 vertices are selected. Not bad, Claude! Maybe of help for you? You could use that as template to only show the attributes of the object belonging to the same domain.
VS Code can't find bpy_extras
I've been using Blender's built-in text editor to write my addon, and I finally decided to use VS Code. The addon works fine in Blender, but it won't run from VS Code. I'm not sure if it's VS Code or one of the extensions, but it's tripping on this line: from bpy_extras.io_utils import ImportHelper Exception has occurred: ImportError - cannot import name 'ImportHelper' from 'bpy_extras.io_utils' (unknown location) File "/home/gtada/Documents/blender/scripting/iges_import/operator_file_import_iges_002.py", line 75, in <module> from bpy_extras.io_utils import ImportHelper ImportError: cannot import name 'ImportHelper' from 'bpy_extras.io_utils' (unknown location) If anybody has an idea I'd love to hear it. I used the Operator File Import template which includes this module and function.
3 likes • Aug 10
You should check if the module is installed (should be the case by default - but who knows). On my computer it's in: C:\Program Files\Blender Foundation\Blender 4.4\4.4\scripts\modules\bpy_extras And, like with bpy you should of course add "# type: ignore" behind the import. More than that is only the usual things: Don't use the "if...main" line, don't use any code other than register/unregister (only a direct call to "register()" if you want to start your addon without installing it which needs the toml file and the __init__.py"). And: You need to start VSCode with the folder where your file is in, not the file itself. Although VSCode would open it, the Blender VSCode addon is not able to use it in this case.
1 like • Aug 11
"# type: ignore" is a type comment which pylance is using to ignore a type problem in VSCode. If you use "import bpy" for example, VSCode has no idea what this is as VSCode works with your system's Python by default and Blender is using it's own. Your code runs always with the Python Blender uses, this the Blender addon in VSCode makes sure. You can of course change the Python interpreter if you click on the Python version in the lower right corner of VSCode and then give it the link to the Python which is in Blender. If you don't do that because you want to work with the system's Python usually, the "# type: ignore" tells pylance that you are sure everything is OK and it should ignore problems with the code line (doesn't matter which one). On that way, "import bpy" is not shown as an error. You would also need it for example in Blender property definitions as these are also something which only Blender understands but not Python.
3 likes • Aug 8
Possible answer can be found here: https://blenderartists.org/t/difference-between-context-object-and-context-active-object/551563/7
Vertex attribute editor
So for like the past month and a half I've been trying to create a menu that can edit all your custom attributes. And with the help of @Victor Stepanov, @Christian Coppes and a little bit of chat gpt, this is what I was able to do it. I wanted to not only showcase what I've done, but ask for a code reveiw because I feel like there is a bit more that could be optimised and I just wanted to see if there is anything worth improving. Like for instance I think in lines 119-122 and 223-226 I think that if you have a ton of attributes you want to create a property for, you could run into an issue where that section of the code takes up 15 lines instead of like the, so far, managable 4 lines. Attached is the script as well as a short gif demonstrating what it does. Tysm
Vertex attribute editor
0 likes • Jul 20
Ah, thanks, now I found it. If you open the spreadsheet window then you can see the additional attributes per vertex and how they change. Only thing which doesn't work: If you select more than one vertex not using Shift-Click but by drawing a rectangle then none of the vertices is an active vertex. In that case, changing attribute values in the menu doesn't change values in the spreadsheet. I personally tend to go away from Python whereever Blender has own possibilities to create the same especially using Nodes. They are written in C++ and are extremely faster than Python and already tested a lot more. In the screenshot you can see a tool created with Geometry Nodes in about half an hour which does nearly the same as yours: The Blend file also contains your script so you can easily compare it. To create something like that you need to switch the Geometry Nodes editor from "Modifier" to "Tool" in the upper right corner in the dropdown. Only in this mode you have the "Selection" Node which is not available in the Modifier Mode. To get the tool saved, right click on the name (here "AttributeTool" and select "Mark s asset". That creates the blue "bookshelf" icon at the right of the name and an "F" is added to the name in the dropdown which means "Fake User" so it's not lost when you save the file. As this is now no modifier but a tool and an asset you get a new menu in the "Edit" mode as you can see in the second screenshot. If you select some vertices of the object and call it you get a tool menu at the bottom left side as you can see in the third screenshot. Here you can select the names of the attributes, you can change the float values independent or together with holding the mouse button and drag down for all three at once, you can set which of these values should change using the "change" bools, you can also change a bool value. In the spreadsheet you can view how it works. As it is a tool it doesn't "remember" which names you used last time so it will always display the default names. But you can change it to an existing column (attribute) name to reuse that.
0 likes • Jul 20
@Orange Flip The "Tool" thing is since Blender 4.0, but mostly people do not know that. You can setup your own tools and (depending on the kind of tool) you can also create own modifiers which are then reusable. You can also import such tools into other blender files.
1-10 of 33
Christian Coppes
5
337points to level up
@christian-coppes-1848
Database developer and Blender/Python beginner

Active 7h ago
Joined Dec 1, 2024
Powered by