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
Can't rename/delete My Storey when running Python script from CLI #4140
Comments
I think it's the same problem as with my suggestion to rename storey with snippet below - it works when called from console but doesn't work when called from python script. obj = bpy.data.objects["IfcBuildingStorey/My Storey"]
obj.name = "test"
obj.name # 'IfcBuildingStorey/test' So the issue in your case is that IFC name is not updated when IfcOpenShell/src/blenderbim/blenderbim/bim/handler.py Lines 40 to 43 in 36387f3
To detect blender objects name change we subscribe to it using blender msgbus: Therefore, if you rename object and export in one python script then object's IFC name updated only after file is exported. You can test it by adding So the possible solutions are:
from blenderbim.bim.handler import name_callback
storey = bpy.data.objects[old_collection_name]
storey.name = storey_name
name_callback(storey, "name") We could have also call all callbacks on |
I'd say this is just a fact of life of how Blender and Python work, not really a bug or anything we can fix. There are limitations such that if you call it headlessly, you need to be aware of these shortcomings. For this reason it's best to:
The less you depend on the UI, the more stable things will become. If you're trying to get a bunch of autogenerated shapes/meshes, this is completely possible without bpy.ops and I'd recommend not using bpy.ops at all. |
Thank you for the feedback @Andrej730 and @Moult, both your answers are incredibly helpful 💯 |
Cross-posting from this OSArch forum thread.
I am trying to rename (or delete) the default storey that is created when initializing an IFC project in Blender, and I wish to do this through running a Python script. However, whether this succeeds or not seems to depend on if the script is run from within the Blender UI or if the script is provided when running Blender from the command line.
I have an example file which should reproduce the problem. If the following snippet is run from the Scripting tab in Blender, the storey seems to be renamed properly. What I try to do is to do the renaming, set the storey as the (current) parent colelction, assign ifc classes to some objects, and link the ifc components to the storey:
This seems to work fine, but if I add the following lines to the Python file (saving the code as
debug_renaming.py
)and run from the command line
the cube will be linked to
IfcBuildingStorey/My Storey
instead ofIfcBuildingStorey/Floor 1
I don't have any clue what is going on here, so help is much appreciated. If the renaming itself is done incorrectly I would love to hear the better way.
Using Blender 4.0.0, BlenderBIM 0.0.23110
The text was updated successfully, but these errors were encountered: