Good morning, long time reader, first time poster!
I receive many DXF drawings with 2D objects. I'd like to create a script which looks up the name of the 2D object and replaces it with a 3D counterpart, of the same name.
Ideally this would be from a 3D object from the asset browser, if possible? if not, could this be done with files from disk or objects within an existing Blend file on disk? Last resort would be to load all the required 3D elements into the scene.
Many of the 2D 'base' objects are instances, there could be 750 objects but just 50 unique meshes in a given file.
This can be achieved manually, to some extent, by using the remap users option in outliner but it would be great to script the entire process.
In terms of code structure I thought the following is a good starting point:
- Loop through all 2D meshes
- output list of unique items, including location and rotation
- 'look-up' matching 3D version
- replace 2D with 3D (based on location of original 2D element)
Update: Although for materials I think this approach, suggested by Gorgious, would allow object access from the asset browser:
with this code, as suggested by Martynas, added to compare scene objects and asset objects
import bpy #Find and replace scene elements scene_ob = bpy.data #objects in scene asset_ob = bpy.data #objects with matching name in asset browser for o in scene_ob.objects: #loops through all objects in the file name = o.data # get mesh name in scene if name == asset_ob: #compare scene ob name against aseet browser object name o.data = asset_ob #replace scene object with asset object
The bit I'm stuck on is loading the asset browser objects into a list and then comparing the scene list against the asset browser list.