AutoCAD - Save as DXF in Sub Folder - autocad

I found this code online to save a selection from an AutoCAD DWG into a DXF format in the project folder. I am not well versed in AutoLISP. What do I need to change to save all of these drawings in a subfolder called "CNC Parts"?
;save selection as dxf
(defun c:DQ ()
(setq dxfname (getstring 1 "\nFilename="))
(command "SAVEAS" "DXF" "VERSION" "2010" "OBJECTS" "CROSSING" "\\" "\\" "" "16" (strcat (getvar "dwgprefix") dxfname) "FILEDIA" "1")
); function

Just add subpath between path and filename
(command "SAVEAS" "DXF" "VERSION" "2010" "OBJECTS" "CROSSING" "\\" "\\" "" "16" (strcat (getvar "dwgprefix") "CNC Parts\\" dxfname) "FILEDIA" "1")

Related

Trailing backslash error web-mode content type

I get this error when trying to set content type in web-mode: File mode specification error: (invalid-regexp Trailing backslash)
I have had a hard time debugging this. I'm very new to emacs so I need some help setting web-mode. I have been following the documentation in web-mode.org but it has been difficult to decypher. Thanks.
(use-package
web-mode
:defer 2
:ensure t
:mode ("\\.html?\\"
"\\.hbs$\\"
"\\.vue$\\"
"\\.css?\\"
"components/.*\\.js[x]?\\'"
"containers/.*\\.js[x]?\\'")
:config (progn
(setq web-mode-enable-auto-closing t
web-mode-enable-auto-opening t
web-mode-enable-auto-pairing t
web-mode-enable-auto-indentation t
web-mode-enable-auto-quoting t
;; right now paired with AutoComplete
web-mode-ac-sources-alist
'(("css" . (ac-source-css-property))
("vue" . (ac-source-words-in-buffer ac-source-abbrev))
("html" . (ac-source-words-in-buffer ac-source-abbrev)))
web-mode-content-types-alist
'(("jsx" . "components/.*\\.js[x]?\\'")
("jsx" . "containers/.*\\.js[x]?\\'")))))
;; usually I set them in containers/ or components/ directorie
;; and to keep seperate from plain JS
;; adjust indents for web-mode to 2 spaces
(defun my-web-mode-hook ()
"Hooks for Web mode. Adjust indents"
;;; http://web-mode.org/
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2))
(add-hook 'web-mode-hook 'my-web-mode-hook)
In the list of regexps after :mode, make sure that they all end with \\'. Currently two of them do, but four of them lost the final ' character.
:mode ("\\.html?\\'"
"\\.hbs$\\'"
"\\.vue$\\'"
"\\.css?\\'"
"components/.*\\.js[x]?\\'"
"containers/.*\\.js[x]?\\'")
\' is a special regexp construct that "matches the empty string, but only at the end of the buffer or string being matched against".

elisp: create dynamic menu with easy-menu and evaluate part of code during creation and not when called

