Replace referenced objects to instance

Replace referenced objects to instance

gergelyilles
Community Visitor Community Visitor
356 Views
2 Replies
Message 1 of 3

Replace referenced objects to instance

gergelyilles
Community Visitor
Community Visitor

I am not a scripter so I asked chatGpt to help writing a script which change the selected referenced objects and replace them to instenced. But I have got a syntax error.

 

here is the script by chatgpt:

 

for obj in selection do (
if isvalidnode(obj) then (
local source = getreference obj -- Get the referenced object
if source != undefined then (
local instance = instance source -- Create an instance of the source
instance.pos = obj.pos -- Match position
instance.rotation = obj.rotation -- Match rotation
instance.scale = obj.scale -- Match scale
delete obj -- Remove the original object
)
)
)

 

and the error:

 

-- Syntax error: at ), expected <factor>
-- In line: )

 

I think I have eqal opening and closing brackets so I dont have a clue.

Please help me someone!

 

0 Likes
357 Views
2 Replies
Replies (2)
Message 2 of 3

denisT.MaxDoctor
Advisor
Advisor

First, the code from ChatGPT doesn’t do anything useful and isn’t close to what you need.

Second, your task isn’t clear to me. Please explain in more detail what you want to achieve, and I’ll try to help you with the code.

0 Likes
Message 3 of 3

gastonDTKNS
Explorer
Explorer

You can start with something like this.  Select all the references, run this, select the original node and keep all the selected nodes as instances

(
  target = selection as Array
  keepInstances = true
  selec = pickobject()
  if selec != undefined do
  (
    keepInstances = querybox "Keep as Instances?"
    for tg in target do
    (
      instanceReplace $selection selec
      tg.name = uniqueName selec.name
    )
    if keepInstances == false do (InstanceMgr.MakeObjectsUnique target #individual)		
    $Selection.material = selec.material
  )
)
0 Likes