2
$\begingroup$

I am sketching an environment scene, wherein I want to draw the location for trees as a Grease Pencil object. So that I can create a more appropriate floor plan design. When I am done sketching, I want to replace the Grease Pencil objects with the actual tree meshes. So I was wondering, considering I keep the object origins in-tact by duplicating the Grease Pencil trees, can I replace them with the mesh object? And the other way around, can I also replace a mesh with a Grease Pencil object? enter image description here

The Link/ Transfer data menu pop-up (Ctrl+L) doesn't allow me to link the object data between different object types.

If this is possible with a script that can be placed in the Ctrl+L menu that would also be fine with me.

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ also might be worth looking into geometry node. Whilst you can't make one on GP objects, by converting GP to curve then plugging it into curve to mesh > merge by distance > instance on points you would end up with a similar result $\endgroup$
    – pevinkinel
    May 31 at 20:33
  • 2
    $\begingroup$ @wilks GN is actually a great idea ! While you can't add GN modifiers to grease pencil objects, you can instance GPs inside a GN modifier on a mesh object. Using a switch node to switch between the two at runtime, you wouldn't even have a destructive behaviour. $\endgroup$
    – Gorgious
    Jun 1 at 6:40
  • $\begingroup$ @Gorgious right, sounds like an even better idea, but I don't see how you'd get any useful position data from the GP object without converting it beforehand, like, is there a node that let's you convert GP to curve/mesh? $\endgroup$
    – pevinkinel
    Jun 1 at 15:28
  • $\begingroup$ Interesting idea, though at this point GN doesn't seem to be mature enough to do this effectively, like the script below does. $\endgroup$
    – Hologram
    Jun 1 at 18:11

1 Answer 1

2
$\begingroup$

You can't change an object's data type once it has been created. Here's a suggestion that will create new objects and copy the data in the same location as the selected objects.

enter image description here

import bpy


class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Replace Selected By Active"
    bl_options = {"REGISTER", "UNDO"}
    
    delete_selected: bpy.props.BoolProperty(default=True, name="Delete Selected")

    @classmethod
    def poll(cls, context):
        return len(context.selected_objects) > 1

    def execute(self, context):
        source = context.active_object
        for obj in context.selected_objects:
            if obj == source:
                continue
            new = bpy.data.objects.new(name=source.name, object_data=source.data)
            source.users_collection[0].objects.link(new)
            new.matrix_world = obj.matrix_world
            # If you don't want the new objects to inherit scale & rotation, use this :
            # new.location = obj.location
            if self.delete_selected:
                bpy.data.objects.remove(obj)
            new.select_set(True)
        return {'FINISHED'}

def menu_func(self, context):
    self.layout.operator(SimpleOperator.bl_idname, text=SimpleOperator.bl_label)

def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.types.VIEW3D_MT_make_links.append(menu_func)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.types.VIEW3D_MT_make_links.remove(menu_func)


if __name__ == "__main__":
    register()

$\endgroup$
2
  • $\begingroup$ This is exactly what I was looking for. I managed to make this into an addon myself :) But I feel like you should be the one to distribute it. $\endgroup$
    – Hologram
    Jun 1 at 18:12
  • $\begingroup$ @Hologram Please do ! I don't mind at all, I already have a bunch on my plate ;) Cheers $\endgroup$
    – Gorgious
    Jun 1 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.