Extending OpenSCAD


OpenSCAD with Syntax Highlighting

There have always been a number of feature missing from openSCAD that frustrated me. So, on Friday, I pulled the source code from it and started hacking on it.

I was pleasantly surprised to discover that most of the openSCAD source code is well written and easy to modify. It helped that I had worked in C++ with the QT libraries before.

The most visible change I’ve made is demonstrated in the above screen shot: syntax highlighting.

I’ve also added a number of language extensions:

  • Dot/Cross Product (* and %)
  • length function for lengths of vectors and strings
  • accessing characters in a string via []

Then there are some things I’ve been thinking of doing:

  • includes using relative paths
  • echo not prepending with “ECHO: “
  • concatenate strings/vectors with a “++” operator UPDATE: Implemented.
  • describe vectors in circular/spherical coordinates. Something like magnitude$theta$phi?

In any case, I’m curious as to what other people would like to change in openSCAD. Your thoughts?

(My changes are not merged into the main branch of openSCAD. You can try them by building my branch, which you can get from github.)

About these ads

Tags:

7 Responses to “Extending OpenSCAD”

  1. Anthong Says:

    woohoo! Thanks for that. Been spending a lot of time in openscad and it can be frustrating when I’m used to working with apps like notepad++

    would love to have tabs to work on multiple docs at once :)

    once you include a lib it would be really nice to be able to see a selection of functions and vars available from it.

    more on the visual side of things, being able to highlight a block in the render from a block of code even if it’s buried somewhere in the mess would be nice.

    • christopherolah Says:

      > would love to have tabs to work on multiple docs at once :)

      I completely forgot how much I wanted that when I started with openSCAD. Consider it added to my list, though I think it would be tricky to implement.

      >once you include a lib it would be really nice to be able to see a selection of functions and vars available from it.
      >more on the visual side of things, being able to highlight a block in the render from a block of code even if it’s buried somewhere in the mess would be nice.

      Those are both really cool ideas, though non-trivial… I’ll keep them in mind.

  2. Erik Says:

    Whoa!! This is great work. I spend a LOT of time in OpenSCAD. More than I can afford, but the syntax highlighting that was missing makes me crazy.

    Those other things are also serious improvements. Though syntax highlighting DEFINTELY makes my day!!

    I have one request that would make OpenSCAD A LOT better: not just highlight syntax, but also highlight where the line with the cursor/caret is, which objects fall under that part. So essentially, it is analogous to:
    1. hitting home (beginning of the line) “#” (for highlighting the item in OpenSCAD)
    2. hitting F5.
    3. Removing the #.
    Similarly, it would be great if you could ‘nudge’ numbers with the arrow keys, to increase or decrease them slightly and see the preview change. This will help you change the right axis (for transform or rotate operations).

    Other definite “want to haves”:
    TABS! (especially those includes, will get people to SCAD more modularly)
    After rotating the view, put the cursor at the line where it was. Too often I change stuff in the wrong place because lines often appear similar.

    • christopherolah Says:

      >Whoa!! This is great work. I spend a LOT of time in OpenSCAD. More than I can afford, but the syntax highlighting that was missing makes me crazy.
      >Those other things are also serious improvements. Though syntax highlighting DEFINTELY makes my day!!

      Thanks! I actually just found out on the openSCAD mailing list that openSCAD could already support syntax highlighting if you change some setting sin the Makefile and build against QCodeEditor (details).

      We’ve agreed that built in syntax highlighting is a good thing, though, so I think my code will get in.

      >I have one request that would make OpenSCAD A LOT better: not just highlight syntax, but also highlight where the line with the cursor/caret is, which objects fall under that part. So essentially, it is analogous to:
      >1. hitting home (beginning of the line) “#” (for highlighting the item in OpenSCAD)
      >2. hitting F5.
      >3. Removing the #.

      I think it would be very difficult to implement precisely this, since my highlighter doesn’t have any easy way of finding out what line it is on, let alone what line your cursor is on. But having highlighting past # till the end of the block/line/whatever should be possible and fairly easy.

      >Similarly, it would be great if you could ‘nudge’ numbers with the arrow keys, to increase or decrease them slightly and see the preview change. This will help you change the right axis (for transform or rotate operations).

      Ooh. That would be cool.

      BTW, congrats on shipping ultimaker!

  3. Anthong Says:

    I thought of a new and easy one… keeping indents.

    most code editors keep track of what column you are in when you goto the next line.

    Also, highlighting a code blaock and increasing the indent by pressing tab would be cool.

  4. ben Says:

    Personally, I’d love to see recursion.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 464 other followers

%d bloggers like this: