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:

How do I get all assets in a given UserAssetLibrary with the Python API?

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.

Thank you.

Asset browser object and scene setup

  • $\begingroup$ Thanks Martynas, I'll add some screenshots and see if I can get the code structure together. $\endgroup$ Mar 17, 2023 at 7:57
  • $\begingroup$ I'm thinking list comprehension may be the way to go with this? I'll end up with two lists: [square, square, sphere, etc] and the items in the asset browser [square, cube]. Will this allow me to compare the two lists and replace items in the first list with the second? $\endgroup$ Mar 18, 2023 at 8:09

1 Answer 1


You can use a forloop to go through all the objects:

import bpy #import Blender's Python API

D = bpy.data
some_list = ... #you need to decide how you load new objects

for o in D.objects: #loops through all objects in the file
    name = o.name # that's all you have to do to get the name
    if name in some_list:
        ...             # data is the mesh, if you replace it, 
        o.data = ...    #the object remains the same keeping transforms
  • $\begingroup$ If you would like to get a less vague answer, you could provide more information, screenshots, some examples and decide how you want to load the new objects exactly.. $\endgroup$ Mar 17, 2023 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .