Iterating over objects to create discrete blocks

OK, so this might be a little convoluted, but maybe there is more that one way to solve my problem.

I am creating geometry in rhino, and am going to export it to sketch-up. My biggest issue is that, when the object is exported into sketch-up, all the discrete objects get all melded together in that very sketch-upy way. I have found that, objects stored inside their own blocks become individual components in sketch-up, which is exactly what I’d like to have in that case.

So I thought I’d be clever and write a rhinoscript that takes selected objects, and iterates through them, creating a new block for each list item. Unfortunately…

My script:

import rhinoscriptsyntax as rs

theObjs = rs.SelectedObjects()
for obj in theObjs:
    rs.AddBlock(obj,(0,0,0))

and I get the error:

Message: iteration over non-sequence of type Guid

Traceback:
line 29, in AddBlock, "C:\Users\User\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\block.py"

line 5, in <module>, "C:\Users\User\AppData\Local\Temp\TempScript.py"

I presume something akin to the GUID reference is somehow lost when iterating through the list, but I can’t figure out how to work it out.

Any ideas?

Thanks!!

try this:
?

import rhinoscriptsyntax as rs

theObjs = rs.SelectedObjects()


for i in range(len(theObjs)):
    obj = [theObjs[i]]
    block = rs.AddBlock(obj, (0,0,0), None, True)
    rs.InsertBlock(block, (0,0,0))

[edited 7:20p]

I was just attempting that solution. This is because rs.AddBlock only takes lists or tuples, correct? Anyway, it worked!

Thanks!

right… it needs a list of guid(s) instead of a raw guid…

i also made the AddBlock part delete the input then insert the block (otherwise, it just makes a block instance but the export will still be the non-blocked geometry)…

anyway, i’d use this on a duplicate .3dm instead of the real one… there’s probably a slicker/safer way to do it :wink:

but i know what you’re saying about the .skp export… seems like it’d be better if the polysurfaces etc were imported as groups/components in sketchup instead of one single group with everything merged together.