Accessing Home directory of ArcMap using ArcPy?Losing printer settings when saving copy of mxd from...
Ramanujan's radical and how we define an infinite nested radical
Does changing "sa" password require a SQL restart (in mixed mode)?
Is opening a file faster than reading variable content?
Will linear voltage regulator step up current?
How do I handle a blinded enemy which wants to attack someone it's sure is there?
Could Comets or Meteors be used to Combat Global Warming?
Why is Shelob considered evil?
Relation between roots and coefficients - manipulation of identities
Does the kobold player race feature, Pack Tactics, give ranged attacks advantage?
Why Third 'Reich'? Why is 'reich' not translated when 'third' is? What is the English synonym of reich?
Is Apex Sometimes Case Sensitive?
Found a major flaw in paper from home university – to which I would like to return
Current measurement op-amp calculation
How can changes in personality/values of a person who turned into a vampire be explained?
How does the income of your target audience matter for logo design?
Identical projects by students at two different colleges: still plagiarism?
How do I write a maintainable, fast, compile-time bit-mask in C++?
Short story where Earth is given a racist governor who likes species of a certain color
Have any astronauts or cosmonauts died in space?
How to write painful torture scenes without being over-the-top
Can you wish for more wishes from an Efreeti bound to service via an Efreeti Bottle?
What does the expression "Happy is as happy does" mean?
Coloring in a multirow
How can I differentiate duration vs starting time
Accessing Home directory of ArcMap using ArcPy?
Losing printer settings when saving copy of mxd from ArcPy?Using arcpy from the command line on ArcGIS Linux Server 10.1Arcpy ListFeatureClasses in same workspace differs when run from ArcMap VS IDLEGetting ArcPy to work with Anaconda?Using Arcpy to Update Data Source Does Not Update Related Tablesarcpy export data view to jpeg: label size changesSetting ArcMap data frame extent with ArcPy?Getting different results using intersect with ArcPy vs ArcMapMoving MXD to different folder without breaking links using ArcPy?Using ListTables when accessing File Geodatabase gives ArcPy IOError?
I want to access to a directory and set that as a arcpy.env.workspace in my Python Script Tool. However, this workspace depends on users so I cannot just use my own folders.
Is there a way to access Home directory (where .mxd file is saved) in arcpy?
I tried retrieving the directory from os.getcwd but that refers to "c:windowssystem32" where ArcMap is accessing.
arcpy python-2.7 workspace
add a comment |
I want to access to a directory and set that as a arcpy.env.workspace in my Python Script Tool. However, this workspace depends on users so I cannot just use my own folders.
Is there a way to access Home directory (where .mxd file is saved) in arcpy?
I tried retrieving the directory from os.getcwd but that refers to "c:windowssystem32" where ArcMap is accessing.
arcpy python-2.7 workspace
1
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago
add a comment |
I want to access to a directory and set that as a arcpy.env.workspace in my Python Script Tool. However, this workspace depends on users so I cannot just use my own folders.
Is there a way to access Home directory (where .mxd file is saved) in arcpy?
I tried retrieving the directory from os.getcwd but that refers to "c:windowssystem32" where ArcMap is accessing.
arcpy python-2.7 workspace
I want to access to a directory and set that as a arcpy.env.workspace in my Python Script Tool. However, this workspace depends on users so I cannot just use my own folders.
Is there a way to access Home directory (where .mxd file is saved) in arcpy?
I tried retrieving the directory from os.getcwd but that refers to "c:windowssystem32" where ArcMap is accessing.
arcpy python-2.7 workspace
arcpy python-2.7 workspace
edited 50 mins ago
PolyGeo♦
53.5k1780240
53.5k1780240
asked 8 hours ago
TimTim
155
155
1
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago
add a comment |
1
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago
1
1
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved.
Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('CURRENT').filePath ) is the folder that the current MXD is saved in. Be sure to import os before attempting to use it.
In ArcGIS Pro the object for the current document is arcpy.mp.ArcGISProject, from the examples, the syntax would be os.path.dirname( arcpy.mp.ArcGISProject("CURRENT").filePath ).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313003%2faccessing-home-directory-of-arcmap-using-arcpy%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved.
Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('CURRENT').filePath ) is the folder that the current MXD is saved in. Be sure to import os before attempting to use it.
In ArcGIS Pro the object for the current document is arcpy.mp.ArcGISProject, from the examples, the syntax would be os.path.dirname( arcpy.mp.ArcGISProject("CURRENT").filePath ).
add a comment |
To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved.
Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('CURRENT').filePath ) is the folder that the current MXD is saved in. Be sure to import os before attempting to use it.
In ArcGIS Pro the object for the current document is arcpy.mp.ArcGISProject, from the examples, the syntax would be os.path.dirname( arcpy.mp.ArcGISProject("CURRENT").filePath ).
add a comment |
To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved.
Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('CURRENT').filePath ) is the folder that the current MXD is saved in. Be sure to import os before attempting to use it.
In ArcGIS Pro the object for the current document is arcpy.mp.ArcGISProject, from the examples, the syntax would be os.path.dirname( arcpy.mp.ArcGISProject("CURRENT").filePath ).
To get the folder that the currently open MXD is in you can use arcpy.mapping.MapDocument('CURRENT').filePath, this returns '' (an empty string) if the MXD isn't saved and the full path to the current MXD if it is saved.
Using the os.path module you can find the folder the document is in with os.path.dirname, thus os.path.dirname( arcpy.mapping.MapDocument('CURRENT').filePath ) is the folder that the current MXD is saved in. Be sure to import os before attempting to use it.
In ArcGIS Pro the object for the current document is arcpy.mp.ArcGISProject, from the examples, the syntax would be os.path.dirname( arcpy.mp.ArcGISProject("CURRENT").filePath ).
answered 7 hours ago
Michael StimsonMichael Stimson
21.4k22360
21.4k22360
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313003%2faccessing-home-directory-of-arcmap-using-arcpy%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try os.environ.get('USERPROFILE') to get to C:Users<username> folder then append 'my documents' to get to the users' documents folder. Caveat: this only works on Microsoft Windows OS.
– Michael Stimson
8 hours ago
Thanks, but I think this won't work if the project file is saved on other disk drive. Or perhaps I can force the user to use it on C drive. I will also check what os module can do. I am thinking that if ArcMap can make that access there would be a way to do so in arcpy as well.
– Tim
8 hours ago
Are you trying to get to the path that the open MXD is saved in? That is arcpy.mapping.MapDocument('CURRENT').filePath for the MXD file and os.path.dirname(arcpy.mapping.MapDocument('CURRENT').filePath) for the folder the MXD is in (returns '' if the MXD isn't saved).There is only one home which should be in the path os.path.join(os.environ.get('USERPROFILE'),r'DocumentsArcGIS')
– Michael Stimson
8 hours ago
Thank you very much! That is what I am expected.
– Tim
8 hours ago