본문 바로가기

Code/cinema4d & 3dsmax

[c4dpython] GUI

GUI

 yes no dialog

 

rvalue = c4d.gui.QuestionDialog("Hello")

 

input dialog

 

name = c4d.gui.InputDialog("input:")

 

alert

 

c4d.gui.MessageDialog("This document has not been previously saved, please save it now.")

 

File Explorer (load)

이건 파일탐색기와 함께 파일이름 가져오기

 

import c4d

fn = c4d.storage.LoadDialog()
doc = c4d.documents.LoadDocument(fn.decode("utf8"))

 

file_name = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title='Please input .json file name', flags=c4d.FILESELECT_LOAD, def_path='D:\\')

 

Get file name using file explorer (save)

이건 파일탐색기를 이용하지만 파일이름을 입력 후 파일이름 가져오기 (밑에코드는 .txt가져오기)

 

fileName = c4d.storage.SaveDialog(type=c4d.FILESELECTTYPE_ANYTHING, title='Save warning txt: input txt file name', force_suffix='txt', def_path='D:\\', def_file='')

 

 

 

GeDialog example

import c4d
from c4d import gui
#Welcome to the world of Python

GROUP_ID1=1000
TEXTBOX=1001
BUTTON1=1002
BUTTON2=1003

class ExampleDlg(gui.GeDialog):
    
    def CreateLayout(self):
        #creat the layout of the dialog
        self.GroupBegin(GROUP_ID1, c4d.BFH_SCALEFIT, 3, 1)
        self.AddEditText(TEXTBOX, c4d.BFH_SCALEFIT)
        self.AddButton(BUTTON1, c4d.BFH_SCALE, name="MessadeDialog")
        self.AddButton(BUTTON2, c4d.BFH_SCALE, name="Close")
        self.GroupEnd()
        return True

    def InitValues(self):
        #initiate the gadgets with values
        self.SetString(TEXTBOX, "Hello World!")
        return True

    def Command(self, id, msg):
        #handle user input
        if id==BUTTON1:
            gui.MessageDialog(self.GetString(TEXTBOX))
        elif id==BUTTON2:
            self.Close()
        return True


dlg = ExampleDlg()
dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50)

참고 자료

maxon gui:

developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.gui/index.html

 

file explorer: 

developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.storage/index.html#c4d.storage