Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

Maxscript function argument
show user profile  3joez
How do I specify a function argument?

I have this function that puts the pivot to the bottom of selected objects

fn bp =

$.pivot = [($.max.x+$.min.x)/2, ($.max.y+$.min.y)/2, $.min.z ]

I want to add an argument so that when I call bp($) it reads the current selection.

fn bp =

$.pivot = [($.max.x+$.min.x)/2, ($.max.y+$.min.y)/2, $.min.z ]

for ob in $ do (
convertToPoly $
polyop.setVertSelection ob #all
ob.weldThreshold = 0.001
polyop.weldVertsByThreshold ob #all


Right now it's not positioning the pivot relatively to the single objects but to the whole selection.

read 496 times
5/16/2014 12:07:37 PM (last edit: 5/16/2014 12:15:59 PM)
show user profile  Garp
If I understand correctly, you want
fn bp obj = obj.pivot = [,, obj.min.z]

then the call would be
for ob in selection do(
. . .
bp ob

Is that it?

edit: you don't have to select the verts prior to welding them since the weld method lets you pass a vertex list (here #all).

edit2: as a more general advice, it's good practice to restore system defaults when you change them as there might be other parts of your script - or other scripts - that rely on their values. Just frame the code with a store/load:
oldThreshold = ob.weldThreshold
. . . change threshold and do stuff
ob.weldThreshold = oldThreshold

read 492 times
5/16/2014 12:47:26 PM (last edit: 5/16/2014 1:11:38 PM)
show user profile  3joez
Garp, that's way more elegant than what I wrote.

fn bp obj =

obj.pivot = [,, obj.min.z ]

for obj in selection do (

obj.weldThreshold = 0.001
polyop.weldVertsByThreshold obj #all
bp obj



I will take the time to restore the defaults too, as you suggested.
read 436 times
5/19/2014 9:52:47 AM (last edit: 5/19/2014 9:52:47 AM)
show user profile  Garp
You're welcome :)

read 430 times
5/19/2014 12:11:07 PM (last edit: 5/19/2014 12:11:07 PM)
#Maxforums IRC
Open chat window