Guest User

Untitled

a guest
Feb 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. class populateAttributes(object):
  2. """Implementation for addin_addin.populateAttributes_button (Button)"""
  3. def __init__(self):
  4. self.enabled = True
  5. self.checked = False
  6. def onClick(self):
  7. try:
  8. relPath = os.path.dirname(__file__)
  9. toolboxPath = os.path.join(relPath,"IncidentToolbox.pyt")
  10.  
  11. pythonaddins.GPToolDialog(toolboxPath, "populateReqAttributes")
  12.  
  13. except SystemExit:
  14. pass
  15. except:
  16. traceback.print_exc()
  17. pythonaddins.MessageBox("Somethings gone horribly wrong, sorry.", "Populate Attributes")
  18.  
  19. relPath = os.path.dirname(__file__)
  20. iniPath = os.path.join(relPath,"incidentTools.ini")
  21.  
  22. def getParameterInfo(self):
  23. """Define parameter definitions"""
  24.  
  25. default_incidentName = None
  26. default_irwinid = None
  27. default_unitID = None
  28. default_localIncidentID = None
  29. default_gacc = None
  30. default_imtName = None
  31. default_contactName = None
  32. default_contactEmail = None
  33. default_contactPhone = None
  34.  
  35. config = ConfigParser.SafeConfigParser()
  36.  
  37. try:
  38. default_incidentName = config.get("incidentAttributes","incidentName")
  39. default_irwinid = config.get("incidentAttributes","irwinid")
  40. default_unitID = config.get("incidentAttributes","unitID")
  41. default_localIncidentID = config.get("incidentAttributes","localIncidentID")
  42. default_gacc = config.get("incidentAttributes","gacc")
  43. default_imtName = config.get("incidentAttributes","imtName")
  44. default_contactName = config.get("incidentAttributes","contactName")
  45. default_contactEmail = config.get("incidentAttributes","contactEmail")
  46. default_contactPhone = config.get("incidentAttributes","contactPhone")
  47. print "defaults set from in memory"
  48.  
  49. except:
  50. if os.path.exists(iniPath):
  51. config.read(iniPath)
  52.  
  53. if "incidentAttributes" in config.sections():
  54. try:
  55. default_incidentName = config.get("incidentAttributes","incidentName")
  56. default_irwinid = config.get("incidentAttributes","irwinid")
  57. default_unitID = config.get("incidentAttributes","unitID")
  58. default_localIncidentID = config.get("incidentAttributes","localIncidentID")
  59. default_gacc = config.get("incidentAttributes","gacc")
  60. default_imtName = config.get("incidentAttributes","imtName")
  61. default_contactName = config.get("incidentAttributes","contactName")
  62. default_contactEmail = config.get("incidentAttributes","contactEmail")
  63. default_contactPhone = config.get("incidentAttributes","contactPhone")
  64. print "defaults set from file"
  65. except:
  66. print "default value missing"
  67.  
  68.  
  69. # IncidentName
  70. param0 = arcpy.Parameter(
  71. displayName="Incident Name",
  72. name="incidentName",
  73. datatype="GPString",
  74. parameterType="Required",
  75. direction="Input")
  76. if default_incidentName:
  77. param0.value = default_incidentName
  78.  
  79. # IRWINID
  80. param1 = arcpy.Parameter(
  81. displayName="IRWINID",
  82. name="irwinid",
  83. datatype="GPString",
  84. parameterType="Required",
  85. direction="Input")
  86. if default_irwinid:
  87. param1.value = default_irwinid
  88.  
  89. # UnitID
  90. param2 = arcpy.Parameter(
  91. displayName="Unit ID",
  92. name="unitID",
  93. datatype="GPString",
  94. parameterType="Required",
  95. direction="Input")
  96. if default_unitID:
  97. param2.value = default_unitID
  98.  
  99. # LocalIncidentID
  100. param3 = arcpy.Parameter(
  101. displayName="Local Incident ID",
  102. name="localIncidentID",
  103. datatype="GPString",
  104. parameterType="Required",
  105. direction="Input")
  106. if default_localIncidentID:
  107. param3.value = default_localIncidentID
  108.  
  109. # GACC
  110. param4 = arcpy.Parameter(
  111. displayName="GACC",
  112. name="gacc",
  113. datatype="GPString",
  114. parameterType="Required",
  115. direction="Input")
  116. if default_gacc:
  117. param4.value = default_gacc
  118.  
  119. # IMTName
  120. param5 = arcpy.Parameter(
  121. displayName="IMT Name",
  122. name="imtName",
  123. datatype="GPString",
  124. parameterType="Required",
  125. direction="Input")
  126. if default_imtName:
  127. param5.value = default_imtName
  128.  
  129. # ContactName
  130. param6 = arcpy.Parameter(
  131. displayName="Contact Name",
  132. name="contactName",
  133. datatype="GPString",
  134. parameterType="Required",
  135. direction="Input")
  136. if default_contactName:
  137. param6.value = default_contactName
  138.  
  139. # ContactEmail
  140. param7 = arcpy.Parameter(
  141. displayName="Contact Email",
  142. name="contactEmail",
  143. datatype="GPString",
  144. parameterType="Required",
  145. direction="Input")
  146. if default_contactEmail:
  147. param7.value = default_contactEmail
  148.  
  149. # ContactPhone
  150. param8 = arcpy.Parameter(
  151. displayName="Contact Phone",
  152. name="contactPhone",
  153. datatype="GPString",
  154. parameterType="Required",
  155. direction="Input")
  156. if default_contactPhone:
  157. param8.value = default_contactPhone
  158.  
  159. params = [param0, param1, param2, param3, param4, param5, param6, param7, param8]
  160. return params
  161.  
  162. def writeParameters(parameters):
  163. #gets array of parameters
  164. fil = fopen('parms.txt','w')
  165.  
  166. #then loop and write
  167. for parm in parameters:
  168. fil.write(str(parm) +'n')
  169.  
  170. #dont forget to close up that file behind you
  171. fil.close()
  172.  
  173. def readParameters():
  174. with open('parms.txt') as fil:
  175. content = fil.readlines()
  176. return content
Add Comment
Please, Sign In to add comment