Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self.x = pythonaddins.GetSelectedTOCLayerOrDataFrame() #Sets FC on different button
- fc = str(button2.x)
- cursor = arcpy.da.InsertCursor( fc, ["SHAPE@"])
- array = arcpy.Array(vertices)
- simpleBuilding = arcpy.Polygon(array)
- cursor.insertRow([simpleBuilding])
- One or more layers failed to draw:
- FDO error 0: [Failed to label layer
- databaseVersionDBO for class Defaut.}
- The requested operation is invalid on a closed state
- [database]
- in onClick
- edit = arcpy.da.Editor(workspace)
- RuntimeError: cannot open workspace
- import arcpy
- import pythonaddins
- import os
- import math
- import sys
- class setCenterpoint(object):
- """Implementation for leetScripts_addin.tool (Tool)"""
- def __init__(self):
- self.enabled = True
- self.cursor = 3
- #selects a point on the map
- def onMouseDownMap(self, x, y, button, shift):
- print "onMouseDowMap executing"
- setCenterpoint.enabled = True
- self.x = x
- self.y = y
- print "Selected point is at %r, %r" % (self.x, self.y)
- pass
- return self.x
- return self.y
- class setArea(object):
- """Implementation for leetScripts_addin.combobox (ComboBox)"""
- def __init__(self):
- self.editable = True
- self.enabled = True
- #self.dropdownWidth = ''
- self.width = 'WWWWWWWWW'
- #Takes user input Area and returns half the side length of the square
- def onEditChange(self,text) :
- squareFeet = text
- self.buffDist = (math.sqrt(float(squareFeet))/2)
- print "Square size: %r ft^2 Buffer Distance: %r ft^2" % (squareFeet,
- self.buffDist)
- return self.buffDist
- pass
- #This is supposed to be how you select the feature class, but right now
- #it doesn't do anything for debugging purposes.
- class SeltLayer(object):
- """Implementation for leetScripts_addin.button2 (Button)"""
- def __init__(self):
- self.enabled = True
- self.checked = False
- def onClick(self):
- #need the input as a string not a class layer.
- self.x = pythonaddins.GetSelectedTOCLayerOrDataFrame()
- print "Selected filepath is: %r" % self.x.dataSource
- print "filepath is %r type" % type(self.x.dataSource)
- pass
- class buildingTool(object):
- """Implementation for leetScripts_addin.button (Button)"""
- def __init__(self):
- self.enabled = True
- self.checked = False
- def onClick(self):
- print "building tool button is executing"
- #Variables for Creating the polygon
- xCoordinate = float(tool.x)
- yCoordinate = float(tool.y)
- bob = float(combobox.buffDist)
- #fc = str(button2.x.dataSource) was used to get featureclass info
- fc = r"realfulldatabasepathrealnextpartrealpolygonlayer"
- outFolderPath = r"U:tempStuff"
- outName = r"actualName"
- databasePlatform = "SQL_Server"
- instance = "realinstance"
- username = "myusername"
- password = "authenticpassword"
- version = "myVersionName"
- arcpy.CreateDatabaseConnection_management(outFolderPath, outName,
- databasePlatform,
- instance,
- 'DATABASE_AUTH',
- username, password,
- 'DO_NOT_SAVE_USERNAME',
- 'instancenameagain',
- '','TRANSACTIONAL',
- version,)
- print "Centroid of buidling:(%r,%r) Side length: %r" % (xCoordinate,
- yCoordinate,
- bob)
- def doStuff():
- #Calculates and creates an array of vertex points, opens an
- #insert cursor, creates a polygon using the arra, and inserts
- #building into the appropriate database. This works fine in file
- #geodatabase
- vertices = []
- vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate + bob)))
- vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate - bob)))
- vertices.append(arcpy.Point((xCoordinate - bob), (yCoordinate - bob)))
- vertices.append(arcpy.Point((xCoordinate - bob), (yCoordinate + bob)))
- vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate + bob)))
- cursor = arcpy.da.InsertCursor( fc, ["SHAPE@"])
- array = arcpy.Array(vertices)
- simpleBuilding = arcpy.Polygon(array)
- cursor.insertRow([simpleBuilding])
- del cursor
- print "Building should be drawn"
- desc = arcpy.Describe(fc)
- print "%r" % desc
- sde = desc.catalogPath.find('.sde')
- #Checks for .sde versions code provided by BenSNadler.
- #arcpy.Describe().isVersioned needs dataset input
- if sde != -1 and desc.isVersioned:
- workspace = desc.catalogPath#problem opening workspace
- print workspace
- #Start editing
- print "initiating editing"
- edit = arcpy.da.Editor(workspace)
- edit.startEditing(True, True)
- edit.startOperation()
- #soon to be function's name
- doStuff()
- print "made it past function call."
- #Stop/save edits
- edit.stopOperation()
- print "Stopping editing"
- edit.stopEditing(True)
- #if no versions then the function runs without using the
- #connection
- else:
- print "made it to else statemenet"
- doStuff()
- print "made it past function call"
- desc = arcpy.Describe(fc)
- sde = desc.catalogPath.find('.sde') #if SDE this will return a value
- #If in sde AND is Versioned, use editor start/stop
- if sde != -1 and desc.isVersioned:
- #get the connection information
- workspace = desc.catalogPath
- #Start editing
- print "Initiating editing"
- edit = arcpy.da.Editor (workspace)
- edit.startEditing ()
- edit.startOperation()
- DO STUFF
- #Stop/save edits
- edit.stopOperation()
- print "Stopping editing"
- edit.stopEditing("True")
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement