Repository navigation
fail to create scad file directly from terminal #18
Description
Activity
Thanks for this. Would you agree that the root of the problem is that you can't use
scad_render_to_file()from the terminal? That's what it sounds like to me. I think I'd prefer to fix the problem inscad_render_to_file()instead of adding another potentially confusing method. I'll let you know how that goes, or if you supply a fix for that, I'd be grateful, too.ok, I could probably fix it in scad_render_to_file() but for a quick terminal adding an append command to file may be a good idea.
It's difficult to make a great code with a blindness erasing command line.So, I just committed something to allow use of
scad_render_to_file()from the terminal. It sounds like you would also like a way to append code to the scad file as you go. I'm not sure that's a very common use case, (meaning, I don't think people probably build SolidPython models that way very often) but I'm open to hearing why you think appending code would be an advantage.Here's how I write SolidPython code. I keep an editor window open with my SolidPython code in it, and at the end of the file I have a line that calls scad_render_to_file() on the object I've been building. Then whenever I run the code, the SCAD file is updated. At the same time I keep the SCAD file open in OpenSCAD.app with "Automatic reload and compile" checked. So as soon as I run my python code, the change in the model appears in OpenSCAD.app.
What's your workflow?
ok, thanks I was thinking about adding an excpt condition to resolve it.
So, I understand an append function is totaly useless with a source file edit but with a command line this function erase the file.
If you want use terminal there are some features to respect.
For a little modification you must rewrite the beginning.
If you want make a big file it's easier to proceed step by step.So I must use this modification in my version or I will rewrite an function each time using terminal to open file and append to it without erasing my previous coding.
- added a commit that references this issue
on Aug 26, 2014
Hi,
I've tried to create a scad file directly with python in terminal from "scad_render_to_file()" function but failed because there is no source file to read.
I suggest add this function to directly append code with python in terminal running :
def scad_render_append_to_file( scad_object, file_header='', filepath=''):
if filepath =='':
filepath = os.path.abspath('.') + "/solid.scad"
f = open( filepath,"a")
f.write( scad_render(scad_object, file_header) )
f.close()
Tested and it's working.
Thanks