Home Technical Talk

Maxscript: Get spline from selected segment?

polycount lvl 666
Offline / Send Message
PolyHertz polycount lvl 666
I'm trying to create a script to divide selected spline segments once, but am having troubles using subdivideSegment (since splineOps.divide doesn't let you specify the number of segments). It requires the spline index to be specified, however since I'll only have the segment selected it needs to be derived from that, and I have no idea how to get the associated spline index or convert the selection to it in order to use getSplineSelection.

Another problem I'm having is that, assuming there's only one spline but multiple segments selected, using a loop results in stacked divisions on single segments instead of one per segment:

segs = getSegSelection $ 1
for i=1 to segs.count do (subdivideSegment $ 1 ((getSegSelection $ 1)) 1)

Replies

  • akramparvez
    Offline / Send Message
    akramparvez polycounter lvl 8
    how to get the associated spline index or convert the selection to it in order to use getSplineSelection.
    For the first question, you need to loop through all the splines and find if you have any selected segments, if yes then you have the splineIndex(could not find easier method).
    Another problem I'm having is that, assuming there's only one spline but multiple segments selected, using a loop results in stacked divisions on single segments instead of one per segment:
    That's because the segment index changes everytime you subdivide, resulting in a stacked divisions.
    for i=1 to (numSplines $) do (
    	segs = getSegSelection $ i -- segs is empty if no segment selected in the spline
    	segsAdded = 0 --keep track of the number of segments added.
    	for j=1 to segs.count do (
    		subdivideSegment $ i (segs[j]+segsAdded) 1 -- increment the seg index by the segsAdded
    		segsAdded += 1
    	)
    )
    updateShape $
    
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Another spline related question: Is the ability to convert one selection type to another exposed to maxscript (ie. convert a segment to its verts)?
  • akramparvez
    Offline / Send Message
    akramparvez polycounter lvl 8
    No, there is nothing exposed in maxscript to do that. I think you cannot convert it in the UI as well for splines, like using ctrl on editable poly to convert.
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    That's a shame, I find that to be very useful for doing certain things when poly modeling.

    Anyhow, can someone tell me why this doesn't work? I'm Just trying to get the index numbers for all splines that have knots/verts selected on them:
    activeSplinez = #()
    for j=1 to (numSplines $) do
         (
         if ((getKnotSelection $ j).count >= 1) then
              (activeSplinez = activeSplinez + j)
         )
    
  • Noors
    Offline / Send Message
    Noors greentooth
    Because that's not the way to append a variable to an array.

    activeSplinez = #()
    for j=1 to (numSplines $) do
         (
         if ((getKnotSelection $ j).count >= 1) then
              (append activeSplinez j)
         )
    print activeSplinez
    
  • Pac_187
    Offline / Send Message
    Pac_187 polycounter lvl 11
    No, there is nothing exposed in maxscript to do that. I think you cannot convert it in the UI as well for splines, like using ctrl on editable poly to convert.

    You can actually convert a segment selection to a knot selection.
    Even though this is not accessible via maxscript...

    Just wanted to let you guys know :)
    GIF:
    max_select_knots_via_segments.gif
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Huh. I had tried appending before the way I did it above, and it seems to work, but yea the code doesn't give an error anymore using the append command.

    One more question: This code works, but it can't be undone. Apparently this is a long standing issue with Maxscript when working with splines. Is there any easy workaround?
    for j=1 to (numSplines $) do
        (
        activeKnotz = #()
        if ((getKnotSelection $ j).count >= 1) then
            (
            join activeKnotz (getKnotSelection $ j)
            for tmp in activeKnotz do
                (setKnotType $ j tmp #bezier)
            )
        )
    updateShape $
    
  • Noors
    Offline / Send Message
    Noors greentooth
    Stepped upon miauu example on scriptspot looking for a solution as undo command doesn't work.
    Filling activeKnotz array isn't necessary, getKnotSelection $ j is already the array of selected knots.
    theHold.Cancel()
    theHold.Begin()
        ns = numSplines $
        convertToSplineShape $
        for j = 1 to ns do
        (
            k = getKnotSelection $ j
            for i in k do setKnotType $ j i #Bezier        
        )
        updateshape $
    theHold.Accept "Knots type = #Bezier"
    
  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    The hold function seems to do the job, but it requires the convertToSplineShape function which makes it unusable if there are any modifiers in the stack :/
    I've been trying to figure out if there's any other undo-enabled spline functions that will let it work, but no luck so far.
Sign In or Register to comment.