Notifications
Clear all

[Closed] Script for sorting out splines

Just for a bit of variety, here’s the start of a dialogue version of the same script…be patient this is my first dialogue!
Right now it doesn’t work too well, since I got a bit confused about the processing order and where to put/assign variables and functions.

Having some fun with the structure, and a rogue integer problem in one of the spinners.

It would be nice to insert some feedback into the dialogue in the labels TBC1 and TBC2…how do you do this?

Also maybe a progress bar at some point when I’ve got my head around the overall structure.

Any thoughts?

It’s disappointing that splineOps.weld() doesn’t work outside of modify mode/subobject level. Since it doesn’t, it looks like you’re doing things the best way available, so I apologize for steering you down a more confusing path. There are a couple of things left in your script that you can clean up, though.

You’re doing sel = getCurrentSelection(), and then later doing splines = for obj in selection where superclassOf obj == Shape collect obj. It would be slightly more efficient (and logical) to use the objects you’ve already gathered into sel for the collect loop. For instance:

sel = getCurrentSelection()
splines = for obj in sel where superclassOf obj == Shape collect obj

Here’s a neat trick – you can condense this all down into a one-liner:

splines = for obj in (sel=getCurrentSelection()) where superclassOf obj == Shape collect obj

This works because assignment returns the value being assigned, and because (sel=getCurrentSelection()) is still being executed in the same namespace where select sel is later being called.

The only other thing that I see is that you’re calling max select none twice. Neither of these two things will break your script if you leave them as is, I just wanted to give you some housecleaning tips:p

Next step would be to make an interface so the user can set some of their own options, like what types of shapes to operate on, what types of cleanup to do, setting the steps variable, etc. Are you ready to try this?

RH

<edit> I wrote that last part before noticing your last post. Glad to see that you’re one step ahead of me;) </edit>

thats OK…your feedback is greatly appreciated!

I also tried a version using the avg_dlx50 extension which has a function splineweld which lets you input a weld threshold.

I’ll have a look at condensing the selection process as part of doing the interface.

Eek I suddenly became a veteran!!:bounce:
And I’m still learning:thumbsup:

OK heres the latest interface…

How do I assign conditions in the main splinesort loop based on the state of the checkboxes in the interface? It looks like the states will get processed before theyre defined as it stands. Does the splinesort function need to be placed elsewhere in the script.

Also when I assign variables from spinners – whats the best way of doing this. Right now they only get assigned when the spinner changes – so I have to set defaults at the beginning of the script.
Can these be automatically set from the default states of the spinners?

I think that there may also be a problem with the release of variables, since I get unpredictable results when I run it twice on the same set of splines…eg. a second pass to change the steps value if its not right the first time.

I left the image file out for now.
The idea was to create a suite of scripts later on…how do you do this, so that they can easily be assigned to menus etc.

Phew…thats a lot of questions!
Thanks again for all your help RH

The best (programming practice) way to do it would be to pass them checkbox states as arguments to your sortsplines routine;


function sortsplines splines checkstate1 checkstate2 ... = (
)

sortsplines splines checkbox1.checked checkbox2.checked...

To avoid a long function definition you could define a struct to hold all the checkbox states;


struct checkstates = (
   state1,
   state2,
   state3...
)

function sortsplines splines states = (
      if (states.state1) then (
     )
)

var states = checkstates state1:checkbox1.checked state2:checkbox2.checked....

sortsplines splines states

(Hope that wasn’t too confusing an example there)

Alternatively you could declare your rollout as a global variable at the head of your script and then refer to the checkboxes directly from within the sortsplines function;


global sortspline

function sortsplines splines = (
    if (sortspline.checkbox1.checked) then (
    )
)

But global variables are a bit bad practice…

Thanks Baldrick…thats a really cunning plan!
I’ll need to read around it a bit in the help file first and then give them a try.

No probs

I just realised that you asked more than one question…

Not sure about your variable clean up, I’ll have to have a closer look at the code for that…

Creating a suite of utilities: Creating your routines as functions that can be called from a UI (as you’re already doing) is the way to go. Then so long as your functions are in memory (load them at startup by placing them in scripts\startup) you can call them from anywhere you like – eg, a macroscript wrapper (so can give them icons or put them on quads), call them from the listener, or create your own switchboard UI to call them from – all perfectly possible. Take a look at something like the blurscripts package to see how they’ve packaged all their utilities together.

Rather than blabber on about things here, I decided to modify and comment your code. Hopefully it won’t be too difficult to see what I’ve changed and why. There are more things that could be done differently, but as long as this works there wouldn’t be much point to it. Just cosmetic stuff. As always, I had nothing to refer to and no way to test this, so it might complain a little over some minor syntax or spelling issues;)

Thanks, Baldrick, for adding your wisdom to the discussion. I can see that you’re fairly new to posting here at CGTalk, but you obviously have some Maxscript savvy! I look forward to your input here:airguitar

RH

Page 2 / 3