본문 바로가기

Code/cinema4d & 3dsmax

[3dsMax python] pymxs 사용해보기

MAXScript 런타임 사용하기

자바스크립트의 런타임은 브라우저가 될수도 있고, node.js 가 될 수 있는것 처럼

맥스스크립트를 인식할 수 있는 런타임이 있고,

파이썬을 인식할 수 있는 런타임이 따로 있습니다.  근데 pymxs 는 맥스스크립트를 랩핑한거니깐 맥스스크립트의 런타임도 사용하는 것 같습니다. 근데 뭐.. 맥스스크립트를 잘 몰라서 큰 의미는 없을것 같습니다.

일단 '그냥 rt. 뒤에 나오는게 맥스스크립트에서 사용하는것과 비슷하게 사용하고, 맥스스크립트 런타임을 사용한다'고 이해하고 넘어야야 겠습니다. 

 

import pymxs
rt = pymxs.runtime
t = rt.Teapot()
rt.classOf(t)

MAXScript Undo System

이거 돌려봤는데 호출해서 사용했을때 버그가 있는것 같아 포럼에 질문남겨놨습니다.(link)

그냥 스크립트에서도 안되면 맥스를 재실행하면 됩니다. (하..)

 

import pymxs
rt = pymxs.runtime
# this will not be undoable:
with pymxs.undo(False):
    t = rt.Teapot() # teapot() 하고 같음

with pymxs.undo(True):
    t.pos = rt.Point3(20,20,20)

pymxs.run_undo() # undo the position
pymxs.run_redo() # redo the position

MAXScript Names

맥스스크립트에 Name이란게 있나봅니다. 아래에서는 world가 name인데 파이썬에서는 name 이란게 없어서 이렇게 사용해야합니다.

 

# maxscript
toolmode.coordsys world
# python
pymxs.runtime.toolMode.coordsys(pymxs.runtime.Name("world"))

Indices

인덱스에 대해서 설명해보겠습니다. 파이썬은 당연히 0부터 접근을 합니다. 하지만 함수에서 인덱스를 받는 경우 1 부터 받기도 합니다. 왜냐하면 맥스스크립트에서는 인덱스가 1부터 시작하기 때문입니다.

 

import pymxs

print len(pymxs.runtime.meditmaterials)
print pymxs.runtime.meditmaterials[0]

mat = pymxs.runtime.PhysicalMaterial()
pymxs.runtime.setMeditMaterial(1, mat) # 이부분!! 1입니다

print len(pymxs.runtime.meditmaterials)
print pymxs.runtime.meditmaterials[0]

Keyword Arguments

맥스스크립트에서 키워드랑 같이 인자를 자주넘긴다고 합니다. 파이썬에서는 그냥 기존에 알고있던대로 사용하면 됩니다. 

 

# maxscript
bm = Bitmap 320 240 color:white
render to:bm
display bm

# python
bm = pymxs.runtime.Bitmap(320,240,color=pymxs.runtime.white)
pymxs.runtime.render(to=bm)
pymxs.runtime.display(bm

Equality vs Identity

t 와 t2 가 같은 객체가 아니니깐 false 가 뜹니다. 하지만 값은 같습니다.

 

from pymxs import runtime as mxs

t = mxs.teapot(name='my teapot')
t2 = mxs.getNodeByName('my teapot')
print t is t2 # this is false
print t == t2 # this is true
print 'The IDs are different: ', id(t), id(t2)

Printing to the Listener with pymxs.print_()

프린트할때 pymxs.print_() 가 좋다고 합니다.

근데 string 만 찍을수 있는 것 같아서 그냥 print 쓰면 될것 같습니다.

 

pymxs.print_('Hello\n')
pymxs.print_('Error\n', True)

 print "Hello, {}".format("World!") # 이렇게 써야지