Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Setting workspace Q

$
0
0
I have the following script in a tool it runs great in a personal gdb, but when i trying to change the work space to SQL Server Express databases i get the error RuntimeError: cannot open workspace. I have a script with the work space as r"Database Servers\DSD15_SQLEXPRESS.gds\Tony_Two_way" and it works fine. What am i getting the error?

Code:

Traceback (most recent call last):
  File "C:\Users\talmeida\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{BB229966-100D-4482-A3FE-B298BD262597}\AddPoints_addin.py", line 18, in onMouseDownMap
    edit = arcpy.da.Editor(workspace)
RuntimeError: cannot open workspace

Tool script i am working with
Code:

import arcpy
import pythonaddins
import os
from arcpy import env

class Add_points(object):
    """Implementation for AddPoints_addin.Add_points (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3 # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
    def onMouseDownMap(self, x, y, button, shift):

        fc = "TonyTwoWay.DBO.CCAP_TEST"
        workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\Tony_Two_way"
        arcpy.env.overwriteOutput = True

        # Start an edit session. Must provide the worksapce.
        edit = arcpy.da.Editor(workspace)

        # Edit session is started without an undo/redo stack for versioned data
        #  (for second argument, use False for unversioned data)
        edit.startEditing(True)

        # Start an edit operation
        edit.startOperation()

        list = []
        with arcpy.da.SearchCursor(fc, ["AddressID"]) as cursor:
            for row in cursor:
                list.append(int(row[0].strip("CC")))       
        del cursor

        list.sort()
        AddressID = list[-1] + 1
        AddressID = 'CC' + str(AddressID)

        row_values = [(x, y, (x, y), AddressID)]
        cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESSID"])

        for row in row_values:
            cursor.insertRow(row)
        del cursor

        arcpy.RefreshActiveView()
       
        # Stop the edit operation.
        edit.stopOperation()

        # Stop the edit session and save the changes
        edit.stopEditing(True)       
        pass


Viewing all articles
Browse latest Browse all 2485

Trending Articles