ScriptSpot

Forum topic · General Scripting

Unable to convert: $selection to type: <node> ----- Why?

By kernberg · 2016-01-25

Description

Hi all you good people!

I'm writing on a small script which is putting all objects in a scene into a container.
The script looks like this:

global assetproxyPUB
select objects
assetUnproxyPUB = $

cnt01 = container size:50 name:h1
cnt01.displaylabel = true
cnt01.localDefinitionFilename = h1 + "_container"
cnt01.AddNodeToContent assetproxyPUB
cnt01.SetAccessType #anythingUnlocked
cnt01.ClearLockedContents()
cnt01.SetLockedContents #lockAllAnimation true
cnt01.saveContainer true
cnt01.setOpen false

Sometimes it works, sometimes it doesn't.
Sometimes maxscript replys: "Unable to convert: $selection to type: "
and highlights this line:

cnt01.AddNodeToContent assetproxyPUB

Does anybody have an idea what could be the reason for this and how to deal with it?

Thank you so much! :)

Comments (4)

kernberg · 2016-02-01

ahhhh, where was my head.. Thank you so much! I owe you a beer... Problem solved

kernberg · 2016-02-01

Hi, I tried to use the selection as array but then I get this error message (in the file attachement).
Any idea, what's going on?

Thank you so much :)

Attachments

Swordslayer · 2016-02-01

Well, it was meant to replace the whole line, not just part of it - note that it's AddNodesToContent, not AddNodeToContent.

Swordslayer · 2016-01-27

It expects one node; when it errors out, you're feeding it multiple nodes. There's no reason to make the variable global, btw. (actually it's a bad practice), and as it's used only once you don't even need the variable. Delete the first three lines and replace the highlighted line with

cnt01.AddNodesToContent (selection as array)