[Closed] Detach Spline sections as a Copy
I need some help with writing a script that takea a segment of a spline and detaches it as a copy, then deselects the original spline and selects the new shape.
To do this in Max, I would have to make the selection, then the copy option (the check box – Same Shp, Reorient, Copy), then click the detach button, exit sub object mode, and then select the new object.
What I want to do is make a script that automates everything after the spline segments are selected. I tried using the MacroRecorder in Listner but the operation doesn鈥檛 show the script for these actions.
Anyone know how to do this or how to find out what commands are needed to do this (the help file didn鈥檛 turn up anything coherent to someone who鈥檚 not familiar with programming)?
Does anyone know of an online resource that gives the information that the Max listener doesn鈥檛 display? If it鈥檚 in the help file, I鈥檇 appreciate it if someone could direct me to what I need to look for. I don鈥檛 have a programming background, so a lot of the technical stuff is Greek to me.
The topics in the help file that you鈥檇 be looking for are:
- SplineShape : Shape
- Editable Spline Modify Panel Command Modes and Operations
Both topics contain, among other, the code:
splineOps.detach <editable_spline_or_line_node_or_modifier>
Which pops up the detachment dialog where you give the detached selection a new name.
Unfortunately, I鈥檓 not spotting any method to change the detachment method, so the above function may be mostly useless to you and you might have to resort to some manual coding.
For example, a quick-and-dirty detach::copy function would be (presuming it doesn鈥檛 have bugs):
fn detachSegSelection myShape:$ doCollapse:false = (
if (myShape == undefined) then ( return false )
else if (classOf myShape != SplineShape) then ( return false )
else (
local newShape = copy myShape
newShape.name = myShape.name + " (detached selection)"
for splineIndex = 1 to numSplines newShape do (
local segSelection = getSegSelection newShape splineIndex
print segSelection
local newSelection = for segIndex = 1 to (numSegments newShape splineIndex) collect (
if (findItem segSelection segIndex == 0) then ( segIndex ) else ( dontcollect )
)
setSegSelection newShape splineIndex newSelection
)
updateShape newShape
max modify mode
select newShape
subObjectLevel = 2
modPanel.addModToSelection (deleteSplineModifier())
if (doCollapse) then ( collapseStack newShape )
)
)
Which you can easily turn into a detachment to the same shape by re-attaching the result.
The alternative is to get the appropriate knots for the segment selections and re-construct those segments yourself into either a new shape or the existing shape.
The above works pretty quickly and adds a 鈥榥on-destructive鈥?type of detachment by taking advantage of the 鈥楧elete Spline鈥?modifier on the stack.
( the function takes a 鈥渄oCollapse:<bool>鈥?parameter which, if passed 鈥榯rue鈥? will collapse the stack – imagine that )
Another alternative would be:
for o in selection where isKindOf o line do
(
s = copy o
s.name = uniqueName (o.name + "_stripped")
s.wirecolor = orange
with redraw off
(
select s
subObjectLevel = 2
max select invert
max delete
subObjectLevel = 0
)
)
It depends on how you want to go at it鈥?the above code would probably make it to the listener if you do the steps by manually.
-Johan
jots ‘max select invert down for future reference*
silly 鈥榤ax <command>鈥?bits that don鈥檛 have proper script equivalents. grmbl
lol!
Well splineOps is lacking an awfull lot of functionality鈥?also most ops is equivalent to pressing the button :rolleyes:鈥?whoever invented that super non intuitive way of coding鈥?/p>
Hack safely!
-Johan
Okay鈥?I鈥檓 such a novice that I鈥檓 sure it鈥檚 something overly obvious that I鈥檓 missing or not understanding, but I can鈥檛 get the script to run in either listener or as a script file that I have saved out. When I run it as a script, nothing happens. When I run it in listener, I get an error stating;
鈥?- Syntax error: at ), expected <factor>
鈥? In line: )鈥?/p>
Which (I assume) means that it鈥檚 only trying to run the last line (which in this case is just a close parenthesis)
How do I impliment this script? What did I miss? (I tried both)
-EDIT-
By the way, thanks for the help so far
perhaps you鈥檙e running into some manner of copy/paste issue. I鈥檓 attachined a zip file with both scripts (each slightly adjusted to optimize them a bit / correct some issues).
In 3ds Max, just choose 鈥淩un Script鈥?and pick one of the files. If that works, you can 鈥淥pen Script鈥? select all the script code, and drag&drop that text to a toolbar to make it a toolbar button for easy re-use in the future.
okay鈥?those work. I did copy out the command and save it out as a script myself (before running it) before this though. Any idea why that didn鈥檛 work? If I know why it happened, it might explain a lot of the problems why I have trouble with scripting in general.
Oh, and thank you! Where do you find those commands? Are they in the help file? I just wasn鈥檛 finding them on my own.
maybe when you selected the code here on CGTalk you didn鈥檛 quite copy all of it? Can鈥檛 really think of a reason. The error message 3ds Max reports is pretty vague and one of the frequent headaches for any scripter
as for the functions / commands – just the 3ds Max help file and, basically, experience with MaxScript and navigating that file. Hitting the 鈥淪earch鈥?option is often your best bet unless you already know what topic to look in, though.
That said鈥?if you鈥檙e serious about scripting, I highly recommend taking a few evenings to just page through the entire help file (skip the topics you won鈥檛 be working with鈥?e.g. NURBS, which is dozens of pages of icky stuff which you鈥檒l only need if you鈥檒l be working with NURBS). There鈥檚 a lot of information in there, and reading it through once will at least give you a mental trigger when you鈥檙e looking to solve a particular problem. In addition, you鈥檒l encounter chapters that may seemingly be useless for what you鈥檙e looking for but are actually quite useful. e.g. 鈥済etTextExtent鈥?(used in another thread I posted to) helps get the width of a string if it were displayed in a rollout. But this command isn鈥檛 actually listed in any of the rollout/UI chapters, but rather in the Strings chapter. (they may have included it in an UI chapter in a later max version, though)