<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Script to in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316878#M24643</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried inserting the line for using a "d" to prefix the output feature dataset name in my script, the script did run, created some datasets and errored out at one of the dwg files, i am not able to figure out why it is not able to create the annotation for that file and why it is erroring out at that point.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script for it&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdb = r"C:\data\DGW2005.gdb"
arcpy.env.workspace = gdb
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "DGW2005.gdb")
reference_scale = "1500"
for file in glob.glob(r"N:\2005_dwg\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error displayed&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Traceback (most recent call last):&amp;nbsp; &lt;BR /&gt; File "C:\data\Scripts\cadconversRight", line 13, in &amp;lt;module&amp;gt;&amp;nbsp; &lt;BR /&gt; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&amp;nbsp; &lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1084, in CADToGeodatabase&amp;nbsp; &lt;BR /&gt; raise e&amp;nbsp; &lt;BR /&gt;ExecuteError: ERROR 000278: 1 error(s) have been detected for layer 050101C01. Errors are described in file GLC:\Users\IEGBUL~1\AppData\Local\Temp\GL050101C011.log.log in your temp directory.&amp;nbsp; &lt;BR /&gt;ERROR 000016: 1 annotation(s) rejected&amp;nbsp; &lt;BR /&gt;Failed to execute (CADToGeodatabase).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; and here is the extent it was able to execute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16990[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried the looping script but it came up with an error, It appears the loop is not functioning well, i guess i am missing something because it is not even creating the GDBs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdbName = "d{0}.gdb".format(year) # d1990.gdb
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"N:\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdbName
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb")
reference_scale = "1500"
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"N:\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb&amp;nbsp; 
for file in glob.glob(r"N:\{0}_dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdbName, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error i got&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Traceback (most recent call last):&amp;nbsp; &lt;BR /&gt; File "C:/Users/iegbulefu/Documents/myscripts/cadconvers5", line 6, in &amp;lt;module&amp;gt;&amp;nbsp; &lt;BR /&gt; gdbName = "d{0}.gdb".format(year) # d1990.gdb&amp;nbsp; &lt;BR /&gt;NameError: name 'year' is not defined&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BLOCKQUOTE&gt;curtvprice;224453 wrote:&lt;BR /&gt;The validation is stripping that leading number because gdb object names should not start with a number. Here's a tweak that will preserve those full names be prefixing a "d" to the output feature dataset name:&lt;/BLOCKQUOTE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(&lt;SPAN style="color:&amp;quot;#008800&amp;quot;;"&gt;"d" + &lt;/SPAN&gt;os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Creating a geodatabase for each folder should be pretty straightforward. Wrap a for loop around what you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"c:\data\cadfiles\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdb
...

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:04:17 GMT</pubDate>
    <dc:creator>IreneEgbulefu</dc:creator>
    <dc:date>2021-12-11T15:04:17Z</dc:date>
    <item>
      <title>Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316869#M24634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi everyone, &lt;BR /&gt;I need a script that can can&amp;nbsp; iterate through&amp;nbsp; folders that contains all my CAD files and authomatically convert each CAD file to a feadture dataset and store them in a specified geodatabase.&lt;BR /&gt;&lt;BR /&gt;I already created a script that is able to pick up a specified CAD file rum the given folder and converts it to a geodatabase with feature dataset, but i need to iterate through the folder to convert all the other files to feature database&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
... from arcpy import env
... env.workspace = "C:/data1"
... input_cad_dataset = "C:/CADdata/94a88W01.dwg"
... output_gdb_path = "c:/data/cadfile.gdb"
... output_dataset_name = "cad9488"
... reference_scale = "500"
... spatial_reference = "NAD_1983_10TM115"
... arcpy.CADToGeodatabase_conversion(input_cad_dataset, output_gdb_path, output_dataset_name, reference_scale)
... reference_scale = "2500"
... arcpy.CADToGeodatabase_conversion(input_cad_dataset, output_gdb_path, output_dataset_name, reference_scale)
... &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:03:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316869#M24634</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316870#M24635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Irene,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can accomplish this using the 'glob' module.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, glob

GDB = r"C:\temp\Python\CAD\CAD_DATA.gdb"

reference_scale = "500"

# Find all DWG files
for file in glob.glob(r"C:\temp\python\CAD\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Convert all DWG files to GDB feature classes
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, GDB, file.split("\\")[-1][0:-4], reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'file.split("\\")[-1][0:-4]' will split the path of the CAD file for each backslash (\), use the last value found by specifying [-1] (which would be the CAD file name), and then strip the '.DWG' from the file name by specifying [0:-4].&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:03:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316870#M24635</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T15:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316871#M24636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The 'file.split("\\")[-1][0:-4]' will split the path of the CAD file for each backslash (\), use the last value found by specifying [-1] (which would be the CAD file name), and then strip the '.DWG' from the file name by specifying [0:-4].&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm more of a fan of using the os.path function for this sort of thing. For one thing it works with forward-slash path delimiters too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; p = r"e:\work\test.dbf"
&amp;gt;&amp;gt;&amp;gt; os.path.basename(p)
'test.dbf'
&amp;gt;&amp;gt;&amp;gt; os.path.splitext(p)
('e:\\work\\test', '.dbf')
&amp;gt;&amp;gt;&amp;gt; os.path.splitext(p)[1]
'.dbf'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316871#M24636</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316872#M24637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the script. I tried the script, It was able to create the gdb and supposedly dataset but i am not able to see them on ArcCatalog.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what my script looks like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, glob
 gdb = r"C:\data\cadfile2.gdb"
 reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
 arcpy.CADToGeodatabase_conversion(file, gdb, file.split("\\")[-1][0:-4], reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the result&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\91-400'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\91036c01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a02c01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a03w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a05w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a14w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a15w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a25w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a26w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a26w02'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a54w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a70w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a81w01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a82c01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a88C01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94a88W01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94b12v01'&amp;gt;&lt;BR /&gt;&amp;lt;Result 'C:\\data\\cadfile2.gdb\\94b13c01'&amp;gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to believe that the 94*** are the feature datasets that should be seen within the geodatabase named "cadfiles2"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Irene,&lt;BR /&gt;&lt;BR /&gt;You can accomplish this using the 'glob' module.&amp;nbsp; Ex:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, glob

GDB = r"C:\temp\Python\CAD\CAD_DATA.gdb"

reference_scale = "500"

# Find all DWG files
for file in glob.glob(r"C:\temp\python\CAD\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Convert all DWG files to GDB feature classes
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, GDB, file.split("\\")[-1][0:-4], reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;The 'file.split("\\")[-1][0:-4]' will split the path of the CAD file for each backslash (\), use the last value found by specifying [-1] (which would be the CAD file name), and then strip the '.DWG' from the file name by specifying [0:-4].&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316872#M24637</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316873#M24638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's an approach that is more robust:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import glob
import os

gdb = r"C:\data\cadfile2.gdb"
arcpy.env.workspace = gdb 
reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # the following line pulls out the "base name" (file.dwg), strips the .dwg extension,
&amp;nbsp;&amp;nbsp;&amp;nbsp; # and then ensures the name is a valid dataset name for the current workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also - look out for this gotcha in the tool reference:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00120000001z000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Feature class names must be unique for the entire geodatabase or the tool will fail.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One more thing, you may want to prefix your feature dataset names with a letter - object names that start with a number can cause ArcGIS operations (especially queries) to fail.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316873#M24638</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316874#M24639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi curtvprice&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried runing this script, it is able to run but with an error stating that it is unable to create the anotation feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In answer to your comments. All my input CAD data are uniquely identified and since i desire to have the feature dataset assume the same name as the CAD data files, I believe that "Feature class names must be unique for the entire geodatabase or the tool will fail" This issue would be averted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for the second issue of having a&amp;nbsp; prefix my feature dataset names with a letter - object names that start with a number can cause ArcGIS operations (especially queries) to fail; is it possible to do this within the script and have it automatically implemented as the feature dataset is being created from the CAD files, My reason is that I have over 60 CAD files that i need to convert to feature dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code and the error i got when i ran it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for helping!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import glob
import os
gdb = r"C:\data\cadfile.gdb"
arcpy.env.workspace = gdb
reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "C:/data/Scripts/cadconvers", line 9, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;BR /&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1084, in CADToGeodatabase&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;BR /&gt;ExecuteError: ERROR 999999: Error executing function.&lt;BR /&gt;ERROR 000021: Failed to create the output annotation feature class&lt;BR /&gt;Failed to execute (CADToGeodatabase).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Here's an approach that is more robust:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import glob
import os

gdb = r"C:\data\cadfile2.gdb"
arcpy.env.workspace = gdb 
reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # the following line pulls out the "base name" (file.dwg), strips the .dwg extension,
&amp;nbsp;&amp;nbsp;&amp;nbsp; # and then ensures the name is a valid dataset name for the current workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Also - look out for this gotcha in the tool reference:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00120000001z000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Feature class names must be unique for the entire geodatabase or the tool will fail.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;One more thing, you may want to prefix your feature dataset names with a letter - object names that start with a number can cause ArcGIS operations (especially queries) to fail.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316874#M24639</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316875#M24640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;it is able to run but with an error stating that it is unable to create the anotation feature class.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's hard to tell without more details, but my guess is that the feature class names are not unique. All object names within a gdb (tables, feature classes, feature datasets [even those inside of a feature dataset], relationship classes, everything) must be globally unique within the gdb workspace. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your .dwg files have feature classes that are named the same, for example: 94b12v01.dwg\Anno and 94b13c01.dwg\Anno) the only solution is to convert each .dwg to unique gdbs or use Feature Class to Feature Class to copy feature classes one at a time with unique names. (This may require an inner loop and more logic, perhaps the use of the arcpy ListFeatureClasses method.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, make sure any feature datasets are deleted from the output gdb after failed attempts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As for setting up the names with a character prefix, you could prefix an "f" to each feature datasetname like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;outDS = "f" + outDS&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 17:22:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316875#M24640</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-08-13T17:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316876#M24641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Curt!&lt;BR /&gt;&lt;BR /&gt;I think youre right. I deleted all that i had previously in the geodatabase and ran the script again and it worked perfectly well. I also tried to insert a line to create the geodatabase within the script and it also worked very well; but my problem now is that I need to customize the feature datasets such that all the feature datasets will have the same fullname as the CADfiles becos we have a naming convention for all our files for ease of recorgnition.&lt;BR /&gt;&lt;BR /&gt;Secondly, I have over 30 different folders created according to the years the data were acquired, so Im wondering if it is possible to use just one script that can&amp;nbsp; create 30 different geodatabases (probably by iteration) and for each database, the feature datasets will be arranged according to the data sets in the specific CAD folder for that year.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what my script looks like &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdb = r"C:\data\DGW2007.gdb"
arcpy.env.workspace = gdb
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "DGW2007.gdb")
reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the output on ArcCatalog &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16901[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; and here is what my inputACDfiles look like&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16904[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is what my CADfolders look like (I have data acquired from 1990 to 2012)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16905[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It's hard to tell without more details, but my guess is that the feature class names are not unique. All object names within a gdb (tables, feature classes, feature datasets [even those inside of a feature dataset], relationship classes, everything) must be globally unique within the gdb workspace. &lt;BR /&gt;&lt;BR /&gt;If your .dwg files have feature classes that are named the same, for example: 94b12v01.dwg\Anno and 94b13c01.dwg\Anno) the only solution is to convert each .dwg to unique gdbs or use Feature Class to Feature Class to copy feature classes one at a time with unique names. (This may require an inner loop and more logic, perhaps the use of the arcpy ListFeatureClasses method.)&lt;BR /&gt;&lt;BR /&gt;Also, make sure any feature datasets are deleted from the output gdb after failed attempts.&lt;BR /&gt;&lt;BR /&gt;As for setting up the names with a character prefix, you could prefix an "f" to each feature datasetname like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outDS = "f" + outDS&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316876#M24641</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316877#M24642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; but my problem now is that I need to customize the feature datasets such that all the feature datasets will have the same fullname as the CADfiles becos we have a naming convention for all our files for ease of recorgnition.&amp;nbsp; &lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The validation is stripping that leading number because gdb object names should not start with a number. Here's a tweak that will preserve those full names be prefixing a "d" to the output feature dataset name:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(&lt;SPAN style="color:&amp;quot;#008800&amp;quot;;"&gt;"d" + &lt;/SPAN&gt;os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Creating a geodatabase for each folder should be pretty straightforward. Wrap a for loop around what you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"c:\data\cadfiles\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdb
...

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316877#M24642</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316878#M24643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried inserting the line for using a "d" to prefix the output feature dataset name in my script, the script did run, created some datasets and errored out at one of the dwg files, i am not able to figure out why it is not able to create the annotation for that file and why it is erroring out at that point.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script for it&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdb = r"C:\data\DGW2005.gdb"
arcpy.env.workspace = gdb
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "DGW2005.gdb")
reference_scale = "1500"
for file in glob.glob(r"N:\2005_dwg\*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error displayed&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Traceback (most recent call last):&amp;nbsp; &lt;BR /&gt; File "C:\data\Scripts\cadconversRight", line 13, in &amp;lt;module&amp;gt;&amp;nbsp; &lt;BR /&gt; arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale)&amp;nbsp; &lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1084, in CADToGeodatabase&amp;nbsp; &lt;BR /&gt; raise e&amp;nbsp; &lt;BR /&gt;ExecuteError: ERROR 000278: 1 error(s) have been detected for layer 050101C01. Errors are described in file GLC:\Users\IEGBUL~1\AppData\Local\Temp\GL050101C011.log.log in your temp directory.&amp;nbsp; &lt;BR /&gt;ERROR 000016: 1 annotation(s) rejected&amp;nbsp; &lt;BR /&gt;Failed to execute (CADToGeodatabase).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; and here is the extent it was able to execute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]16990[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried the looping script but it came up with an error, It appears the loop is not functioning well, i guess i am missing something because it is not even creating the GDBs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdbName = "d{0}.gdb".format(year) # d1990.gdb
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"N:\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdbName
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb")
reference_scale = "1500"
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"N:\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb&amp;nbsp; 
for file in glob.glob(r"N:\{0}_dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdbName, outDS, reference_scale)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error i got&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Traceback (most recent call last):&amp;nbsp; &lt;BR /&gt; File "C:/Users/iegbulefu/Documents/myscripts/cadconvers5", line 6, in &amp;lt;module&amp;gt;&amp;nbsp; &lt;BR /&gt; gdbName = "d{0}.gdb".format(year) # d1990.gdb&amp;nbsp; &lt;BR /&gt;NameError: name 'year' is not defined&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BLOCKQUOTE&gt;curtvprice;224453 wrote:&lt;BR /&gt;The validation is stripping that leading number because gdb object names should not start with a number. Here's a tweak that will preserve those full names be prefixing a "d" to the output feature dataset name:&lt;/BLOCKQUOTE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext(&lt;SPAN style="color:&amp;quot;#008800&amp;quot;;"&gt;"d" + &lt;/SPAN&gt;os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Creating a geodatabase for each folder should be pretty straightforward. Wrap a for loop around what you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"c:\data\cadfiles\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdb
...

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316878#M24643</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316879#M24644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I tried inserting the line for using a&amp;nbsp; "d" to prefix&amp;nbsp; the output feature dataset name in my script, the script did&amp;nbsp; run, created some datasets and errored out at one of the dwg files, i am not able to figure out why it is not able to create the annotation for that file and why it is erroring out at that point.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Check the value of outDS you're getting with a print statement -- but also make sure your output GDB is entirely empty. &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;arcpy.env.overwriteOutput&amp;nbsp; = True&lt;/SPAN&gt;&lt;SPAN&gt; is a good idea too!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perhaps this syntax will work better for you:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outDS = arcpy.ValidateTableName("d" + os.path.splitext(os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;(regarding looping attempt) i guess i am missing something because it is not even creating the GDBs.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes - Look up the syntax on .format() in the python help. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to substitute that year into the gdb name using .format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;gdbName = "d{0}.gdb".format(year)
arcpy.CreateFileGDB_management("C:/data",gdbName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316879#M24644</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T15:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316880#M24645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Curtiv,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been working on this script since yesterday and uptil this morning I have not been able to get it to populate the geodatabase with&amp;nbsp; datasets. I also observed that it is not picking information from the format() as supposed. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am actually having some difficulties on how best to set the format parameters because the parameters are supposed to be folders (subdirectories) within a directory and and each of them has a suffix at the end. Each time i insert the foldernme as it is within the format() parameter, the script does not recorgnise it and so it gives me a syntax error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please see how my folders are arranged. I have gone through a lot python format() function but couldnt find any that is similar to mine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17033[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script and the errors Im getting&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import arcpy
import glob
import os
# Set workspace and variables
gdbName = "d{0}.gdb".format(1990)
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"{0}.gdb".format(1990)# 1991_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdbName
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb")
reference_scale = "1500"
for year in range(1990,2005): # 1990-2004
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder = r"N:\{0}_dwg".format(1990) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format(year) # d1990.gdb&amp;nbsp; 
for file in glob.glob(r"N:\{0}_dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName("d" + os.path.splitext(os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This one just creates the geodatabase name d{0}.gdb (it does not substitute the 0 with the names specified in the format(), i dont understand why)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Check the value of outDS you're getting with a print statement -- but also make sure your output GDB is entirely empty. &lt;SPAN style="font-style:italic;"&gt;arcpy.env.overwriteOutput&amp;nbsp; = True&lt;/SPAN&gt; is a good idea too!&lt;BR /&gt;&lt;BR /&gt;Perhaps this syntax will work better for you:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outDS = arcpy.ValidateTableName("d" + os.path.splitext(os.path.basename(file))[0])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yes - Look up the syntax on .format() in the python help. &lt;BR /&gt;&lt;BR /&gt;You need to substitute that year into the gdb name using .format:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;gdbName = "d{0}.gdb".format(year)
arcpy.CreateFileGDB_management("C:/data",gdbName)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316880#M24645</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316881#M24646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;BR /&gt;This one just creates the geodatabase name d{0}.gdb (it does not substitute the 0 with the names specified in the format(), i dont understand why)&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This line in your code is wrong:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should be&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb"&lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;.format(year)&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and also should be inside the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/library/stdtypes.html#string-methods" rel="nofollow"&gt;Python 2.7 docs: string methods&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Aug 2012 19:27:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316881#M24646</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-08-17T19:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python Script to</title>
      <link>https://community.esri.com/t5/python-questions/python-script-to/m-p/316882#M24647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; This line in your code is wrong:&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb"&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;Should be&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb"&lt;SPAN style="color:&amp;quot;#0000FF&amp;quot;;"&gt;.format(year)&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;and also should be inside the loop.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;A href="http://docs.python.org/library/stdtypes.html#string-methods" rel="nofollow noopener noreferrer" target="_blank"&gt;Python 2.7 docs: string methods&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Curtis, It appears the script is not recorgnising the years as just foldernames within a director. When I run the script it simply picks up the year just before the last, e.g if i specifiy range(1990,2009) it will just create a gdb folder for 2008 and thats all, even when i just put one year (1998) in the parameter for the format it will just create the an empty gdb in the name 1998 without datasets in it&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It does not create and populate the gdb with feature datasets and it does not iterate through the folders in the directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please can you check my script to know where im not getting it right. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Import system modules
import arcpy
import glob
import os
# Set workspace and variables
for year in range(1990,2009): # 1990-2009
&amp;nbsp;&amp;nbsp;&amp;nbsp; inFolder =&amp;nbsp; r"c:\data\cadfiles\{0}_dwg".format(year) # 1990_dwg
&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbName = "d{0}.gdb".format (1990,2009) # d1990.gdb
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdbName&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "d{0}.gdb".format(year))
reference_scale = "1500"
for file in glob.glob(r"N:\{0}_dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CADToGeodatabase_conversion(file, gdbName, outDS, reference_scale)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:04:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-to/m-p/316882#M24647</guid>
      <dc:creator>IreneEgbulefu</dc:creator>
      <dc:date>2021-12-11T15:04:26Z</dc:date>
    </item>
  </channel>
</rss>