I'm trying to create a dynamic menu for my own compiling plugin, but I have hit a wall. This is the code that I have at the moment:
(defun mme-tools-create-menu ()
(easy-menu-define mme-tools-menu erlang-mode-map "MME-Tools-Menu"
'("MME-Tools"
("Current Subsystem"
["Run gmake" mme-tools-build]
["Build beams" mme-tools-build-beam]
["Run Posttest" mme-tools-build-posttest]
["Run Move" mme-tools-build-move])
("Build Subsystem")))
(dolist (path mmepaths)
(if (string-match "code" path)
(let* ((ss (file-name-base path))
(uss (upcase ss)))
(easy-menu-add-item mme-tools-menu '("Build Subsystem")
[uss (mme-tools-build-path-subsystem " -j10 beam" (getenv ss))])))))
What I want the code to do is to make a sub-menu called "Build Subsystem" and fill it with entries. But no entries are created. Any help would be appreciated.
I'd suggest you do something like
(easy-menu-define mme-tools-menu erlang-mode-map "MME-Tools-Menu"
`("MME-Tools"
("Current Subsystem"
["Run gmake" mme-tools-build]
["Build beams" mme-tools-build-beam]
["Run Posttest" mme-tools-build-posttest]
["Run Move" mme-tools-build-move])
("Build Subsystem"
,#(mapcar (lambda (path)
(when (string-match "code" path)
(let* ((ss (file-name-base path))
(uss (upcase ss)))
(vector uss `(mme-tools-build-path-subsystem " -j10 beam" (getenv ',ss))))))))))
I suspect you might be looking for something like this, but it's hard to know without seeing more code. You should be able to debug this yourself, using macroexpand etc. until you get a proper set of arguments to pass to easy-menu-define.
Wrt Stefan's code, this adds the missing mapcar second arg, as you mentioned, and it removes the backquote before (mme-tools-build-path-subsystem...) (just a guess).
(easy-menu-define
mme-tools-menu
erlang-mode-map "MME-Tools-Menu"
`("MME-Tools"
("Current Subsystem"
["Run gmake" mme-tools-build]
["Build beams" mme-tools-build-beam]
["Run Posttest" mme-tools-build-posttest]
["Run Move" mme-tools-build-move])
("Build Subsystem"
,#(mapcar (lambda (path)
(when (string-match "code" path)
(let* ((ss (file-name-base path))
(uss (upcase ss)))
(vector uss
(mme-tools-build-path-subsystem
" -j10 beam" (getenv ',ss))))))
mmepaths))))

AutoCAD 2013 - Error: ARXLOAD failed

currently i have autocad 2012 and want to upgrade to autocad 2013.
I have a custom made addition to my autocad.
But when i try to load this i get this:
COM.VLX loaded.; error: ARXLOAD failed
Here is a part of my acaddoc.lsp:
;; ACADDOC.LSP is loaded into memory before the drawing is completely
;; initialized. S::STARTUP is called when a new drawing or an existing
;; drawing is opened. And is guaranteed to perform any setup operations
;; after a drawing is initialized.
(defun LoadARXVBA(/ strplatform strExt)
(if (wcmatch (getvar "platform") "*(x64)*")
(setq strExt "x64.arx")
(setq strExt ".arx")
)
;; load arx modules
(arxload (strcat "DetectESC" strExt))
(arxload (strcat "osnap" strExt))
(arxload (strcat "beditReactor" strExt))
;; load vba projects
(vla-loaddvb (acadobject) (findfile "sinkblock.dvb"))
(vla-loaddvb (acadobject) (findfile "triggers.dvb"))
(if (member "plotlog.arx" (arx));if loaded by acad.rx
(vla-loaddvb (acadobject) (findfile "PlotLog.dvb"))
)
;; connect to plotlog server
(if (member (strcat "plotlog" strExt) (arx))
(vla-runmacro (acadobject) "StartMonitor")
)
;; visuallisp projects
(load "base.vlx")
(load "startup.vlx")
(load "TSLOAD"); Load TIMESAVERS' commands:
(defun EVALCHK (dummy / ) 1)
;; run stuff
(startup)
)
(defun-q main(/)
;; load visuallisp & vba projects
(setvar "screenmenu" 1)
(setvar "menubar" 1)
(load "com.vlx")
(if (eq (vla-get-visible (acadobject)) :vlax-true)
(LoadARXVBA)
) ;end if
(princ)
) ;end main
(setvar "savetime" 8)
;; append 'main function to any posible existing S::STARTUP function
(setq s::startup (append s::startup main))
;|«Visual LISP© Format Options»
(100 2 1 2 nil "end of " 100 70 0 0 nil T T nil T)
;*** DO NOT add text below the comment! ***|;
Can anyone help me with this?
I have read at some places that there something changed in the arx loading ...
The ARX module will need to be rebuilt with the ObjectARX 2013 SDK for use in AutoCAD 2013.
Download ObjectARX 2013 : http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=785550 and rebuild your solution using the 2013 SDK.
Here is the ObjectARX Wizard for AutoCAD 2013 and MSVC 2010 : http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=785550
Hope it helped.
Tom,

Loop Over Video Files in Folder to get video length

I have the following which returns how many seconds a selected video file is.
However I was after a way to just give it the movie folder and for it to then loop through all subdirectories and find all video file types.
Once it has these I would like to list the video length in "1 hour 53 seconds" type format as "7990 seconds" isn't too helpful.
Thanks
set macPath to (choose file) as text
tell application "System Events"
set ts to time scale of movie file macPath
set dur to duration of movie file macPath
set movieTime to dur / ts
end tell
You have several sub-questions involved in your question.
1) How do I get all of the files in a folder, including the sub folders
2) how do I filter that list to only include video files
3) How do I loop through that list of video files and extract information from each and
4) How do I convert seconds into a useable string of words
Normally I would ask that you break it down into those individual questions because it's a large task for someone to write the whole thing for you. However, in this case you're lucky because I had done this before myself... so you can have my script. I put lots of comments in the code to help you learn how it works.
-- I found these extensions for video files here http://www.fileinfo.net/filetypes/video
-- we can check the file extensions of a file against this list to evaluate if it's a video file
set video_ext_list to {"3g2", "3gp", "3gp2", "3gpp", "3mm", "60d", "aep", "ajp", "amv", "asf", "asx", "avb", "avi", "avs", "bik", "bix", "box", "byu", "cvc", "dce", "dif", "dir", "divx", "dv", "dvr-ms", "dxr", "eye", "fcp", "flc", "fli", "flv", "flx", "gl", "grasp", "gvi", "gvp", "ifo", "imovieproject", "ivf", "ivs", "izz", "izzy", "lsf", "lsx", "m1v", "m2v", "m4e", "m4u", "m4v", "mjp", "mkv", "moov", "mov", "movie", "mp4", "mpe", "mpeg", "mpg", "mpv2", "msh", "mswmm", "mvb", "mvc", "nvc", "ogm", "omf", "prproj", "prx", "qt", "qtch", "rm", "rmvb", "rp", "rts", "sbk", "scm", "smil", "smv", "spl", "srt", "ssm", "svi", "swf", "swi", "tivo", "ts", "vdo", "vf", "vfw", "vid", "viewlet", "viv", "vivo", "vob", "vro", "wm", "wmd", "wmv", "wmx", "wvx", "yuv"}
-- get the folder to check
set f to choose folder
-- notice the use of "entire contents" to also go through subfolders of f
-- use a "whose" filter to find only the video files
tell application "Finder"
set vidFiles to (files of entire contents of f whose name extension is in video_ext_list) as alias list
end tell
-- use a repeat loop to loop over a list of something
set vidList to {} -- this is where we store the information as we loop over the files
repeat with aFile in vidFiles
-- get some information from aFile
tell application "System Events"
set vidFile to movie file (aFile as text)
set ts to time scale of vidFile
set dur to duration of vidFile
end tell
-- add the information to the "storage" list we made earlier
set end of vidList to {POSIX path of aFile, secs_to_hms(dur / ts)}
end repeat
return vidList
(*=================== SUBROUTINES ===================*)
-- convert seconds into a string of words
-- the use of "mod" and "div" here makes it easy
-- we also make sure that each value is at least 2 places long to make it look nicer
on secs_to_hms(the_secs)
set timeString to ""
set hr to the_secs div hours
if hr is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (hr as text))) & " hours "
set min to the_secs mod hours div minutes
if min is not 0 then set timeString to timeString & (text -2 thru -1 of ("0" & (min as text))) & " minutes "
set sec to the_secs mod minutes div 1
if sec is not 0 then
set fraction to text 2 thru 3 of ((100 + the_secs mod 1 * 100) as text)
set timeString to timeString & (sec as text) & "." & fraction & " seconds"
end if
if timeString ends with space then set timeString to text 1 thru -2 of timeString
return timeString
end secs_to_hms
I came across this post because I wanted to have a log of video files in a folder; something I could import in a spreadsheet, also to calculate the total duration but not only.
The posted script didn't work for me so I ended up importing the folder in Final Cut Pro, doing Batch Export on the folder and than File > Export > Batch List, which resulted in a plain text file I could import in a spreadsheet as the start of a log and to calculate the total duration.
Perhaps this helps others.

Extracting URLs from an Emacs buffer?

How can I write an Emacs Lisp function to find all hrefs in an HTML file and extract all of the links?
Input:
<html>
<a href="http://www.stackoverflow.com" _target="_blank">StackOverFlow&lt/a>
<h1>Emacs Lisp</h1>
<a href="http://news.ycombinator.com" _target="_blank">Hacker News&lt/a>
</html>
Output:
http://www.stackoverflow.com|StackOverFlow
http://news.ycombinator.com|Hacker News
I've seen the re-search-forward function mentioned several times during my search. Here's what I think that I need to do based on what I've read so far.
(defun extra-urls (file)
...
(setq buffer (...
(while
(re-search-forward "http://" nil t)
(when (match-string 0)
...
))
I took Heinzi's solution and came up with the final solution that I needed. I can now take a list of files, extract all URL's and titles, and place the results in one output buffer.
(defun extract-urls (fname)
"Extract HTML href url's,titles to buffer 'new-urls.csv' in | separated format."
(setq in-buf (set-buffer (find-file fname))); Save for clean up
(beginning-of-buffer); Need to do this in case the buffer is already open
(setq u1 '())
(while
(re-search-forward "^.*<a href=\"\\([^\"]+\\)\"[^>]+>\\([^<]+\\)</a>" nil t)
(when (match-string 0) ; Got a match
(setq url (match-string 1) ) ; URL
(setq title (match-string 2) ) ; Title
(setq u1 (cons (concat url "|" title "\n") u1)) ; Build the list of URLs
)
)
(kill-buffer in-buf) ; Don't leave a mess of buffers
(progn
(with-current-buffer (get-buffer-create "new-urls.csv"); Send results to new buffer
(mapcar 'insert u1))
(switch-to-buffer "new-urls.csv"); Finally, show the new buffer
)
)
;; Create a list of files to process
;;
(mapcar 'extract-urls '(
"/tmp/foo.html"
"/tmp/bar.html"
))
If there is at most one link per line and you don't mind some very ugly regular expression hacking, run the following code on your buffer:
(defun getlinks ()
(beginning-of-buffer)
(replace-regexp "^.*<a href=\"\\([^\"]+\\)\"[^>]+>\\([^<]+\\)</a>.*$" "LINK:\\1|\\2")
(beginning-of-buffer)
(replace-regexp "^\\([^L]\\|\\(L[^I]\\)\\|\\(LI[^N]\\)\\|\\(LIN[^K]\\)\\).*$" "")
(beginning-of-buffer)
(replace-regexp "
+" "
")
(beginning-of-buffer)
(replace-regexp "^LINK:\\(.*\\)$" "\\1")
)
It replaces all links with LINK:url|description, deletes all lines containing anything else, deletes empty lines, and finally removes the "LINK:".
Detailed HOWTO: (1) Correct the bug in your example html file by replacing <href with <a href, (2) copy the above function into Emacs scratch, (3) hit C-x C-e after the final ")" to load the function, (4) load your example HTML file, (5) execute the function with M-: (getlinks).
Note that the linebreaks in the third replace-regexp are important. Don't indent those two lines.
You can use the 'xml library, examples of using the parser are found here. To parse your particular file, the following does what you want:
(defun my-grab-html (file)
(interactive "fHtml file: ")
(let ((res (car (xml-parse-file file)))) ; 'car because xml-parse-file returns a list of nodes
(mapc (lambda (n)
(when (consp n) ; don't operate on the whitespace, xml preserves whitespace
(let ((link (cdr (assq 'href (xml-node-attributes n)))))
(when link
(insert link)
(insert "|")
(insert (car (xml-node-children n))) ;# grab the text for the link
(insert "\n")))))
(xml-node-children res))))
This does not recursively parse the HTML to find all the links, but it should get you started in the direction of the general solution.

Resources