Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. class SetLayer(object):
  2. """Implementation for leetScripts_addin.button2 (Button)"""
  3. def __init__(self):
  4. self.enabled = True
  5. self.checked = False
  6. def onClick(self):
  7. self.a = pythonaddins.GetSelectedCatalogWindowPath()
  8. self.a = self.a.encode('mbcs')
  9. print self.a
  10. self.b = os.path.split((self.a))
  11. self.c = self.b[0]
  12. self.d = os.path.split(self.c)
  13. self.e = (self.b[1]) #feature class
  14. self.f = (self.d[1]) #feature dataset
  15. self.g = (self.d[0]) #workspace
  16. print "Feature class: %r" % self.e
  17. print "Feature dataset: %r" % self.f
  18. print "Workspace: %r" % self.g
  19. connProp = arcpy.Describe(self.g).connectionProperties
  20. self.h = connProp.instance.split(":", 2)
  21. self.k = self.h[2].encode('mbcs') #instanceX
  22. self.i = connProp.database.encode('mbcs') #databaseX
  23. print "Instance is %r" % self.k
  24. print "Database is %r" % self.i
  25. print "Availible Versions:"
  26. self.List = arcpy.da.ListVersions(self.g)
  27. self.nameList = []
  28. for version in self.List:
  29. self.nameList.append(version.name)
  30.  
  31. print self.nameList
  32. print "Tool finished"
  33. pass
  34.  
  35. #working on editing this to provide dropdown
  36. class setVersion(object):
  37. """Implementation for leetScripts_addin.combobox2 (ComboBox)"""
  38. def __init__(self):
  39. self.editable = True
  40. self.enabled = True
  41. self.width = 'WWWWWW'*3
  42. self.dropdownWidth = 'WWWWW'*3
  43. def onEnter(self):
  44. self.items = button2.nameList
  45. def onSelChange(self, selection):
  46. #self.items.append(button2.nameList)
  47. self.version = selection#change this
  48. print self.version
  49. pass
  50.  
  51. if sde != -1 and desc.isVersioned:
  52.  
  53. #Check to see if this connection file exists
  54. path = r"U:tempStuffactualName.sde"
  55. if not os.path.isfile(path):
  56. #Creates connection file if it doesn't already exist
  57. os.makedirs(r"U:tempStuff")
  58. outFolderPath = r"U:tempStuff"
  59. outName = r"actualName.sde"
  60. databasePlatform = "SQL_Server"
  61. instance = button2.k
  62. database = button2.i
  63. username = "username"
  64. password = "password"
  65. version = combobox2.version
  66. #Make sure you change between OPERATING_SYSTEM_AUTH and DATABASE_AUTH
  67. arcpy.CreateDatabaseConnection_management(outFolderPath, outName,
  68. databasePlatform,
  69. instance,
  70. 'OPERATING_SYSTEM_AUTH',
  71. username, password,
  72. 'DO_NOT_SAVE_USERNAME',
  73. database,
  74. '','TRANSACTIONAL',
  75. version,'')
  76.  
  77. workspace = r"U:tempStuffactualName.sde"#change to current workspace
  78. fc = os.path.join(workspace, featureDataset, fcName)
  79. print workspace
  80. print "Feature class is %r" % fc
  81. #Start editing
  82. print "initiating editing"
  83. arcpy.ChangeVersion_management(fcName, "TRANSACTIONAL",
  84. combobox2.version, '')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement