CAD to File Geodatabase – Python script

In near feature I am going to work on the project where the CAD conversion to esri format will be required. The script below might be useful…

Syntax:

CADtoGeodatabase_conversion (input_cad_datasets, out_gdb_path, out_dataset_name, reference_scale, {spatial_reference})

input_cad_datasets [CAD drawing dataset,…] – The collection of CAD files to convert to geodatabase features. The input parameter will accept CAD data from multiple formats (DWG, DXF, and DGN) in one operation.

Workspace out_gdb_path – The ArcSDE, file, or personal geodatabase where the Output Feature Dataset will be created. The target geodatabase must already exist.

String out_dataset_name – The name of the feature dataset to be created.

Double reference_scale – Enter the scale to use as a reference for the annotation. This sets the scale to which all symbol and text sizes in the annotation will be made relative.

Spatial Reference spatial_reference – (Optional) The spatial reference of the output feature dataset. If you wish to control other aspects of the spatial reference (i.e., the xy, z, m domains, resolutions, tolerances), use the relevant environments.

Code sample:


#Name: CadtoGeodatabase.py
# Description: Create a feature dataset
# Author: ESRI
# Import system modules
import arcpy
from arcpy import env
# Set workspace
env.workspace = "C:/data"

# Set local variables
input_cad_dataset = "C:/data/City.DWG"
out_gdb_path = "C:/data/HabitatAnalysis.gdb"
out_dataset_name = "analysisresults"
reference_scale = "1000"
spatial_reference = "NAD_1983_StatePlane_California_VI_FIPS_0406_Feet"

# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "HabitatAnalysis.gdb")

# Execute CreateFeaturedataset
arcpy.CadToGeodatabase_conversion(input_cad_dataset, out_gdb_path, out_dataset_name, reference_scale)

References:
Source: ESRI Help
Mapping Specification for DWG/DXF (MSD)

 

Advertisements

Python – Define Workspace for SDE Connection

One of the possiblilities is to provide the full path to the sde connection file. You can check it creating the connection in ArcCatalog then right clicking and selecting Properties.


C:\Python26\ArcGIS10.0>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy
>>> arcpy.env.workspace="C:\Users\osedok\AppData\Roaming\ESRI\
Desktop10.0\Arc
Catalog\PABLO to TEST_SDE_SERVER.sde"
>>> dataset_list=arcpy.ListDatasets()
>>> for feature_dataset in dataset_list:
...     print feature_dataset
...
MASTERMAP.ITN_Network
PABLO.Administrative
PABLO.Default_Blank_Dataset
PABLO.Default_Dataset
PABLO.Development
>>>