How to clone object using python

How to clone object using python

mateusz.zelent
Participant Participant
3,249 Views
8 Replies
Message 1 of 9

How to clone object using python

mateusz.zelent
Participant
Participant

Hi,

 

could you help how to duplicate object using python script ind 3Dmax 2018?

 

Regards,

MZ

0 Likes
Accepted solutions (2)
3,250 Views
8 Replies
Replies (8)
Message 2 of 9

morten_bohne
Advocate
Advocate

If you just want to copy the selected node, you could do it like this:

from pymxs import runtime as rt

# get the selected node
sel = rt.selection[0]

# copy selected node
rt.copy(sel)
Message 3 of 9

mateusz.zelent
Participant
Participant

Hi, 

 

thank you for your response. 

 

I have found second way: 

 

MaxPlus.Core.EvalMAXScript("myType = #copy")
rt.maxOps.cloneNodes(rt.mySphere2,  cloneType=rt.myType)

My goal is to create a vector field (space of 3d of arrows):

Znalezione obrazy dla zapytania vector fields

 

I do not know how to draw an arrow using python code, so I would like to clone an already created one. Then I plan to give them rotation and location later. What do you think is the best way to achieve this?

 

Message 4 of 9

morten_bohne
Advocate
Advocate
Accepted solution

that works too 🙂

 

If you want to get rid of the EvalMaxScript part, you could do it like this:

rt.maxOps.cloneNodes(sel, cloneType = rt.name("copy"))

 

and to create a grid of objects:

count = 3
offset = 50

for x in range(count):
	for y in range(count):
		for z in range(count):
			node = rt.teapot()
			node.pos = rt.point3(x*offset, y*offset, z*offset)
Message 5 of 9

mateusz.zelent
Participant
Participant

Perfect!

 

Thank you for help, now I know also how to create an arrow, but do you know how to connect these two objects into one node?

node=pymxs.runtime.cone()
node.radius1=1.8
node.height=3.5
node.pos=rt.point3(0,0,5)

node=pymxs.runtime.cylinder()
node.radius=0.9
node.height=5
node.pos=rt.point3(0,0,0)

0 Likes
Message 6 of 9

morten_bohne
Advocate
Advocate
Accepted solution
import pymxs

cone=pymxs.runtime.cone()
cone.radius1=1.8
cone.height=3.5
cone.pos=rt.point3(0,0,5)

cylinder=pymxs.runtime.cylinder()
cylinder.radius=0.9
cylinder.height=5
cylinder.pos=pymxs.runtime.point3(0,0,0)

pymxs.runtime.convertToMesh(cone)
pymxs.runtime.convertToMesh(cylinder)

pymxs.runtime.attach(cone, cylinder)

arrow = cone
arrow.pivot = pymxs.runtime.point3(0,0,0)

 

Message 7 of 9

mateusz.zelent
Participant
Participant

Thanks to you, right now I am very close to finish this task!

 

I hope that will be a last question, do you know how to assign material to each node? 

 

I would like to do smh like this:

 

1. Select node 1, 

2. assign to the node Scanline -> Standard,

3. Set the color, and material properties.

 

 

0 Likes
Message 8 of 9

morten_bohne
Advocate
Advocate
from pymxs import runtime as rt

tpot = rt.Teapot()
mat = rt.StandardMaterial()
tpot.material = mat
mat.Diffuse_Color = rt.color(255, 0, 0)
0 Likes
Message 9 of 9

mateusz.zelent
Participant
Participant

Hi, 

 

how to select standard material I know, but how to select a different one and then control its parameters?

 

Mateusz 

0 Likes