Hi All,
I'm currently attempting to develop an addin that creates a KML from a layer within arcmap, and then opens that KML. All seems to be going well except that every time the tool runs it crashes arcmap. I am aware that this is because i am using the "os.startfile()" command. What possible workaround can i use to get this file to open at the end of my script.
Thanks,
Ben
*Not a python expert by any means
Solved! Go to Solution.
Jason Schriener at ESRI got this work around for me.
Add this def:
def run_in_other_thread(function): #conflicts w/ os.startfile will crash arcmap. this is a workaround
# functool.wraps will copy over the docstring and some other metadata
# from the original function
@functools.wraps(function)
def fn_(*args, **kwargs):
thread = threading.Thread(target=function, args=args, kwargs=kwargs)
thread.start()
thread.join()
return fn_
Call it like this:
startfile = run_in_other_thread(os.startfile)
startfile(theFilePath)
Do you want to open the KML in your current MXD in ArcMap? Or using an outside program like Google Earth?
Todd,
Google Earth, the file actually opens when my addin is run, it just crashes arcmap in the process of doing so.
Thanks,
Ben
Ben,
Thanks for more info. If you're using Windows, os.startfile() shouldn't be giving you any issues, and like you said, it starts Google Earth fine (if kml/kmz is associated with that program within windows as the default program). Is there anything else in your code after the os.startfile() is called?
Jason Schriener at ESRI got this work around for me.
Add this def:
def run_in_other_thread(function): #conflicts w/ os.startfile will crash arcmap. this is a workaround
# functool.wraps will copy over the docstring and some other metadata
# from the original function
@functools.wraps(function)
def fn_(*args, **kwargs):
thread = threading.Thread(target=function, args=args, kwargs=kwargs)
thread.start()
thread.join()
return fn_
Call it like this:
startfile = run_in_other_thread(os.startfile)
startfile(theFilePath)
Thanks Kevin, worked like a charm.
I actually came across the thread with this information while researching the problem and it ended up that i was just calling it wrong.
For all others running into this error in the future this seems to be the workaround.