Notifications
Clear all

[Closed] Spline Inseter

I made a script (with the help of you beautiful people) that can take a spline and pull the ends in 3 units. There’s probably a more elegant way to do this, but I’m not much a programer so I did the best I could. It works fine so long as I only have one shape selected. If I have multiple shapes selected, though, the part towards the end that welds knots together doesn’t work right. It works fine for the last shape in the selection, and it works fine as long as no spline has more than 3 knots in it, but if there’s a spline with 4 or more knots that is not in the last shape of the selection, it doesn’t weld. I can’t figure out why. If anyone has any suggestions on how I can get it to weld reliably, I would appreciate it. Here’s the whole script to look at and if anyone else would get a use out of it.

try (destroyDialog spline_inseter) catch()

rollout spline_inseter “Spline Inseter”
(
–Creates button
button do_it “Inset Splines” width:141 height:27

on do_it pressed do
(
    --Makes an array of selected splines
    thesel = selection as array
    --Loops through selection
    for i = 1 to thesel.count do
    (
        --Isolates one spline
        obj = thesel[i]
        --Keeps track of the spline name
        name_tracker = obj.name
        --Empties the face array
        face_array = #()
        --Empties the edges array
        edges = #()
        --Makes an extrude modifier
        extr = extrude()
        --Sets the extrude amount
        extr.amount = 100000
        --Adds an extrude modifier to the spline
        addmodifier thesel[i] extr
        --Converts the extruded spline to an editable poly
        converttopoly obj 
        --Insets the polys, creates a shape from the inseted polys, deletes the original spline, and renames the new spline with the old name
        select obj
        subobjectLevel = 4
        polyOp.setFaceSelection obj #all
        obj.insetType = 0
        obj.insetAmount = 3
        obj.EditablePoly.buttonOp #Inset
        face_array = polyOp.getFaceSelection obj
        edges = polyop.getEdgesUsingFace obj face_array
        polyop.createShape obj edges
        spl = $Shape01
        delete obj
        spl.name = name_tracker
        
        setCommandPanelTaskMode mode:#modify
        --Welds all verts together
        max select none
        select spl
        subObjectLevel = 1
        max select all
        splineOps.weld spl
        subObjectLevel = 0
        updateshape spl
        
        --Deletes all knots but the bottom ones
        
        for s = 1 to (numsplines $) do
        (
            global edge_array = #()
            global deleter = 0
            for k = 1 to (numsegments $ s) do
            (
                tracker = 0
                knt_1 = getKnotPoint $ s k
                if isClosed $ s do
                (
                    if k < (numsegments $ s) do
                    (
                        knt_2 = getKnotPoint $ s (k+1)
                    )
                    if k== (numsegments $ s) do
                    (
                        knt_2 = getKnotPoint $ s (1)
                    )
                )
                
                if isClosed $ s == false do
                (
                    knt_2 = getKnotPoint $ s (k+1)
                )
                
                
                if knt_1.z > ($.pos.z+40000) do
                (
                    if tracker == 0 do
                    (
                        deleter = (deleter + 1)
                        edge_array [deleter] = k
                        tracker = 1
                    )
                )
                if knt_2.z > ($.pos.z+40000) do
                (
                    if tracker == 0 do
                    (
                        deleter = (deleter + 1)
                        edge_array [deleter] = k
                        tracker = 1
                    )
                )
                subObjectLevel = 2
                setsegselection spl s edge_array
            )
        )
        max delete
        updateshape $
        
        --Welds all verts together
        subObjectLevel = 1
        max select all
        splineOps.weld $
        subObjectLevel = 0
        updateshape $
        
        --Sets the knots to corner
        for s = 1 to (numSplines $) do
        (
            for k = 1 to (numKnots $ s) do
            (
                knt = getKnotPoint $ s k
                in_vec = getInVec $ s k
                out_vec = getOutVec $ s k
                setKnotType $ s k #corner
                knt.z = (knt.z - 3)
                setInVec $ s k in_vec
                setOutVec $ s k out_vec
                setKnotPoint $ s k knt
                updateshape $
            )
        )
    )
)

)

createDialog spline_inseter 160 40

5 Replies

I was reading though your script and can’t see what you are trying to do. When I run your script it makes a edit poly from shape then makes it back into a shape. But new shape is -3 units below old shape.

Are you trying to make a smaller outline of a shape? Sorry

Si

Yeah, I’m sure it seems strange. Here’s a picture of a file I run into on a regular basis. This is the side view and top view. Each different color is a different shape with a unique name. I need all of these to stay unique and have the same name, but I need the ends of each spline of each shape pulled in 3 units. Normally how I would handle this is extrude each shape up, convert it to a poly, inset every face by 3 units, select the bottom edges of the new faces, create a new shape from that selection, delete the poly, rename the new shape with the old name, and drop the new shape 3 units to match the original z position of the first shape. Given that the shapes can have a variety of orientations and heights, this is the quickest way I could think of to pull the ends in by 3 units. I tried to make this script to automate the process since it’s the same every time. That’s what the script does, but it can only do it one shape at a time.

I had to do this for a scaffold script. You can inset a spline, this gives you a shape with 2 spines. You just delete shape 1 and you are left with a spine inset the amount you need. I’m not in office but I will try and sort it for you in the morning. So all in all you never need to change name or colour and don’t have to make poly from your shape.

Oh, one other thing. This looks like it might be from cad. Some splines might be flipped. The check this you get length of your spline first then copy it and measure both spline indexes. If one is shorter then you know it is not flipped. Delete you copy and offset the first. Bit long but you can’t get a normal of a spline to see if it’s flipped.

This should work for you. It will also find and repair all flipped splines


 ---------------------------------------------------------------------------
 -- Make Offset of Splines
 -- Simon Donaghy
 ---------------------------------------------------------------------------
 My_offset = 3
 
 The_Spline = #()
 The_Spline = for o in selection where SuperclassOf o == shape collect o
 macros.run "Modifier Stack" "Convert_to_Spline"
 for s = 1 to The_Spline.count do(
 	-------- Make our offsets ---------
 	 applyOffset The_Spline[s] My_offset
 	applyOffset The_Spline[s] -My_offset
 	deleteSpline The_Spline[s] 4
 	-------- get our spline length ---------
 	Old_Length_Array = getSegLengths The_Spline[s] 1
 	In_Length_Array = getSegLengths The_Spline[s] 2
 	Out_Length_Array = getSegLengths The_Spline[s] 3
 	Old_Length = 0
 	In_Length = 0
 	Out_Length = 0
 	for i = 1 to Old_Length_Array.count do(
 		Old_Length = Old_Length + Old_Length_Array[i]
 		In_Length = In_Length + In_Length_Array[i]
 		Out_Length = Out_Length + Out_Length_Array[i]
 	)
 	--------  Remove extra Shapes  -----------
 	if In_Length < Old_Length then(
 		--------  Good spline  -----------
 		deleteSpline The_Spline[s] 3
 		deleteSpline The_Spline[s] 1
 	)
 	else(
 		--------   Flipped spline  -----------
 		deleteSpline The_Spline[s] 2
 		deleteSpline The_Spline[s] 1
 		splineOps.reverse The_Spline[s]
 	)
 )
 gc()