How to store a new shape in a local


#1

Hello everyone!
First, I’m sorry for my english, I’ll do my best to be understandable!

I am trying to create a shape from an edit poly in maxscript.
My script works, but I can’t store my new item in a variable. This is annoying because I can’t use my new item in my script. Like, it is impossible to change the wirecolor of my new shape!

Here is my script:

(
function newShape_Sphere shapename:"" radius:"" segment:"" =
(
local newsphere = sphere radius:radius wirecolor:red segments:segment
local mod_Poly = Edit_Poly()
addModifier newsphere mod_Poly
modPanel.setCurrentObject newsphere.modifiers[#Edit_Poly]
newsphere.modifiers[#Edit_Poly].SetSelection #Edge #{1…380}
local newShape = newsphere.modifiers[#Edit_Poly].CreateShape shapename
– newShape.wirecolor = red

  delete newsphere
  return newShape

)

local shapeSphere = newShape_Sphere shapename:“TestShape01” radius:2.0 segment:20

)


#2
shp_name = uniqueName #tmpShapeName
$.modifiers[1].createShape shp_name
shp = getNodeByName shp_name
shp.wirecolor = red

#3
fn ExtractShape polyMod shapeName =
(
	oldShapes = shapes as array
	polyMod.CreateShape shapeName
	newShape = undefined
	for o in shapes where finditem oldShapes o == 0 do newShape = o
	newShape
)

delete objects
obj = sphere isselected:true radius:10 wirecolor:blue segments:20
polyMod = edit_poly()
addmodifier obj polyMod
subobjectLevel = 2
polyMod.select #edge #{1..200}
newShape = ExtractShape polyMod "NewShapeName"
delete obj
newShape.wirecolor = orange

#4

It does work! Thank you for your help!


#5

MZ’s solution did work, but It took fairly long time to execute.
So I’ve worked with Serejah solution and I found this which work perfectly!
Thank you for your help!

function newShape_Sphere nameshape radius segment = 
(
	local newsphere = sphere radius:radius wirecolor:red segments:segment
	newsphere.name = "Sphere Origine"
	local mod_Poly = Edit_Poly()
		addModifier newsphere mod_Poly
		modPanel.setCurrentObject newsphere.modifiers[#Edit_Poly]
		newsphere.modifiers[1].SetSelection #Edge #{1..380}
		newsphere.modifiers[1].CreateShape nameshape
	local newshape = getNodeByName nameshape
		newshape.wirecolor = red
	
	delete newsphere
	return newshape

)

#6

make sure to have a unique name for the target node, nameshape in your case
or you end up picking wrong node if a node with such name already exists


#7

Oh you’re right @Serejah Thanks :slight_smile: