SHARE
TWEET

[Substance Painter] P4 functions for Painter

deKaf Oct 22nd, 2019 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getInfo() {
  2.     var projectUrl = alg.project.url();
  3.     var filePath = projectUrl.slice(8);
  4.  
  5.     var checkoutput = alg.subprocess.check_output("p4 fstat " + filePath);
  6.     var test = checkoutput.split ("\n");
  7.  
  8.     var fileInfo = new Object();
  9.  
  10.     for (var i = 0; i < test.length; ++i) {
  11.         var temp = test[i].split(" ");
  12.         try {
  13.             fileInfo[temp[1]] =  temp[2].replace("\r", "");
  14.         } catch(e) {
  15.             //pass
  16.         }
  17.                    
  18. }
  19.  
  20.     return fileInfo
  21.  
  22. }
  23.  
  24. function statusColor() {
  25.     var check = getInfo()
  26.     var color;
  27.     if ((check.workRev == check.headRev) || (check.haveRev == check.headRev)) {
  28.         return color = "green";
  29.     } else {
  30.         return color = "red";
  31.     }
  32. }
  33.  
  34.  
  35. function addFile() {
  36.  
  37.     var projectUrl = alg.project.url();
  38.     var filePath = projectUrl.slice(8);
  39.  
  40.     alg.log.info ("Attempting to add file to default changelist...")
  41.     alg.subprocess.call("p4 add " + filePath);
  42.    
  43.     var checkChangeList = getChangeList();
  44.     if ( checkChangeList != "None" ) {
  45.    
  46.     alg.log.info("File has been checked out to default changelist:" + checkChangeList); }
  47.     else {
  48.         alg.log.info("File is not in any changelist... try again or add manually")
  49.     }
  50. }
  51.  
  52. function editFile() {
  53.    
  54.     alg.log.info("Opening file for edit...")
  55.  
  56.     var check = getInfo();
  57.     alg.log.info(check);
  58.  
  59.     if ( check.isMapped != undefined ) {
  60.  
  61.         alg.subprocess.check_output("p4 edit " + check.clientFile)
  62.         alg.log.info("File checked out to changelist: " + check.change)
  63.     }
  64.         else {
  65.             alg.log.info("File does not exist in depot")
  66.             addFile()
  67.         }
  68.  
  69. }
  70.  
  71. function getChangeList() {
  72.     var projectUrl = alg.project.url();
  73.     var filePath = projectUrl.slice(8);
  74.  
  75.     var check = getInfo();
  76.    
  77.     alg.log.info(check.headAction)
  78.     alg.log.info(check.headChange)
  79.  
  80.     if (check.headAction == 'edit') {
  81.  
  82.         if (check.headChange == "") {
  83.             return check.change;
  84.         }
  85.     }
  86.     else {
  87.         return undefined;
  88.     }
  89.  
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top