Calling other binaries/shell access

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling other binaries/shell access

Elmo Mäntynen
It has been suggested before, but it would make all sorts of stuff
possible to be able to call scripts from openscad code. Like for example
the generation of 2D text with every font that is available, or using
the QR-code generating script that is to be included in MCAD. Just a
simple call is enough, with some error reporting in case of failure. The
script would generate an .dxf or .stl in a known location, and then the
openscad code could import that and go from there. I could do the nice
API for these things, but I couldn't coax openscad to allow me to call
the scripts.

Attached is the diff with my hacking (against the latest svn!), for
inspiration, and a suggested API. I got it to compile, but no result
came from calling the scripts, without any errors.

Elmo

shell_access.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Whosawhatsis
I haven't looked at your code, but I think a logical syntax for this would be to use backquote-delimited command substitution. This would allow you to include a script that outputs scad code. Of course, there might also be syntax for including an STL/DXF that is generated at runtime, but I think the former would be more useful.

On Tuesday, January 18, 2011 at 3:06 AM, Elmo wrote:
It has been suggested before, but it would make all sorts of stuff
possible to be able to call scripts from openscad code. Like for example
the generation of 2D text with every font that is available, or using
the QR-code generating script that is to be included in MCAD. Just a
simple call is enough, with some error reporting in case of failure. The
script would generate an .dxf or .stl in a known location, and then the
openscad code could import that and go from there. I could do the nice
API for these things, but I couldn't coax openscad to allow me to call
the scripts.

Attached is the diff with my hacking (against the latest svn!), for
inspiration, and a suggested API. I got it to compile, but no result
came from calling the scripts, without any errors.

Elmo
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Attachments:
- shell_access.diff

Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Elmo Mäntynen
I forgot that one. Yes, the QR-code generating script actually outputs
scad code, and my suggested API would work with that: User code just
calls into the generated code. Of course it would need to have a known
api. And syntax errors reported by OpenSCAD would not be obfuscated as a
consiquence.

Elmo

On 01/18/2011 01:30 PM, Whosawhatsis wrote:

> I haven't looked at your code, but I think a logical syntax for this
> would be to use backquote-delimited command substitution. This would
> allow you to include a script that outputs scad code. Of course, there
> might also be syntax for including an STL/DXF that is generated at
> runtime, but I think the former would be more useful.
>
> On Tuesday, January 18, 2011 at 3:06 AM, Elmo wrote:
>> It has been suggested before, but it would make all sorts of stuff
>> possible to be able to call scripts from openscad code. Like for example
>> the generation of 2D text with every font that is available, or using
>> the QR-code generating script that is to be included in MCAD. Just a
>> simple call is enough, with some error reporting in case of failure. The
>> script would generate an .dxf or .stl in a known location, and then the
>> openscad code could import that and go from there. I could do the nice
>> API for these things, but I couldn't coax openscad to allow me to call
>> the scripts.
>>
>> Attached is the diff with my hacking (against the latest svn!), for
>> inspiration, and a suggested API. I got it to compile, but no result
>> came from calling the scripts, without any errors.
>>
>> Elmo
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email] <mailto:[hidden email]>
>> http://rocklinux.net/mailman/listinfo/openscad
>>
>> Attachments:
>> - shell_access.diff
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

kintel
Administrator
In reply to this post by Elmo Mäntynen
Elmo,

Thanks for your patch.
I'm uncertain how we should best deal with this for several reasons:
o OpenSCAD makes heavy use of caching. This should be taken into account.
o I would like a way to cancel rogue scripts.
o As already mentioned, syntax needs to be thought through

All this is best done after the upcoming release, when I can merge the refactored codebase into master.
We'll officially move to git as well. For now, you can fork from github and play from there:
https://github.com/openscad/openscad

 -Marius


Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Steven Dick
Another way to handle external scripts would be to use a makefile, and just include the generated code in the model...

