AutoCAD (also LT) combox control in plot window, ChooseString not finding printer - autohotkey

I made an AutoHotkey script to print drawings to PDF; however, I am having issues with a particular combobox in AutoCAD's plot dialog box. This combobox allows you to select one of your installed printers or printer configuration files. The printer I want to choose is one of the built-in ones, called "DWG To PDF.pc3". Here is my code snippet that DOESN'T work (it appears to do nothing):
Control , ChooseString , DWG , ComboBox1 , Plot - Model
Additionally, I've tried with and without quotes (it's always hard for me to tell when I need to quote literal text) and the full name -- nothing works. My workaround (temporarily, I hope) is to use Control , Choose , N. This is undesirable as different users may have more or fewer printers installed and this will affect where the desired printer is placed in the list. Here is a snippet of that code:
Control , Choose , 20 , ComboBox1 , Plot - Model
For reference, I have installed AutoHotkey version 1.1.30.01 - November 11, 2018.
What am I missing? Or any suggestions or creative solutions (even from other programming languages)? Thank you!
EDIT:
TL;DR - This is mainly geared for LT.
Full Context - I have full AutoCAD (Mechanical) and use LISP for many tasks. In fact, I've used your (Lee Mac's) tutorials and helpful posts across many forums to get started with it years ago. At my company, we have 27 seats of LT (11 full) where I've set up a company ribbon with SCR files for a few things, including printing. This case is a little different because some of the users need to be able to select a few different pre-configured print options.
Of course, I could make more SCR files for this purpose, but they lack user-error-prevention that AHK can provide. Really, I have a working program with AHK, but it's just short of meeting my standard since there seems to be something goofy going on with just that one particular combobox. So, if someone could steer me towards figuring that out, I would greatly appreciate it.

