Notifications
Clear all

[Closed] objectsets and single objects

Hello!

A really simple question:

normally I write things like

fn Bla objs =
(
for o in objs do () etc.
)

and then Bla ($ as array)

the problem is that it doesnt work with single object selections. I mean i could check for the class of the object but its not so neat… is there a way of turning a single object into an objectset? Or how do you clever people handle this?

Thanks in advance!

seb

4 Replies

in the case of selected objects you can use “selection” as it returns the current selection as an array. so “bla selection” will always work

hOpe this helps,
o

This should do the trick:

fn Bla objs = 
(
  -- turn <objs> into an array if needed
  if classof objs != array and
     classof objs != objectset then
  (
    objs = #(objs)
  )

  -- just an example, this fn returns the object's names
  for o in objs collect o.name
)

-- examples
Bla $Box01
Bla #($Box01, $Box02)
Bla lights

Or, you could also write a function for it that can be used throughout your script:

fn makeObjArray objs = 
(
  if classof objs != array and classof objs != objectset then #(objs) else objs
)

fn Bla objs = 
(
  for o in (makeObjArray objs) collect o.name
)

Cheers,
Martijn

eeexcellent! you guys just rock! thanks!!

or in some cases you use a mapped function,


mapped fn randomcolor obj=
(
-- copyright 2002 Joshua Newman [www.joshuanewman.net]( http://www.joshuanewman.net/) 
r=(random 0 255)
b=(random 0 255)
g=255-((r+b)/2)
obj.wirecolor=(color r g b)
)