Maxscript 디렉토리 관리하기

 

 

Maxscript에는 디렉토리를 관리해주는 함수가 있습니다.

SetDir, GetDir..

이함 수를 통해 미리 정해둔 경로를 받을 수 있어 상당히 편리합니다.

(PC마다 3dsmax 설치 경로가 달라도 알아서 대응해주니 좋아요~)

 

GetDir #maxroot

결과 : "C:\Program Files\Autodesk\3ds Max 2011\"

이런식으로 말이죠.

 

그런데 아쉬운 점이 정해진 타입만을 처리 해줍니다.

내가 임의로 만들어 사용하기가 힘든데요.

그래서 디렉토리 관리 기능이 필요 합니다.

 

 

--------------------------------------------------------------------------------------------------------
--  HGDirClass
--------------------------------------------------------------------------------------------------------
struct HGDirClass
(
 -- Private ============================================================================
 Private
 --====================================================================================
 m_dirFile = (getDir #maxroot) + "DirectoryList.ini",
 m_section = "Directory List",
 
 
 ----------------------------------------------------------------
 -- OnCreate
 ----------------------------------------------------------------
 fn OnCreate =
 (
  dirs = getINISetting m_dirFile m_section -- 없으면 빈 배열을 받는다.

  dirs = sort dirs
  for i = 1 to dirs.count do
   dirs[i] = dirs[i] as name -- Name이 String 타입보다 사용하기 편하고 Max 기능과 통일성을 위해 Name으로 설정

  
  return dirs
 ),
 
 
 -- Public =============================================================================
 Public
 --====================================================================================
 ----------------------------------------------------------------
 -- typeList
 ----------------------------------------------------------------
 typeList = OnCreate(), -- 생성시 사용가능한 목록을 보여주기 위해
 
 
 ----------------------------------------------------------------
 -- SetDir
 ----------------------------------------------------------------
 fn SetDir type path =
 (
  if isKindOf type Name then
  (
   setINISetting m_dirFile m_section type path
   typeList = OnCreate()
   return ok
  )
  else
   return false
 ),
 
 
 ----------------------------------------------------------------
 -- GetDir
 ----------------------------------------------------------------
 fn GetDir type =
 (
  if isKindOf type Name then
   getINISetting m_dirFile m_section type
  else
   return false
 ),
 
 
 ----------------------------------------------------------------
 -- DeleteDir
 ----------------------------------------------------------------
 fn DeleteDir type =
 (
  if isKindOf type Name then
  (
   delINISetting m_dirFile m_section type
   typeList = OnCreate()
   return ok
  )
  else
   return false
 )
)

 

 

이를 사용해 경로를 저장하고 읽어보겠습니다.
 -- 디렉토리 저장하기 --
 fn SaveDir =
 (
  -- Dir 설정 --
  HGDir = HGDirClass()
  HGDir.SetDir #ExternalTools (GetDir #maxroot + "ExternalTools\\") -- 내가 원하는 경로를 추가
  HGDir.SetDir #Scripts (GetDir #Scripts + "\\HwangGoon\\")
  HGDir.SetDir #Dll (HGDir.GetDir #Scripts + "Dll\\")
  HGDir.SetDir #Sample (HGDir.GetDir #Scripts + "Sample\\")
  HGDir.SetDir #Save (HGDir.GetDir #Scripts + "Save\\")
  HGDir.SetDir #Temp (HGDir.GetDir #Scripts + "Temp\\")
  HGDir.SetDir #Startup (GetDir #Scripts + "\\Startup\\HwangGoon\\")
 )
 SaveDir()

 

 -- 디렉토리 불러오기 --

HGDir = HGDirClass() -- 이렇게 받으면 typeList를 일단 받아 볼 수 있다(리스너에서 확인해 보자)

HGDir.GetDir #ExternalTools

결과 : "C:\Program Files\Autodesk\3ds Max 2011\ExternalTools\"

 

매번 디렉토리를 풀패스로 쓰기 보다는 이런식으로 디렉토리를 관리해주는 것이 좋습니다.

이렇게 하면 다른 스크립트에서도 경로를 사용 할 수도 있으니 더 활용성이 좋아지겠죠.

 

Posted by Hwanggoon
,