Anybody have ever ran into something like that&
When I run my custom python toolbox, the feature class created in output is not permanent.
1. The toolbox contains a few import from custom modules, classes etc....
2. The toolbox work perfectly, no error displayed (try, Catch Error etc..)
So here's what's happening:
- I can see the Feature Class that I just created in the output File Geodatabase (ex: in arcCatalog) and it's also added a layer in the TOC and I can do whatever I want with it (ex: export, run it another toolbox etc...)
- It also has a valid source
But:
- if a quit arcGIS, it won't be there anymore when re-open
- if a save the mxd (hit the save button) it will still be there
- if I save the mxd using arpy.mapping it doesn't stay
So at the end The Feature class is deleted - gone forever if I don't save the mxd with the "save button"
Strange isn't it?
Run the tool again. In your Table of Contents, click on the button at the top to list contents by source (normally the second button). Look for your new feature and note the source path.
If the data is not saved in the database you are working on the feature is either being created “in-memory”, scratch workspace or in your default GDB depending upon which version of ArcGIS you are using. Since the data persists if you save your MXD, which only saves the reference to the data, I would guess it is one of the later possibilities. You may need to modify your Python script to include setting the arcpy.env.workspace as part of your code prior to outputting the new feature class. General use of this setting are noted below but will be dependent upon your custom code.
# Get the current workspace
current_Workspace = arcpy.env.workspace
# Set the workspace environment to local file geodatabase
arcpy.env.workspace = "C:/data/base.gdb"
#set to SDE file
arcpy.env.workspace = r"c:\data\base.sde"
If you find the data is being saved in the database you are working on, simply add it back into your MXD using the Add-data button and navigate to the path shown in the TOC next time you need the data. The MXD only stores a reference to the data not the data itself. The data is stored in shapefiles, GDBs, enterprise databases, etc. that are added to a MXD for display.
Hi Lance Cole, thanks for the advises, all of those parameters are being taken care of..(arcpy.env.workspace etc..)
I uploaded a short video to show you what is going on...I actually never experienced something like that before, I've done many python toolbox before, but this is the first one that does this kind of behavior.
Maybe it's because my main ascript imports many external modules?
If I run my script from from pyscripter it works just fine and the FeatureClass created doesn't disappear.
Thanks for your help but I dont see anything that could fix this, I'm gonna work on a turn-around for this situation. Like running a 2nd tool that saves the mxd of something like that...
Regards
Here's the youttube link to the video in case it didn't work...
https://www.youtube.com/watch?v=khgbjFG7_rs&feature=youtu.be