Jump to content

Maxscript - Delete spline segments not working inside functions


niculaegeorge

Recommended Posts

Goal: Create a quarter of an ellipse, and elevate one of its points. :geek:

 

I’ve manage to make it work, but inside a function, everything falls apart.

Obviously from the code that I’m a beginner, so this is it:

Delete $*
 clearlistener ()
 function test var1 =
 (
 Ellipse adaptive: true  length:10 width:var1 pos:[0,0,0] name: "s"
 convertToSplineShape $s
 updateshape $s
 Select $s
 modPanel.setCurrentObject $s.baseObject --this line is optional
 subobjectLevel = 2
 setSegSelection  $s 1 (#(1,3,4))  --keep: false –delete all except second quadrant
  
 splineOps.delete $ --everything is ok until now
  
 --actionMan.executeAction 0 "40020"  -- worked for a while, then it started to delete the entire shape
 subobjectLevel = 0   --this is where everything goes berserk, I tried "=2" as well, still not working.
 updateshape $s
 --clearselection()
  
 addmodifier $s (Spline_IK_Control helper_size: 0.5 linkTypes: 2 box:off helper_cross: on wirecolor: yellow)
  updateshape $s
 $s.spline_ik_control.createHelper  ($s.spline_ik_control.getKnotCount())
     clearselection()
 move $Point001 [0,0,10]  --point repositioning not working on the second run of the code
   $Point001.pos.z =10  --not working either when the code is run second time
 )  
   
 test 20

Point repositioning in the last lines at first they did not work, then it started again but point002 start to move as well, then it only worked after the second execution of the code in a fresh environment. I feel like I’m in the Twilight Zone...

at line

subobjectlevel = 0

after the splineops.delete $

command, the segments reappear as if the delete command did not took hold. Like it was a temporary delete of somekind. :? I've tried resetshape, updateshape, clearselection, and many things in different arrangements. Is there a command like „clear and empty all variables and reset the entire environment for a fresh start” to place at the start of the code? What am I missing here?

My guess is that I'M NOT EXITING FROM THE SUB-OBJECT EDITING MODE PROPERLY :unsure: and thus the results are not embedded and printed out of from the shape cache or something. And probably that is why the final repositioning of a spline IK point is not working properly, since I’m still in a somekind of a sub-object editing mode.

Link to comment
Share on other sites

Thanks to forum user gazybara on cgsociety.org apparently I have to “open” the spline before I attempt any operations on it. I didn’t know that. I have learned something new today.

Deleting knots and not segments is indeed far more efficient 8), and resetting the numbering of the first knot is indeed brilliant if in future developments of the code I intend to use a for loop to delete them.

I’m interested in repositioning ONLY ONE of the remaining 2 points in the spline, therefore my final code, and what I was really after, basically looks like this:

fn my_fct =
 (
 spl = convertToSplineShape(Ellipse adaptive: true  length:10 width:20 pos:[0,0,0] name: "s")
 open spl 1
 deleteKnot spl 1 1
 deleteKnot spl 1 3
 setKnotPoint spl 1 1 [0,5,2]
 updateshape spl
 )
 my_fct()

So I will develop upon this code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...