<?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: PYT: arcpy.mp.ArcGISProject(&amp;quot;CURRENT&amp;quot;) doesn't work on toolbox initialization? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1569871#M73384</link>
    <description>&lt;P&gt;Yeah, what I did was like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;globalvar1 = ""
globalvar2 = ""

def setglobals():
    code
    global globalvar1
    global globalvar2
    code 
    return 

class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        setglobals()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It didn't work if I called setglobals() during the pyt initialization, but instead I just call it during each tool's initialization and it's worked so far.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2024 18:14:42 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-12-18T18:14:42Z</dc:date>
    <item>
      <title>PYT: arcpy.mp.ArcGISProject("CURRENT") doesn't work on toolbox initialization?</title>
      <link>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1563069#M73252</link>
      <description>&lt;P&gt;I'm trying to set a global variable containing the current APRX version.&lt;/P&gt;&lt;PRE&gt;glblcurVer = arcpy.mp.ArcGISProject("CURRENT").documentVersion&lt;/PRE&gt;&lt;P&gt;This works great for the most part except it gives me an OS error if I call this as part of the toolbox initialization.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1732727928191.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/120497iAB77E9EBC4B1D3C9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1732727928191.png" alt="AlfredBaldenweck_0-1732727928191.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Does anyone have any ideas for how to make this work? It's a variable used in a majority of the tools in this toolbox, so I'd prefer to not have to re-create it for each tool.&lt;/P&gt;&lt;P&gt;EDIT: My temporary work around is to call a function to set the global variable on each tool's initialization, rather than on the PYT. It appears to work so far, but I'm still open to ideas, here.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 17:45:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1563069#M73252</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-11-27T17:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: PYT: arcpy.mp.ArcGISProject("CURRENT") doesn't work on toolbox initialization?</title>
      <link>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1569859#M73382</link>
      <description>&lt;P&gt;I have found it to be kind of dangerous to work with global variables in toolboxes because weird errors like this can happen. especially with the current workspace. what I have ended up doing as my standard is create a variable that contains that current path in execution step and just pass that into all my functions. there are probably better ways of doing things but it has stopped errors related to environment from occurring so I'm happy.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 17:47:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1569859#M73382</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2024-12-18T17:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: PYT: arcpy.mp.ArcGISProject("CURRENT") doesn't work on toolbox initialization?</title>
      <link>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1569871#M73384</link>
      <description>&lt;P&gt;Yeah, what I did was like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;globalvar1 = ""
globalvar2 = ""

def setglobals():
    code
    global globalvar1
    global globalvar2
    code 
    return 

class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        setglobals()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It didn't work if I called setglobals() during the pyt initialization, but instead I just call it during each tool's initialization and it's worked so far.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 18:14:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pyt-arcpy-mp-arcgisproject-quot-current-quot-doesn/m-p/1569871#M73384</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-12-18T18:14:42Z</dc:date>
    </item>
  </channel>
</rss>

