Skip to content

Lenbok/scad-dbus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

OpenSCAD D-Bus control for Emacs

Provides Linux users control of OpenSCAD from within Emacs.

OpenSCAD has the ability to use D-Bus (an Linux IPC mechanism) as an input driver, which allows manipulation of the viewport and execution of menu commands. Since Emacs also speaks D-Bus, we can execute most of the OpenSCAD GUI adjustments without having to switch windows or reach for our mouse.

Screenshot

screenshot.png

Installation

First, make sure you have a version of OpenSCAD built with experimental features enabled. Apparently enabled in snapshots http://www.openscad.org/downloads.html#snapshots or if building your self, see https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Building_on_Linux/UNIX#Experimental

Then enable DBus in OpenSCAD via:

Preferences-> Features -> input-driver-dbus
Preferences-> Axes -> DBus

You will see at the bottom of the Axes tab, a Status: line that says something like DBusInputDriver (:1.1205) open

Install scad-dbus.el in your load path, and then:

(require 'scad-dbus)

An example hydra is provided that gives a simple interface for issue successive commands to OpenSCAD. You might bind it like this:

(define-key scad-mode-map (kbd "C-c o") 'hydra-scad-dbus/body)

If you are using use-package and straight.el, you might prefer something like this:

(use-package scad-dbus
  :after scad-mode
  :straight (:host github :repo "Lenbok/scad-dbus" :branch "master")
  :bind (:map scad-mode-map ("C-c o" . 'hydra-scad-dbus/body)))

You can test whether emacs sees OpenSCAD on the D-Bus by executing (scad-dbus-connected).

Note: as of writing, OpenSCAD has some kind of bug where even though the D-Bus API is activated (and the above scad-dbus-connected reports OpenSCAD as being available), it won’t initially execute commands if it is started with it’s built-in editor hidden. After some manual selection of random menu items in the GUI, the API may start to behave (and thus the emacs scad-dbus interface works), but the easiest workaround is to ensure the built-in editor is visible when starting OpenSCAD (you can then hide it). See: openscad/openscad#3367

Extensions

Not all of the available OpenSCAD menu items have had emacs functions created, just those that I tend to use. The list of all available items can be retrieved via:

M-x scad-dbus-list-actions

If you would like to create an emacs function that can interactvely be invoked to execute that action, you can use the scad-dbus--action-command macro, e.g:

(scad-dbus--action-command scad-dbus-show-help-about "helpActionAbout")

Alternative

scad-preview https://github.com/zk-phi/scad-preview is another approach to previewing OpenSCAD from within emacs. This mode calls the OpenSCAD command every time a new preview image is required, with all the performance penalty this implies. On the other hand, it is more cross-platform.

About

Control OpenSCAD from Emacs using D-Bus

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published