Stripping string names from selected

Hi, new user here , first off I must say what an amazing community.

I found this script and wondered how I could edit the string name of the selected object

ie selected objects are box_001 , dave_ , foobar_blahblah , instead I just want to strip everything away after the underscore of the name. Which will then build the layers and place the objects into the layer

(
if selection.count != 0 do
(
for o in selection do
(
objName = o.name
if (objLayer = LayerManager.getLayerFromName objName) == undefined then
(
objLayer = Layermanager.newLayerFromName objName
objLayer.addNode o
)
else
(
objLayer.addNode o
)
)
)
)

Kind regards

Rob

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
brownpaperbag's picture

Thanks so much for the

Thanks so much for the pointer

r

miauu's picture

.

(
	if selection.count != 0 do
	(
		for o in selection do
		(
			objName = o.name
			--
			nameArr = filterString objName "_"
			objNameWithout = nameArr[1]
			--
			if (objLayer = LayerManager.getLayerFromName objNameWithout) == undefined then
			(
				objLayer = Layermanager.newLayerFromName objNameWithout
				objLayer.addNode o
			)
			else
			(
				objLayer.addNode o
			)
		)
	)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.