Using Python to Launch and Use IDEA
Forums
Hi, is it possible to use IDEA from Python without first opening IDEA? Is there some code I can add to be able to do this?
The code below works if I open IDEA before running the code. This is the error I get when running the below code: "Invalid database or the database hasn't been specified yet."
Thank you.
import win32com.client as win32ComClient
if __name__ == "__main__":
try:
resultDbName = "Sample-Employees-Extraction.IMD"
criteria = 'COUNTRY=="Mexico"'
idea = win32ComClient.Dispatch(dispatch="Idea.IdeaClient")
table = idea.OpenDatabase("Sample-Employees.IMD")
task = table.Extraction()
task.IncludeAllFields()
task.AddExtraction(resultDbName, "", criteria)
task.PerformTask(1, table.Count)
idea.OpenDatabase(resultDbName)
finally:
task = None
table = None
idea = None
Thank you for the reply, I
Thank you for the reply, I ended up using single quotes around the criteria and the line worked (I updated the original post as well). I am getting the "Invalid database or the database hasn't been specified yet." error when I try set my table variable to my database.
table = idea.OpenDatabase("Sample-Employees.IMD")
I made sure 'Sample-Employees.IMD' is available so I'm not sure what's the issue.
The script works perfectly if I first open IDEA. I'm wondering if I'm missing a step to initialize IDEA through Python.
Excuse me I overlooked the
There have been double quotes in the original post (I copied that line). Your problem seems to depend on the project path. As long as I tested IDEA always opens the last used project folder. For files in that folder only the filename is necessary. So, finally the best solution would be to use absolute paths to avoid such errors.
If you open IDEA first and
If you open IDEA first and run the code from the library IDEA's integrated Python version is used. Without starting IDEA first, you could try whether it works to run the code from PythonWin (http://ideascripting.com/forum/pythonwin-ide-and-gui-framework). That's the same Python version as delivered with IDEA. I've run my tests on it because I have no further Python interpreter installed on my system and it worked.
I'm not sure but it seems to
I'm not sure but it seems to be something to do with how quickly the script is executed. I am able to run the script line by line and it works, but if I just run the script (even with PythonWin) I get the "Invalid database or database hasn't been specified yet" error.
Yes it is possible to run
Yes it is possible to run Python code without opening IDEA. The only line I can see that seems not working is criteria = "COUNTRY=="Mexico"". You have to specify criteria = "COUNTRY==\"Mexico\"". If that doesn't help try run your script line by line.