회원 로그인
|
Python for Maya - 9. polysmooth 자동 설정 (format 변환)
기반으로 복습하는 차원에서 재정리한 것입니다.
Subdiv Proxy로 smooth 적용된 pCube들을 선택하는 code이다.
object을 선택하면서 Exponential Level의 값이 얼마가 적용되었는지도 출력해보자.
import maya.cmds as cmd sel_ = cmd.ls('pCu*', type='transform') my_sel = [] for obj_ in sel_: his_list = cmd.listHistory(obj_, lv=1) for his_ in his_list: if cmd.nodeType(his_) == 'polySmoothProxy': my_sel.append(obj_) print '%s smooth %s' % (obj_, cmd.getAttr('%s.exponentialLevel' % his_)) break cmd.select(my_sel) # pCube13 smooth 1 # # pCube14 smooth 1 # # pCube15 smooth 1 #
print '%s smooth %s' % (obj_, cmd.getAttr('%s.exponentialLevel' % his_))출력할 때 %s는 string 치환을 의미한다.
print 뒤에 두개의 %s에 obj_와 cmd.getAttr('%s.exponentialLevel' % his_)가 문자열로 치환되어 들어간다는 얘기다.
#간단한 예로.. str_ = 'Maya Python' print 'format : %s' % str_ # format : Maya Python #
#2개 일 때.. str_ = 'Maya' str2_ = 'Python' print 'format : %s %s' % (str_, str2_) # format : Maya Python #여기서 getAttr는 object의 속성 값을 구할 때 사용되는 mel이다.
이제 smooth 걸린 object의 Exponential Level 값을 설정하는 것을 해보겠다.
import maya.cmds as cmd sel_ = cmd.ls('pCu*', type='transform') my_sel = [] for obj_ in sel_: his_list = cmd.listHistory(obj_, lv=1) for his_ in his_list: if cmd.nodeType(his_) == 'polySmoothProxy': smooth_fac = cmd.getAttr('%s.exponentialLevel' % his_) print '%s smooth %s' % (obj_, smooth_fac) if smooth_fac < 2: cmd.setAttr('%s.exponentialLevel' % his_, 2) break # pCube13 smooth 1 # # pCube14 smooth 1 # # pCube15 smooth 1 # # pCube16 smooth 1 #중간에 code가 추가되어
if smooth_fac < 2: cmd.setAttr('%s.exponentialLevel' % his_, 2)object에 설정되어 있는 smooth_fac 값이 2보다 작으면 아래 setAttr로 Exponential Level을 2로 변경하는 것이다.
Exponential Level을 0로 변경해 보자.
import maya.cmds as cmd sel_ = cmd.ls('pCu*', type='transform') my_sel = [] for obj_ in sel_: his_list = cmd.listHistory(obj_, lv=1) for his_ in his_list: if cmd.nodeType(his_) == 'polySmoothProxy': smooth_fac = cmd.getAttr('%s.exponentialLevel' % his_) print '%s smooth %s' % (obj_, smooth_fac) if smooth_fac > 0: cmd.setAttr('%s.exponentialLevel' % his_, 0) break # pCube13 smooth 2 # # pCube14 smooth 2 # # pCube15 smooth 2 # # pCube16 smooth 2 #
if smooth_fac > 0: cmd.setAttr('%s.exponentialLevel' % his_, 0)당연히 현재 smooth_fac 값이 2이고 0보다 크기 때문에 아래 setAttr 명령어를 실행하여 Exponential Level을 0로 변경한 것이다.
지금까지 polySmoothProxy로 적용된 object를 찾아내어 Exponential Level 값을 변경하는 것이지만, mesh smooth로 적용된 object는 polySmoothFace로 찾아내면 된다.
즉, if cmd.nodeType(his_) == 'polySmoothProxy':를 if cmd.nodeType(his_) == 'polySmoothFace': 로 바꿔서 사용하면 된다.
───────────────────────────────────────────────────
source : http://cafe.naver.com/digitaldream/472 - 'Maya Python 시작하기' 9) polysmooth 자동 설정
- smoothObject_2008.mb (73.7KB) (0)
댓글 0개
| 엮인글 0개
466개(1/24페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
마야 뷰포트 네비게이션 팁 | 푸딩뱃살 | 43508 | 2020.04.06 17:22 | |
Maya 버전 별 Python 버전 | 푸딩뱃살 | 64751 | 2014.01.08 17:59 | |
464 | [Dev] Autodesk Maya Devkit 다운로드 | 푸딩뱃살 | 699 | 2023.01.28 14:28 |
463 | [Base] (해결 중) modules 환경설정 중 | 푸딩뱃살 | 641 | 2022.11.09 11:47 |
462 | [Script] pymel 딕셔너리형 사용 시 KeyError | 푸딩뱃살 | 856 | 2022.11.07 12:08 |
461 | [오류] Building Numpy for Maya Python 2.7.x | 푸딩뱃살 | 596 | 2022.10.23 14:38 |
460 | [Base] 뷰포트에서 조절자가 안 보일때 | 푸딩뱃살 | 779 | 2022.10.13 15:47 |
459 | [Rigging] mirror joints 사용 시 유의 사항 | 푸딩뱃살 | 794 | 2022.10.04 10:46 |
458 | [Script] 2022에서 enum34 모듈 설치 금지 | 푸딩뱃살 | 602 | 2022.08.17 18:08 |
457 | [Script] pymel 예제 | 푸딩뱃살 | 619 | 2022.07.05 19:20 |
456 | [Script] 인코드 / 디코드 - 2.7 한글 사용 | 푸딩뱃살 | 898 | 2022.03.08 17:52 |
455 | [Dev] ui 없이 mayapy로 자동화 | 푸딩뱃살 | 701 | 2022.02.17 13:56 |
454 | [Dev] mayapy로 ui파일 py로 | 푸딩뱃살 | 526 | 2022.02.15 18:20 |
453 | [오류] Error : MayaBonusTools | 푸딩뱃살 | 912 | 2022.01.21 17:52 |
452 | [오류] Error: ModuleNotFoundError | 푸딩뱃살 | 770 | 2022.01.21 16:24 |
451 | [Dev] mayapy | 푸딩뱃살 | 644 | 2022.01.19 20:08 |
450 | [Base] function selCom at 0x7f29c5c04aa0 | 푸딩뱃살 | 610 | 2022.01.19 17:24 |
449 | [Base] wireframe on shaded 단축키 만들기 | 푸딩뱃살 | 911 | 2022.01.04 10:55 |
448 | [오류] OpenCL Error | 푸딩뱃살 | 520 | 2021.12.28 01:40 |
447 | [Script] Easily Translate MEL Commands to Python | 푸딩뱃살 | 824 | 2021.12.02 11:22 |
446 | [Base] output window 띄우지 않기 | 푸딩뱃살 | 821 | 2021.11.24 21:44 |
445 | [Rigging] shapeEditorManager 삭제 안됨 | 푸딩뱃살 | 890 | 2021.11.12 23:30 |