<?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: Setting workspace dynamically as part of out path in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97470#M7563</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;oops, if you have a variable defined for your gdb, enter that.&amp;nbsp; Or, if explicitly naming it, you need quotes (because it is a string).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In other words 'NameError: name 'Prog_Assign' is not defined' means the interpeter thinks you're referencing a defined variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...so this is needed in the way you are using it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;out_path = os.path.join(arcpy.env.workspace, "Prog_Assign.gdb")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry 'bout that, not paying attention!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 21 Jul 2013 15:02:56 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2013-07-21T15:02:56Z</dc:date>
    <item>
      <title>Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97466#M7559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've successfully managed to set my workspace as a 'arcpy.GetParameterAsText(0)'. I then created a file GDB and I'm now trying to create a rasterdataset in this file GDB. The rasterdataset wants&amp;nbsp; an 'out_path' to be set. I tried what I have below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Create Raster Dataset
out_path = "Prog.gdb"
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "")
# Mosaic Rasters into a the Raster Dataset
inputs = arcpy.ListRasters("", "TIF")
# Set the target to the Raster Dataset that was already created
target = "R_Dataset"
# Run the Mosaic tool
arcpy.Mosaic_management (inputs, target, "LAST", "FIRST", "", "", "NONE", "0", "NONE")
# Set local variables
in_raster = "R_Dataset"
in_mask_data = "Study_area_extent"
#Extract by Mask
outExtractByMask = arcpy.sa.ExtractByMask (in_raster, in_mask_data)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;I want to know is there anyway for the original workspace to become part of the out_path when another user runs the code, so it would be something like 'Workspace + Prog.gdb".&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jul 2013 13:13:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97466#M7559</guid>
      <dc:creator>DonalCasey</dc:creator>
      <dc:date>2013-07-21T13:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97467#M7560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sure.&amp;nbsp; The out_path parameter for this tool can be a workspace or raster catalog...so to set this to your file gdb, typically with the way you've already set things up in your description (not apparent in your code snippet), do something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&amp;nbsp; #typically this statement is at the beginning of your script&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# then if you have a statement similar to this to set the workspace to a dir:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# ...you can follow up with this to 'append' the file gdb:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_path = os.path.join(arcpy.env.workspace, &amp;lt;your gdb&amp;gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or...if you set the workspace to an already existing gdb, then the out_path param in the tool would simply be the workspace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; I removed the misleading out_path parameter and replaced that with &amp;lt;your gdb&amp;gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I originally expressed that as out_path because that's the variable reference in your script snippet...but it isn't really a path so that's bad form.&amp;nbsp; Anyway, this should clear things up a bit.&amp;nbsp; Note that you can (and should) enforce the parameter var types allowed when you set up your script tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jul 2013 14:14:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97467#M7560</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-07-21T14:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97468#M7561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Sure. The out_path parameter for this tool can be a workspace or raster catalog...so to set this to your file gdb, typically with the way you've already set things up in your description (not apparent in your code snippet), do something like this:&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;import os #typically this statement is at the beginning of your script&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;# then if you have a statement similar to this to set the workspace to a dir:&amp;nbsp; &lt;BR /&gt;arcpy.env.workspace = arcpy.GetParameterAsText(0)&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;# ...you can follow up with this to 'append' the file gdb:&amp;nbsp; &lt;BR /&gt;out_path = os.path.join(arcpy.env.workspace, out_path)&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;Or...if you set the workspace to an already existing gdb, then the out_path param in the tool would simply be the workspace.&amp;nbsp; &lt;BR /&gt; &lt;BR /&gt;Hope that helps,&amp;nbsp; &lt;BR /&gt;Wayne&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Wayne, I tried the below based on your advice:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;out_path = os.path.join(arcpy.env.workspace, Prog_Assign.gdb)
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I get an error in the script tool stating: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;out_path = os.path.join(arcpy.env.workspace, Prog_Assign.gdb)&lt;BR /&gt;NameError: name 'Prog_Assign' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is my synthax perhaps messed up?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97468#M7561</guid>
      <dc:creator>DonalCasey</dc:creator>
      <dc:date>2021-12-11T06:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97469#M7562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sounds like either your gdb hasn't been created yet...or the name is wrong.&amp;nbsp; (Or the path to it is wrong.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure of your workflow - do you want to set the workspace to an existing gdb?&amp;nbsp; ...or create the gdb 'dynamically'?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Post your entire code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jul 2013 14:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97469#M7562</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-07-21T14:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97470#M7563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;oops, if you have a variable defined for your gdb, enter that.&amp;nbsp; Or, if explicitly naming it, you need quotes (because it is a string).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In other words 'NameError: name 'Prog_Assign' is not defined' means the interpeter thinks you're referencing a defined variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...so this is needed in the way you are using it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;out_path = os.path.join(arcpy.env.workspace, "Prog_Assign.gdb")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry 'bout that, not paying attention!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jul 2013 15:02:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97470#M7563</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-07-21T15:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Setting workspace dynamically as part of out path</title>
      <link>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97471#M7564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Sounds like either your gdb hasn't been created yet...or the name is wrong.&amp;nbsp; (Or the path to it is wrong.)&lt;BR /&gt;&lt;BR /&gt;Not sure of your workflow - do you want to set the workspace to an existing gdb?&amp;nbsp; ...or create the gdb 'dynamically'?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;EDIT:&amp;nbsp; Post your entire code.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for all your help so far, I want to set the workspace to the gdb that will be created at the start of the script and will have shps imported into it!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Jul 2013 15:43:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-workspace-dynamically-as-part-of-out-path/m-p/97471#M7564</guid>
      <dc:creator>DonalCasey</dc:creator>
      <dc:date>2013-07-21T15:43:56Z</dc:date>
    </item>
  </channel>
</rss>

