We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Is there a way to name children of clones

Home Forums Programming Is there a way to name children of clones

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #78605
    kvdml
    Customer

    Hi,
    verge 4.71
    I appended a scene, panel.glb, which consists of an empty, ‘panel’, and two child geometries: ‘panel_frame’ and ‘panel_glass’.
    Like this:
    * panel
    ->panel_frame
    ->panel_glass

    When I make clones of panel, the two children are cloned as well. But only panel receives a new name:
    [“panel”, “panel_frame”, “panel_glass”]
    [“panel2”, “panel_frame”, “panel_glass”]
    [“panel3”, “panel_frame”, “panel_glass”]

    My question:
    A. is there a way to rename panel_frame to ‘panel frame_2″ & “panel frame_3”, because I can not target these objects with setObjTransform or setMorphFactor like this

    B. If I can’t rename the objects, is there a way I can target these? Like panel2.panel_frame?

    C. Or is it better to make separate clones of panel_frame and panel_glass and parent to a new parent?

    thx

    #78606
    Brameister
    Participant

    Maybe you could use a short function in an exec script puzzle to rename the children, something like this:

    Attachments:
    You must be logged in to view attached files.
    #78616
    kvdml
    Customer

    thx,
    had to rework it a bit, but I got it working like this:

    function renameChildrenOfClone(clonedObjectName) {
    // Retrieve the cloned object from the scene using its name
    const clonedObject = app.scene.getObjectByName(clonedObjectName);

    // Extract the index number from the parent object’s name
    const indexMatch = clonedObjectName.match(/\d+$/);
    const index = indexMatch ? indexMatch[0] : ”;

    for (let i = 0; i < clonedObject.children.length; i++) {
    const child = clonedObject.children;

    if (child.name.startsWith(‘panel_frame’)) {
    child.name = panel_frame${index};
    } else if (child.name.startsWith(‘panel_glass’)) {
    child.name = panel_glass${index};
    }
    }
    }

    • This reply was modified 1 week, 6 days ago by kvdml.
    #78617
    kvdml
    Customer

    this is my clone object before and after the rename function

    [‘panel2’, ‘panel_frame’, ‘panel_glass’]
    [‘panel2’, ‘panel_frame2’, ‘panel_glass2’]

    [‘panel3’, ‘panel_frame’, ‘panel_glass’]
    [‘panel3’, ‘panel_frame3’, ‘panel_glass3’]

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.