myobject_export.gcode: myobject.stl
        x=`pwd`; cd $(skeinforgedir) ; ./skeinforge.py $$x/myobject.stl

myobject.stl: myobject-qcode.scad myobject.scad
        $(openscad) -s myobject.stl myobject.scad

myobject-qcode.scad: myobject-gcode.sh
        ./myobject-gcode.sh > myobject-gcode.scad


This would satisfy the caching problem...
Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Owen Taylor
In reply to this post by kintel
Just want to point out my patches that I posted last year in this context as well:

 http://rocklinux.net/pipermail/openscad/2010-August/000573.html

(Since the pipemail seems to have eaten the patches, I've stuck them at
http://fishsoup.net/misc/openscad/external-script/)

Those had pretty good caching integration, but no interruptibility. There's some comments in the code about what it would take to switch to QProcess instead of blocking the main loop.

- Owen

On Thu, Jan 20, 2011 at 11:39 PM, Marius Kintel <[hidden email]> wrote:
Elmo,

Thanks for your patch.
I'm uncertain how we should best deal with this for several reasons:
o OpenSCAD makes heavy use of caching. This should be taken into account.
o I would like a way to cancel rogue scripts.
o As already mentioned, syntax needs to be thought through

All this is best done after the upcoming release, when I can merge the refactored codebase into master.
We'll officially move to git as well. For now, you can fork from github and play from there:
https://github.com/openscad/openscad

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Elmo Mäntynen
In reply to this post by Steven Dick
Of course this works. I could even drive openscad from python, for which
MCAD has code, but it adds a layer of indirection that I would like to
avoid for the more simple cases. I would like to offer library code that
would be easily usable from the IDE by newbies.

On 01/21/2011 02:34 PM, Steven Dick wrote:

> Another way to handle external scripts would be to use a makefile, and
> just include the generated code in the model...
>
> myobject_export.gcode: myobject.stl
>          x=`pwd`; cd $(skeinforgedir) ; ./skeinforge.py $$x/myobject.stl
>
> myobject.stl: myobject-qcode.scad myobject.scad
>          $(openscad) -s myobject.stl myobject.scad
>
> myobject-qcode.scad: myobject-gcode.sh
>          ./myobject-gcode.sh > myobject-gcode.scad
>
>
> This would satisfy the caching problem...
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Calling other binaries/shell access

Elmo Mäntynen
In reply to this post by Owen Taylor
This is a lot more code than what I tried :)

This API is great for the most parts, but I would like the option of not
passing the implicit arguments, since most unixy tools would barf at the
sight of them :). I would like to be able to call any cmd tool without
having to make an external script (even though I can, it would still be
a major hindrance).

Elmo

On 01/21/2011 09:54 PM, Owen Taylor wrote:

> Just want to point out my patches that I posted last year in this
> context as well:
>
> http://rocklinux.net/pipermail/openscad/2010-August/000573.html
>
> (Since the pipemail seems to have eaten the patches, I've stuck them at
> http://fishsoup.net/misc/openscad/external-script/)
>
> Those had pretty good caching integration, but no interruptibility.
> There's some comments in the code about what it would take to switch to
> QProcess instead of blocking the main loop.
>
> - Owen
>
> On Thu, Jan 20, 2011 at 11:39 PM, Marius Kintel <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Elmo,
>
>     Thanks for your patch.
>     I'm uncertain how we should best deal with this for several reasons:
>     o OpenSCAD makes heavy use of caching. This should be taken into
>     account.
>     o I would like a way to cancel rogue scripts.
>     o As already mentioned, syntax needs to be thought through
>
>     All this is best done after the upcoming release, when I can merge
>     the refactored codebase into master.
>     We'll officially move to git as well. For now, you can fork from
>     github and play from there:
>     https://github.com/openscad/openscad
>
>       -Marius
>
>     _______________________________________________
>     OpenSCAD mailing list
>     [hidden email] <mailto:[hidden email]>
>     http://rocklinux.net/mailman/listinfo/openscad
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad