Script logic for setting up for UE4

I’m looking to set up a script to help more quickly iterate on getting the model into Unreal.

Main issue right now is material reassignment at the other end.

I’m thinking of a script that reorganizes the model hierarchy into layers based on material assignment instead so that selection in unreal is fast and easy and I just have to assign like 5 or 6 groups instead of going through the entire object-based hierarchy.

So… The flow might look something like this?:

save file
save as new file //prevent accidental destruction of working model
delete all curves
delete all objects flagged not to render in maxwell… // not sure if this is possible. may have to create a specific material name and filter for it here.

for each layer

if layer is set to visible
get current layer material name assignment

if destination layer doesn’t exist (material name)
create new destination layer (material name)
assign correct material to new layer

move current layer objects to destination (material name) layer
) // close the visibility if
delete layer (current layer)
next layer

Any holes in this logic? Or a simpler way to do it?

I have run into a problem… V6 seems to explode blocks differently than V5.

When I explode my test block in V5, I get what you would expect: new layers with the materials from the blocks layers assigned:

However, exploding the same block in V6 I get this:

Clicking on the material icon brings up the dialog with the correct material name… But something isn’t populating the material index correctly to allow me to pick up the MaterialName from the index (and then subsequently make a new layer with the MaterialName.

It doesn’t seem to make a difference if the block file is saved in V5 or V6. I’ll attach the block test file. I’m linking it with reference material mode.

test block.3dm (67.5 KB)

Hi - Thanks for reporting, I see that here as well.
I filed this as RH-57046.

Thanks Wim.

I have my script basically working (in V5)

One little hiccup… Is there an elegant way to test if any of an object’s parent layers are not visible?

I generally have something like a “tools” layer, and then inside that I’ll have layers with reference material, cad drawings, construction curves and trimmers etc. that I want to be able to hide with one click.

So as my script is stepping through the model, it checks for visibility and deletes objects if the layer is invisible. However it’s missing objects in (for example) the “cad” layer (which is set to visible, but is a child to “tools” which is invisible.) Is there like a one-line clean option for testing for this or for each object do I need to like if there is a parent layer, and test its visibility, and test if there’s another parent and test its visibility etc. Like a loop that keeps testing till it runs out of parents.

Hi Ryan -

Could you explain in detail why this is a problem for you?

Apparently possible options include:

  1. Leave it as it currently is.
  2. The explosion will create a new material with the same name as an existing material.
  3. Something more complicated that will take lots of time and effort to figure out and test.

What do you want to do?

(see bug report RH-57046 for more information)


When I import into unreal engine with datasmith you end up with thousands of individual meshes that all need materials assigned. Even though the model may only use a handful of different materials overall, it takes ages to go through the model and assign materials if the hierarchy is organized in the logical way you would organize the model in Rhino. So basically my script goes through each object and (if necessary) makes a layer that’s named after the material that’s assigned, then moves the object to that layer.

So this way I end up with a model that has like 6 layers, one for each material. Then it’s really fast in UE4 to pick all the children for a given layer and assign everything the correct material in basically one click.

The problem comes when you explode a block, then look at the index for the layer material and it’s entry is blank. The index comes back as -1 so everything that was in a block gets lumped into the same layer which isn’t workable. Works perfectly in V5. This is specifically a V6 issue.

Thanks for that background, Ryan.
Is it possible for you to share your code? Perhaps there is a different way of achieving your goal.

It’s really scabby and full of debugging prints and stuff… But attached.

I’m having an issue where if I don’t run the functions one at a time it messes up… alternately commenting them out. (4.6 KB)

1 Like

Hey Ryan - Comment from Dale on that issue:

For this user it sounds like have duplicate names would work AS LONG AS the materials with duplicate names are the same. I’ll comment out the new_mat.ClearName(); and see if anybody complains.

Currently, we allow materials to have non-unique names and that has been the case since Rhino 1.

He has pushed a fix in the build-of-the-day of the Rhino 7 WIP.
Could you install that and see if this works for you?

I haven’t bought a V6 license yet… So I don’t believe I can test a fix in V7.

RH-57046 is fixed in the latest WIP