Question

I've run into a frustrating problem with some max script I'm writing and was hoping someone might know why my code isn't working.

I've had success in my same script with other geometry and attach:

fn base = (
     base_geo = convertToPoly(Plane length:10 width:10 pos:[0,0,5] isSelected:on lengthsegs:1 widthsegs:1)
     base_geo.pivot = [0,0,0]
     return base_geo
)

corner_geo = base()
plane1 = base()
--irrelevant rotation + transformation scripts
corner_geo.attach plane1 corner_geo

this works fine

however when I try the same thing later:

fn place_trim x y z trim_type = (
maxOps.cloneNodes trim_type cloneType:#copy newNodes:&cur_group
--convertToPoly(cur_group)
cur_group.pos = [x,y,z]

    --not sure how to properly access this name
--print "cur_group name = " + cur_group[1].name
return cur_group
)


fn walls trim_type = (
wall_geo = base()
rotate wall_geo (angleaxis -90 [1,0,0])
plane1 = base()
wall_geo.attach plane1 wall_geo

if trim_type == "inner" do (
    trim_type = final_inner_trim
)
if trim_type == "outer" do (
    trim_type = final_trim
)

if trim_type != undefined do (
    trim = place_trim 0 0 0 trim_type

wall_geo.attach trim wall_geo

)

return wall_geo
)


final_trim = $trim_final
final_inner_trim = $inner_trim_final
walls("outer")

When I reach the bolded section of code I get this error: "--Unable to convert: #($Editable_Poly:trim_final001 @ [0,0,0]) to type: node"

I'd be very grateful for any suggestions on what I'm doing incorrectly!

Was it helpful?

Solution

Although I've already replied back at cgtalk, the comment here turns it into a slightly different topic. In a situation like this, the only way I can think of to get the new copy of $Plane000 (assuming this default prefix as you are not specifying any other) by name would be searching for n of the $Plane* nodes with the highest number - don't do that, ever.

It doesn't matter that in this particular case, there's a simple solution where you get the node returned directly; in some cases (such as the detach command) you won't. Again, the detached object would get the default Object prefix, but actually the easiest way to get it is just

obj = objects[objects.count]

Same applies for a bunch of newly created objects: get a count of objects before, then when yu get some new nodes in the scene through a process over which you have little or no control (think third party plugins), simply collecting the nodes starting from the previous count raised by one will get you there.

OTHER TIPS

I'm not sure its that complicated. Quite simply, your place_trim function returns an array. Even if its an array of size 1, Max won't implicitly convert that to a node pointer. You need to get your items out of the array for the attach.

What you want to do is

for some_trom in trim do ( wall_geo.attach some_trim wall_geo )

If performance is a concern, you could disable ref msgs / undo while doing this operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top