<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 7, 2011, at 1:07 PM, Mateusz Dobrychłop wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello,<div><br></div><div>I'm trying to write my own Chimera extension. First of all, I'd like to thank you for providing so much useful information and so many examples on your site, it's extremely helpful.</div> <div><br></div><div>But there's one problem that might be a serious issue once I try to share this extension with other people. I don't know why, every time I need the extension to write a file, I have to determine an exact path to the localisation where I want the file to be placed. Otherwise it always creates the file on the desktop (I use Windows 7).</div> <div><br></div><div>Is there any way to make Chimera create new files in the extension's directory without giving it an accurate path?</div></blockquote><br></div><div>Hi Mateusz,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>I think the answer is no, you cannot get Chimera to write new files in the extension's directory without giving an "accurate" (full) path. That said, it isn't that hard to generate the full path, since the Python module attribute __file__ gives the full path to that module source file. So to write the file "x.y" in the extension's directory you would:</div><div><br></div><div>import os.path</div><div>dir, fname = os.path.split(__file__)</div><div>out = open(os.path.join(dir, "x.y"), "w")</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>This raises the question of <i>why</i> you are writing a file into the extension directory. Is it a temporary file of some sort? If so, Chimera has a function (OpenSave.osTemporaryFile) for generating a temporary file path that will be removed when Chimera quits. So using that to open a temporary file ending in ".y" would be:</div><div><br></div><div>from OpenSave import osTemporaryFile</div><div>tmpPath = osTemporaryFile(suffix=".y")</div><div>out = open(tmpPath, "w")</div><div><br></div><div>--Eric</div><div><br></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>Eric Pettersen</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> <span class="Apple-converted-space"> </span></span>UCSF Computer Graphics Lab</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="5" style="font: 16.0px Helvetica"><span class="Apple-converted-space"> </span><a href="http://www.cgl.ucsf.edu">http://www.cgl.ucsf.edu</a></font></p><br class="Apple-interchange-newline"></div></span> </div><br></body></html>