Firstly, it would be helpful if you could clarify whether the host application is the full version of AutoCAD or the lite version AutoCAD LT, since the former supports full customisation using the AutoLISP, .NET, or ObjectARX APIs (and hence this task is straightforward) whereas the latter does not support customisation, meaning third-party tools (such as AutoHotKey) must be used.
If you have access to the full version of AutoCAD, then the task of plotting to a PDF can be accomplished with an AutoLISP program such as the following:
(defun c:pdfall ( / *error* cmd ctb )
(defun *error* ( msg )
(if ctb (setvar 'ctab ctb))
(if cmd (setvar 'cmdecho cmd))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(setq ctb (getvar 'ctab)
cmd (getvar 'cmdecho)
)
(setvar 'cmdecho 0)
(foreach lay (layoutlist)
(setvar 'ctab lay)
(command
"_.-plot"
"_Y" ;; Detailed plot configuration? [Yes/No]:
"" ;; Enter a layout name <Current-Layout>:
"DWG To PDF.pc3" ;; Enter an output device name:
"ISO full bleed A4 (297.00 x 210.00 MM)" ;; Enter paper size:
"_M" ;; Enter paper units [Inches/Millimeters]:
"_L" ;; Enter drawing orientation [Portrait/Landscape]:
"_N" ;; Plot upside down? [Yes/No]:
"_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
"_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
"_C" ;; Enter plot offset (x,y) or [Center]:
"_Y" ;; Plot with plot styles? [Yes/No]:
"monochrome.ctb" ;; Enter plot style table name (enter . for none):
"_Y" ;; Plot with lineweights? [Yes/No]:
"_N" ;; Scale lineweights with plot scale? [Yes/No]:
"_N" ;; Plot paper space first? [Yes/No]:
"_N" ;; Hide paperspace objects? [Yes/No]:
(LM:uniquefilename (strcat (getvar 'dwgprefix) lay ".pdf"))
"_N" ;; Save changes to page setup [Yes/No]:
"_Y" ;; Proceed with plot [Yes/No]:
)
)
(setvar 'ctab ctb)
(setvar 'cmdecho cmd)
(princ)
)
;; Unique Filename - Lee Mac
;; Returns a filename suffixed with the smallest integer required for uniqueness
(defun LM:uniquefilename ( fnm )
(if (findfile fnm)
(apply
'(lambda ( pth bse ext / tmp )
(setq tmp 1)
(while (findfile (setq fnm (strcat pth bse "(" (itoa (setq tmp (1+ tmp))) ")" ext))))
)
(fnsplitl fnm)
)
)
fnm
)
(princ)
However, assuming you only have access to the basic AutoCAD LT platform, I would suggest using the command-line version of the PLOT command: -PLOT, so that you only need to supply keyboard input to a predictable sequence of prompts, rather than interacting with a dialog interface which differs depending on the last used settings.
When using the -PLOT command, the sequence of prompts for a Paperspace Layout will be as shown in the AutoLISP program posted above, i.e.:
"_.-plot"
"_Y" ;; Detailed plot configuration? [Yes/No]:
"" ;; Enter a layout name <Current-Layout>:
"DWG To PDF.pc3" ;; Enter an output device name:
"ISO full bleed A4 (297.00 x 210.00 MM)" ;; Enter paper size:
"_M" ;; Enter paper units [Inches/Millimeters]:
"_L" ;; Enter drawing orientation [Portrait/Landscape]:
"_N" ;; Plot upside down? [Yes/No]:
"_E" ;; Enter plot area [Display/Extents/Limits/View/Window]:
"_F" ;; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1=1>:
"_C" ;; Enter plot offset (x,y) or [Center]:
"_Y" ;; Plot with plot styles? [Yes/No]:
"monochrome.ctb" ;; Enter plot style table name (enter . for none):
"_Y" ;; Plot with lineweights? [Yes/No]:
"_N" ;; Scale lineweights with plot scale? [Yes/No]:
"_N" ;; Plot paper space first? [Yes/No]:
"_N" ;; Hide paperspace objects? [Yes/No]:
<Your PDF Filename Here>
"_N" ;; Save changes to page setup [Yes/No]:
"_Y" ;; Proceed with plot [Yes/No]:

Related

Moving point to the end of the last line without reorienting the buffer

Is it possible to move point to the end of a buffer without reorienting the text around that line? This seems to be the default behaviour of goto-char. My goal is to correct a minor annoyance which places the cursor at the second last line when I press "L". I wrote a custom function to do this properly but now when I move the point to the last line the screen scrolls down half a page and it becomes the center of the buffer.
(defun cf-last-line (count) (interactive "p")
(let ((max (truncate (window-screen-lines))))
(move-to-window-line max)
(line-move (* -1 (1- count)) t t)
(beginning-of-line)))
Edit: It turns out my problem is related to the fact that the GUI shows partial lines (which may appear to be fully exposed but upon closer inspection lie just below the status bus). I suppose my question then becomes whether or not it is possible to have the point lie on such a partial line (though I suspect this is unlikely) without moving it to the center and if not whether it is possible to instead prevent the X11 frame from showing partial lines at the bottom of the window.
Solution as described by lawlist:
(setq scroll-conservatively 101)
(setq make-cursor-line-fully-visible nil)

Centre Emacs buffer within window

I wrap all my code at 80 columns, and there are times where the Emacs window is wider than 80 columns and there is a lot of unused whitespace on the right side.
I would like to position the Emacs buffer, so all the text is displayed in the middle of the window.
This is different to centre aligning text (more akin to the whitespace on either side of the text when viewing pdfs).
I think this can be achieved by dynamically adjusting the fringe mode widths, depending on the current window size, but I'm not sure where to start. Any ideas?
As demonstrated here this is indeed possible:
(set-fringe-mode
(/ (- (frame-pixel-width)
(* 80 (frame-char-width)))
2))
However, as I am testing this I seem to have more luck with using margins, at least when also resizing my frame:
(defun my-resize-margins ()
(let ((margin-size (/ (- (frame-width) 80) 2)))
(set-window-margins nil margin-size margin-size)))
(add-hook 'window-configuration-change-hook #'my-resize-margins)
(my-resize-margins)
Here is a function which should do what you want, using margins instead of fringes (since I tend to display buffer boundaries in the fringe and I find it becomes ugly if the fringe is too large).
(defun my/center (width)
(interactive "nBuffer width: ")
(let* ((adj (- (window-text-width)
width))
(total-margin (+ adj
left-margin-width
right-margin-width)))
(setq left-margin-width (/ total-margin 2))
(setq right-margin-width (- total-margin left-margin-width)))
(set-window-buffer (selected-window) (current-buffer)))
You ask to display the buffer in the center of the window, which just moves some of the extra whitespace to the left of the buffer, from the right.
How about a solution that eliminates that extra whitespace instead? If that is acceptable, here are two approaches.
If the buffer is alone in its frame, then you can fit the frame to the buffer, using library fit-frame.el. I bind command fit-frame to C-x C-_. This saves space not only within Emacs but for your desktop. (Library zoom-frm.el lets you also shrink/enlarge a frame incrementally, so you can save space by shrinking a frame when you don't need to see its content in detail.)
If not (so the buffer is shown in a frame where there are multiple windows), and if the buffer's window has another window to the left or right of it, then you can do one of the following:
2a. If the buffer's window has another window to the left or right of it, then you can use command fit-window-to-buffer. But you will also need to set option fit-window-to-buffer-horizontally to non-nil.
2b. Use C-{ (shrink-window-horizontally), followed by C-x z z z..., to incrementally shrink the window width (removing the extra whitespace).
2c. Load library face-remap+.el. Whenever you use text-scaling (e.g. C-x C- or C-x =), the window size grows or shrinks along with the text size, so you don't get extra whitespace added at the right when you shrink the text. This is controlled by user option text-scale-resize-window.
Center window mode
https://github.com/anler/centered-window-mode
Global minor mode that centers the text of the window.
If another window is visible the text goes back to normal if its width is less than "cwm-centered-window-width."
Modern answer is https://github.com/rnkn/olivetti or https://github.com/joostkremers/writeroom-mode, both worked immediately for me where other things did not

"Package GLUT does not exist", even though cl-opengl installed in Arch Linux

I have emacs configured with SLIME for developing in Common Lisp (sbcl) on Arch Linux. The thing is, I now want to start working with OpenGL as well, so I've installed cl-opengl to provide the necessary bindings. I have also set up a symlink on .local/share/common-lisp to /usr/share/common-lisp (I should be able to load all systems using ASDF that way).
However, when I try to compile the following code in SLIME (using C-c C-k)
(require :asdf) ; need ASDF to load other things
(asdf:load-system :cl-opengl) ; load OpenGL bindings
(asdf:load-system :cl-glu) ; load GLU bindings
(asdf:load-system :cl-glut) ; load GLUT bindings
(defclass my-window (glut:window)
()
(:default-initargs :width 400 :height 300
:title "My Window Title"
:x 100 :y 100
:mode '(:double :rgb :depth)))
(defmethod glut:display-window :before ((win my-window))
(gl:shade-model :smooth) ; enables smooth shading
(gl:clear-color 0 0 0 0) ; background will be black
(gl:clear-depth 1) ; clear buffer to maximum depth
(gl:enable :depth-test) ; enable depth testing
(gl:depth-func :lequal) ; okay to write pixel if its depth
; is less-than-or-equal to the
; depth currently written
; really nice perspective correction
(gl:hint :perspective-correction-hint :nicest)
)
(defmethod glut:display ((win my-window))
(gl:clear :color-buffer-bit :depth-buffer-bit)
(gl:load-identity))
(defmethod glut:reshape ((win my-window) width height)
(gl:viewport 0 0 width height) ; reset the current viewport
(gl:matrix-mode :projection) ; select the projection matrix
(gl:load-identity) ; reset the matrix
;; set perspective based on window aspect ratio
(glu:perspective 45 (/ width (max height 1)) 1/10 100)
(gl:matrix-mode :modelview) ; select the modelview matrix
(gl:load-identity) ; reset the matrix
)
(glut:display-window (make-instance 'my-window))
I get the following error:
READ error during COMPILE-FILE:
Package GLUT does not exist.
even though cl-glut.asd exists in /usr/share/common-lisp/systems.
What am I doing wrong?
ASDF:LOAD-SYSTEM doesn't take effect until load time, since it's a plain function. If you want the effect to happen at compile time, you have to wrap it in an eval-when form. But it's better to write a system definition that :depends-on those other systems.

How to recenter an Emacs buffer around an overlay

I want to recenter an Emacs buffer so as to show as much as possible of an overlay and of its context around it. Specifically, I want this behavior:
If the overlay fits in the visible window, I want to show as much as line before it as lines after it;
Otherwise, I want the beginning of the overlay to be shown.
This behavior is somewhat similar to what I see when using different regions highlighted in ediff.
Is there a not-so-complicated way to achieve this? I tried to look into the ediff code (specifically ediff-util.el) but things seems very complicated to me.
I'm not quite sure what usage you're looking for, but this code should do what you want.
It can be called with an overlay, or if called interactively, will choose one of the overlays at the current position and do the action on it.
(defun make-overlay-visible (overlay)
"given an overlay, center it on the window
(or make beginning visible if it cannot fit in the window)"
(interactive (list (car (overlays-at (point)))))
(when overlay
(goto-char (overlay-start overlay))
(recenter 0)
(when (and (pos-visible-in-window-p (overlay-start overlay))
(pos-visible-in-window-p (overlay-end overlay)))
(goto-char (/ (+ (overlay-start overlay) (overlay-end overlay)) 2))
(recenter))))

How to interactively read in two inputs and use them in a function call

I am currently taking a class to learn elisp so I have no experience with this language. I am trying to interactively read in two inputs (the width and length of a rectangle) and then use them to call a function to compute the area of the rectangle. The code I have is as follows:
(defun rectangle_Area(w l)
"Compute the area of a rectangle, given its width and length interactively."
(interactive "nWidth: ")
(interactive "nLength: ")
(setq area (rectangleArea w l))
(message "The rectangle's area is %f." area))
Currently I get a wrong number of arguments error.
Like I said, I have no previous experience... all I really need to know is how to store/read in two separate values using interactive.
Thank you for any help
C-hf interactive RET:
To get several arguments, concatenate the individual strings,
separating them by newline characters.
So we have:
(defun rectangle_Area(w l)
"Compute the area of a rectangle, given its width and length interactively."
(interactive "nWidth: \nnLength: ")
(setq area (rectangleArea w l))
(message "The rectangle's area is %f." area))