#--------------------------------------------------------------------------------------------------- # Script create by Semidieu, aka Basil Gass # # You may use this script for everything you wish, # except selling THIS python script. # Last update: 26 march 2007 #--------------------------------------------------------------------------------------------------- import poser import fnmatch import os #----------------------------------------------------------------------------- # This is ockham's GetCurrentRuntime routine, modified by duckmango # Edited by Semidieu to suit my needs... #----------------------------------------------------------------------------- def PoserPrefPath(): if os.path.splitext(os.path.split(poser.AppLocation())[1])[0]=='PoserPro' or os.path.splitext(os.path.split(poser.AppLocation())[1])[0]=='Poser Pro': PFolder = 'Poser Pro' else: PFolder = 'Poser 7' if float(poser.Version()) < 7: prefs = os.path.join(os.path.split(poser.AppLocation())[0], "runtime", "prefs", "LibraryPrefs.xml") else: if os.name == "nt": env = os.environ["APPDATA"] prefs = os.path.join(env, PFolder, "LibraryPrefs.xml") else: env = os.path.expanduser('~') prefs = os.path.join(env, "Library", "Preferences", PFolder, "LibraryPrefs.xml") if os.path.exists(prefs): return prefs else: return "" def GetCurrentLibPath(): # USAGE: # (cur_Lib, all_Lib) = GetCurrentLibPath() # -> cur_Lib is a dictionnary giving the current folder. # -> KEYS:"POSE","FIGURE","LIGHT","CAMERA","HAND","FACE","HAIR","PROP","MATERIAL" RuntimePath = "" TheLibPath = "" pz2Path="" cr2Path="" lt2Path="" cm2Path="" hd2Path="" fc2Path="" hr2Path="" pp2Path="" mt5Path="" allLibraries=[] BasePath = os.path.split(poser.AppLocation())[0] # try to read the Library Prefs (work for Poser 5, 6 and 7) prefsPath = PoserPrefPath() fpPrefs = open(prefsPath,"rt") if not fpPrefs: raise "Prefs file not found." DesiredIndex = -1 # default if something wrong ActualIndex = -1 # default if something wrong PathPart = "" while 1: OneLine=fpPrefs.readline() if string.find(OneLine, '')!=-1:break # Assume Poser arranges the xml file in a totally fixed format, so that we will always encounter the curFolder line before the folder itself. QuoteParts = string.split(OneLine,'"') if string.count(OneLine,'curFolder='): # This line is like: # Split it by quote marks. The second element will give us number. DesiredIndex = int(QuoteParts[1]) elif (DesiredIndex >= 0) and string.count(OneLine,'index='): # This line is like: # Split it by quote marks. Element 1 will give us the path; # Element 3 will give us the number. ActualIndex = int(QuoteParts[3]) allLibraries.append(QuoteParts[1]) if DesiredIndex==ActualIndex: # This line is the one we want. PathPart = QuoteParts[1] #We'll make the Runtime into an absolute path if string.find(PathPart, 'Runtime')== 0 or string.find(PathPart, 'Downloads') == 0: PathPart = os.path.join(BasePath, PathPart) RuntimePath = os.path.normpath(PathPart) else: PathPart="" elif (PathPart != ""): # Current Runtime has been found. Now, get the character path if string.find(QuoteParts[0], 'libraryType') != -1: # Create a dictionnary to get all current libraries path... if (QuoteParts[1] == "1"):pz2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "2"):cr2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "3"):lt2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "4"):cm2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "5"):hd2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "6"):fc2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "7"):hr2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "8"):pp2Path = RuntimePath + os.sep + QuoteParts[3] + os.sep if (QuoteParts[1] == "9"):mt5Path = RuntimePath + os.sep + QuoteParts[3] + os.sep fpPrefs.close() TheLibPath = {"POSE": pz2Path, "FIGURE": cr2Path, "LIGHT": lt2Path, "CAMERA": cm2Path, "HAND": hd2Path, "FACE": fc2Path, "HAIR": hr2Path, "PROP": pp2Path, "MATERIAL": mt5Path, 'ROOT': RuntimePath} # DO A POST WORK ON THE FILE NAMES (removes the & value) for i in TheLibPath: if string.find(TheLibPath[i], '&')!=-1: TheLibPath[i]=TheLibPath[i].replace('&', '&') return TheLibPath def GenerateScrollXMLHeader(GenXML, title, TitleLength, x, y, pad, ScriptDir, filename): GenXML.write('\n') GenXML.write('\n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write('\n') GenXML.write(' \n') left = str(pad) top = str(pad + 9) bottom = str(y - pad - 20) right = str(x - pad) GenXML.write(' \n') l = str(- pad - 15) r = str(- pad - 5) rl = str(y - pad - 15) rr = str(y - pad - 5) t_num = pad + 20 b_num = t_num + 10 rt_num = t_num rb_num = b_num t = str(t_num) b = str(b_num) rt = str(rt_num) rb = str(rb_num) GenXML.write(' \n') t_num = b_num b_num = y - pad - 40 rt_num = rb_num rb_num = b_num t = str(t_num) b = str(b_num) rt = str(rt_num) rb = str(rb_num) GenXML.write(' \n') t_num = b_num b_num = t_num + 10 rt_num = rb_num rb_num = b_num t = str(t_num) b = str(b_num) rt = str(rt_num) rb = str(rb_num) GenXML.write(' \n') l = str(pad) t = str(pad + 20) r = str(-pad -5) #or only -5 b = str(y - pad - 20) rl = l rt = t rr = str(x -pad - 5) rb = b GenXML.write(' \n') def GenerateListChecks(labels, isCheck, title, titleLength, Width, Height, Pad, fileWOext): # labels is the list you wish to show; # isCheck if set to 1, the check boxes will be selected on load. # Title The dialog title # titleLength Create a rectangle, so the bounding box is partially hidden # Width The dialog width. It is not recommended to use low settings. # Height The dialog height. # Pad The padding. Usually, using Poser standarts: Pad = 40 # fileWOext the temporary filename for the dialog. Enter a valid filename WITHOUT extension ! #Get the python script path folder if float(poser.AppVersion().split(".")[0]) < 7: ScriptDir = os.path.split(poser.AppLocation())[0] + os.sep else: ScriptDir = os.path.split(poser.ScriptLocation())[0] + os.sep try: GenXML = open(ScriptDir + fileWOext + ".xml","w") #Write the header GenerateScrollXMLHeader(GenXML, title, titleLength, Width, Height, Pad, ScriptDir, fileWOext) #Generate the XML lines for each materials. n = 0 co_check = 10301 #Check positoin x1 = 10 x2 = x1 + 20 y1 = 10 y2 = y1 + 20 #Text position x5 = 40 x6 = 250 y5 = 14 y6 = y5 + 20 #Go to next line... GenXML.write('\n') for label in labels: #rename the map... GenXML.write(' \n') GenXML.write(' \n') n = n + 1 co_check = co_check + 1 y1 = y1 + 20 y2 = y2 + 20 y5 = y5 + 20 y6 = y6 + 20 #Write the footer GenXML.write(' \n') #Add various buttons: Max = Width - (2*Pad) #MUST CHANGE TO INTEGER !!! BtnSize = int((Max-20)/3) SA = [str(Pad), str(Pad + BtnSize)] UA = [str(Pad + BtnSize + 10), str(Pad + (BtnSize*2)+10)] IA = [str(Pad + (BtnSize*2)+20), str(Pad + (BtnSize*3)+20)] GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write(' \n') GenXML.write('\n') #Close XML file GenXML.close() #Create the dialog class. myDialog = open(ScriptDir + fileWOext + "GUI.py","w") myDialog.write('import poser\n') myDialog.write('def CheckDialog_GUI(labels):\n') myDialog.write(' class CheckDialogClass:\n') myDialog.write(' def __init__(self,labels):\n') myDialog.write(' xmlPath = r"' + os.path.join(ScriptDir, fileWOext + '.xml') + '"\n') myDialog.write(' #defines main dialog window\n') myDialog.write(' self.dlg = poser.Dialog(file=xmlPath, title="CheckDialogGUI.py", message = "", width=' + str(Width) + ', height=' + str(Height) + ')\n') myDialog.write(' \n') myDialog.write(' #Set the values\n') myDialog.write(' for label in labels:\n') myDialog.write(' try:\n') myDialog.write(' self.Labels.append([label, ' + str(isCheck) + '])\n') myDialog.write(' except:\n') myDialog.write(' self.Labels = [[label,' + str(isCheck) + ']]\n') n_num = 0 n = str(n_num) for label in labels: myDialog.write(' self.dlg.SetButtonValue(name="lab' + n + '_check", value=' + str(isCheck) + ')\n') myDialog.write(' self.dlg.AddButtonCallback(name="lab' + n + '_check", callback=self.lab' + n + '_checkCB)\n') myDialog.write(' self.dlg.AddButtonCallback(name="lab' + n + '", callback=self.lab' + n + '_checkCB)\n') myDialog.write(' \n') n_num = n_num + 1 n = str(n_num) myDialog.write(' self.dlg.AddButtonCallback(name="SelectAll", callback=self.SelectAllCB)\n') myDialog.write(' self.dlg.AddButtonCallback(name="UnselectAll", callback=self.UnselectAllCB)\n') myDialog.write(' self.dlg.AddButtonCallback(name="InvertAll", callback=self.InvertAllCB)\n') n_num = 0 n = str(n_num) ret = "" for label in labels: myDialog.write(' def lab' + n + '_checkCB(self, CB):\n') myDialog.write(' if self.Labels[' + n + '][1] == 0:\n') myDialog.write(' self.dlg.SetButtonValue(name="lab' + n + '_check", value=1)\n') myDialog.write(' self.Labels[' + n + '][1] = 1\n') myDialog.write(' else:\n') myDialog.write(' self.dlg.SetButtonValue(name="lab' + n + '_check", value=0)\n') myDialog.write(' self.Labels[' + n + '][1] = 0\n') n_num = n_num + 1 n = str(n_num) myDialog.write(' def SelectAllCB(self, CB): \n') myDialog.write(' k = 0\n') myDialog.write(' for chk in self.Labels:\n') myDialog.write(' if chk[1] == 0:\n') myDialog.write(' self.Labels[k][1] = 1\n') myDialog.write(' self.dlg.SetButtonValue(name="lab\" + str(k) + \"_check", value = 1)\n') myDialog.write(' k = k + 1\n') myDialog.write(' def UnselectAllCB(self, CB): \n') myDialog.write(' k = 0\n') myDialog.write(' for chk in self.Labels:\n') myDialog.write(' if chk[1] == 1:\n') myDialog.write(' self.Labels[k][1] = 0\n') myDialog.write(' self.dlg.SetButtonValue(name="lab\" + str(k) + \"_check", value = 0)\n') myDialog.write(' k = k + 1\n') myDialog.write(' def InvertAllCB(self, CB): \n') myDialog.write(' k = 0\n') myDialog.write(' for chk in self.Labels:\n') myDialog.write(' if chk[1] == 0:\n') myDialog.write(' self.Labels[k][1] = 1\n') myDialog.write(' self.dlg.SetButtonValue(name="lab\" + str(k) + \"_check", value = 1)\n') myDialog.write(' else:\n') myDialog.write(' self.Labels[k][1] = 0\n') myDialog.write(' self.dlg.SetButtonValue(name="lab\" + str(k) + \"_check", value = 0)\n') myDialog.write(' k = k + 1\n') myDialog.write(' \n') myDialog.write(' def rLabels(self):\n') myDialog.write(' return(self.Labels)\n') myDialog.write(' def Show(self):\n') myDialog.write(' return(self.dlg.Show())\n') myDialog.write(' \n') myDialog.write(' dialog = CheckDialogClass(labels)\n') myDialog.write(' return(dialog.Show(), dialog.rLabels())\n') myDialog.write('\n') myDialog.close() except: print "Check Dialog cannot work !" try: GenXML.close() except: pass try: myDialog.close() except: pass #Launch the newly create python file. #Import the python file. Labels = [] try: if float(poser.AppVersion().split(".")[0]) < 7: ScriptDir = os.path.split(poser.AppLocation())[0] + os.sep else: ScriptDir = os.path.split(poser.ScriptLocation())[0] + os.sep poser.ExecFile(ScriptDir + "CheckDialogGUI.py") (sh, Labels) = CheckDialog_GUI(labels) #Try to delete the temporary files: try: #Delete the py and xml file. os.remove(ScriptDir + fileWOext + ".xml") os.remove(ScriptDir + fileWOext + "GUI.py") except: pass return (sh, Labels) except: print "error with the material manager" return (0, Labels) #--------------------------------------------------------------------------------------------------- # Get the Poser scene object... #--------------------------------------------------------------------------------------------------- scene = poser.Scene() #--------------------------------------------------------------------------------------------------- # Get the current FIGURE folder #--------------------------------------------------------------------------------------------------- LibPaths = GetCurrentLibPath() CurrentLibPath = LibPaths["FIGURE"] #Get the current selected figure. try: myFig = poser.Scene().CurrentFigure() myFigOK = 1 except: poser.DialogSimple.MessageBox("No figure selected. Please select the one where the clothes must be conformed to !") myFigOK = 0 if myFigOK == 1: #--------------------------------------------------------------------------------------------------- # Create the list of character in the current figure folder #--------------------------------------------------------------------------------------------------- oFig = [] for file in os.listdir(CurrentLibPath): if fnmatch.fnmatch(file, "*.cr2") or fnmatch.fnmatch(file, "*.crz"): oFig.append(file) if oFig != []: #Load the Check dialog. (show, SelectedFIG) = GenerateListChecks(oFig, 1, "Conform to " + myFig.Name(), 200, 300, 500, 40, "CheckDialog") if show: #Load all figures.... for fig in SelectedFIG: if fig[1] == 1: try: cr2Path = os.path.join(CurrentLibPath, fig[0]) if os.path.exists(cr2Path): #Load the file scene.LoadLibraryFigure(cr2Path) newFig = poser.Scene().CurrentFigure() #Conform the new figure newFig.ConformTo(myFig) # Reselect the base figure poser.Scene().SelectFigure(myFig) else: print "File not found" except: print "Problem loading " + fig[1]