Notifications
Clear all

[Closed] spline project script doesn't work

Hi,

i found a mcr called “Spline Project” from “Chuggnut” on my old harddrive, and i remembered it worked quite well some years ago. I’ve installed it, but it always say “Invalid selecetion” – regardless of wether a mesh or poly object, a regular or an irregular mesh …
I hope there are no copyright issues posting the code in this forum – back then it was free.

Here is the code:
[color=Yellow]
–***********************************
–* project spline onto mesh v1.1 *
–***********************************

macroscript Spline_project category:“Chuggs tools” tooltip:“Spline Project”
(
if (selection.count == 1) and (superclassof selection[1] == shape) then
(
obj = copy selection[1]
obj.name += “_projected”
converttosplineshape obj

       pointer = splineshape name:"pointer" wirecolor:(color 255 255 0)
       for i = 1 to obj.numsplines do
           (
           mid = [0,0,0]
           midcount = 0
           for n = 1 to (numknots obj i) do
               (
               mid += (getknotpoint obj i n)
               midcount += 1
               )
           addnewspline pointer
           addknot pointer i #corner #line (mid / midcount)
           addknot pointer i #corner #line ((mid / midcount) + (obj.dir * 80))
           )
       updateshape pointer

       if (pickobj = pickobject message:"Pick an object") != undefined do
           (
           new_obj = pickobj
           fail = 0
           for t = 1 to obj.numsplines do
               (
               for i = 1 to (numknots obj t) do
                   (
                   k = getknotpoint obj t i
                   r = ray k obj.dir
                   if (np = intersectray new_obj r) != undefined then
                       (
                       d = length (k - np.position)
                       v = false
                       if (getknottype obj t i == #bezier) or (getknottype obj t i == #beziercorner) do
                           (
                           inv = getinvec obj t i
                           outv = getoutvec obj t i
                           v = true
                           )
                       setknotpoint obj t i np.position
                       if v do
                           (
                           infail = true
                           outfail = true
                           r = ray inv obj.dir
                           np = intersectray new_obj r
                           if np != undefined do
                               (
                               setinvec obj t i np.pos 
                               infail = false
                               )
                           r = ray outv obj.dir
                           np = intersectray new_obj r
                           if np != undefined do
                               (
                               setoutvec obj t i np.pos
                               outfail = false
                               )
                           if infail do
                               (
                               setknottype obj t i #beziercorner
                               setinvec obj t i (inv + (obj.dir * d))
                               )
                           if outfail do
                               (
                               setknottype obj t i #beziercorner
                               setoutvec obj t i (inv + (obj.dir * d))
                               )
                           )
                       )
                   else
                       (
                       fail += 1
                       )
                   )
               )
           if fail == (numknots obj) then
               (
               updateshape obj
               delete obj
               delete pointer
               )
           else
               (
               updateshape obj
               delete pointer
               )
           )
       )
   else
       (
       messagebox "Invalid selection!"
       )
   )[/color]

I’m far away from a scripter so i hope someone can fix it working with max 2011.

Note: Please, Mr. Chuggnut, forgive me posting this, but this script is very useful to me…If there are any issues with copyright etc. pls. let me know. Then this thread should be closed immediately!

TIA

4 Replies

It looks like it works if the message you are getting is invalid selection. I didn’t test it but the line at the bottom that says:


else
(
messagebox "Invalid selection!"
)  

Means that you must not have the correct type of object selected. And at the top:


superclassof selection[1] == shape
 

means you need to select an object of a class shape. So shape or editable spline. If you don’t have on object of that class selected in will open a message box that says “Invalid selection!”

Hi Viro,

thanks for your reply and it’s all right what you have stated so far, but i used this script times ago with meshes, so that’s the reason why i post it here. Look at this old scriptspot entry:
http://www.scriptspot.com/3ds-max/scripts/spline-project

(Sadly the author powered down his website:shrug:)

Maybe max versions before 2010 have interpreted things less rigorous, so “shape” was eventually right…Don’t know, what do u think?

I think you might be confussing this script with another script.

From the script spot post:
Same kinda thing as mesh project except projects spline anlong their Z axis onto the surface of an object.”

Which makes me think he did another script called mesh project.
http://www.scriptspot.com/3ds-max/scripts/mesh-project

ok, that could be the reason why …am i really so stupid? Yes, i am:lightbulb Thanks for this hint, sometimes wood disappears behind trees:surprised

Ähh, and what about this script? What could be done with that?