Notifications
Clear all

[Closed] Detach splines from a multispline object

Hi guys I’ve been having a hard time trying to write a simple script that loops through all the splines in a multispline shape and detach them as separate objects. I’ve managed to write the loop but the splineOps.detach() method requires that I named every piece manually. Is there any way to name the objects automatically?

Thanks a lot

3 Replies

Cozmo,

Below are two ways to do this. The first method creates new shapes by rebuilding each spline in the original shape. The other one copies the entire shape and deletes splines from those copies leaving one spline in place. Since the second method creates a copy from the original shape object, this will preserve stuff like material assignments.

(

	/*
		Detaches splines by rebuilding each spline in a new shape.
	*/
	fn ExplodeShape_Copy Shp =
	(
		local SplineCount = numSplines Shp
		
		for Spl = 1 to SplineCount do
		(
			SplineCopy = splineShape name:(uniqueName (Shp.name + "_Exploded_"))
			addNewSpline SplineCopy
			KnotCount = numKnots Shp Spl
			for Knt = 1 to KnotCount do
			(
				if Knt < KnotCount or isClosed Shp Spl then
					addKnot SplineCopy 1 (getKnotType Shp Spl Knt) (getSegmentType Shp Spl Knt) (getKnotPoint Shp Spl Knt) (getInVec Shp Spl Knt) (getOutVec Shp Spl Knt)
				else
					addKnot SplineCopy 1 (getKnotType Shp Spl Knt) #Curve (getKnotPoint Shp Spl Knt) (getInVec Shp Spl Knt) (getOutVec Shp Spl Knt)
			)

			if isClosed Shp Spl then close SplineCopy 1
			updateShape SplineCopy		
		)
	)

	/*
		Detaches splines by copying the entire shape and deleting splines.
	*/
	fn ExplodeShape_Delete Shp =
	(
		local SplineCount = numSplines Shp
		
		for Spl = 1 to SplineCount do
		(
			ShapeCopy = copy Shp name:(uniqueName (Shp.name + "_Exploded_"))
			DelSpline = 1
			for SplineIndex = 1 to SplineCount do
			(
				if SplineIndex == Spl then
					DelSpline += 1
				else
					deleteSpline ShapeCopy DelSpline
			)
		)
	)
	
	--ExplodeShape_Copy $
	ExplodeShape_Delete $
	
)

Cheers,
Martijn

You rock, man, thank you very much for the effort, I was really at a loss here
thanks again
See you around

Also, feel free to steal any code you want from my objectDetacher script here…

http://www.neilblevins.com/soulburnscripts/soulburnscripts.htm

It does exactly what you’re after.

  • Neil