Unfortunately before moving away from the input box ArcGIS is placing a workspace in front of the inputted name. I am just going to go with a warning for users and move on. Your code helped me figure out how to do this, so thanks! if self.params[0].value and self.params[6].altered: outFC = str(self.params[6].value) self.params[6].clearMessage import os if os.path.dirname(outFC)!= str(self.params[0].value): self.params[6].setWarningMessage("Output location not within project folder!")
if self.params[0].value and self.params[6].altered: outFC = str(self.params[6].value) self.params[6].clearMessage import os if os.path.dirname(outFC)!= str(self.params[0].value): self.params[6].setWarningMessage("Output location not within project folder!")
def updateMessages(self): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" if self.params[0].value and self.params[6].value: import os inWS = os.path.dirname(str(self.params[0].value)) outWS = os.path.dirname(str(self.params[6].value)) if inWS != outWS: self.params[6].setWarningMessage( "Output will be written to a different workspace than input!") return
So the user sets their project workspace and then sets the name of the output location however since I am using a data type of Raster Dataset with an output direction, the parameter wants to use the current workspace set by the tool as the default location if a user just inputs a name. (1) Additionally the browser dialog which opens points to the last workspace a dataset was written to which can also be different. (2) I just want them both to point to the users selected workspace by default.
# the first parameter [0] is the (input) workspace parameter # to make things easy for the user, set this to default to the current workspace # in the parameter properties dialog (or in the code if pyt toolbox) # the second [1] is your output dataset. def updateParameters(self): if self.params[0].value and self.params[1].altered: outFC = str(self.params[1].value) import os if os.path.dirname(outFC) == "" self.params[1].value = os.path.join(self.params[0].value,outFC)
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.