让博客园支持Autolisp语法

;;------------------=={ Get Files Dialog }==------------------;;

;;                                                            ;;

;;  An analog of the ‘getfiled‘ function for multiple files.  ;;

;;------------------------------------------------------------;;

;;  Author: Lee Mac, Copyright ?2013 - www.lee-mac.com       ;;

;;------------------------------------------------------------;;

;;  Arguments:                                                ;;

;;  msg - Dialog box label; ‘Select Files‘ if nil or "".      ;;

;;  def - Default directory; dwgprefix if nil or "".          ;;

;;  ext - File extension filter (e.g. "dwg;lsp"); "*" if nil  ;;

;;------------------------------------------------------------;;

;;  Returns:  List of selected files, else nil                ;;

;;------------------------------------------------------------;;

;;  Version 1.3    -    25-07-2013                            ;;

;;------------------------------------------------------------;;

(defun LM:getfiles ( msg def ext /*error* dch dcl des dir dirdata lst rtn )

(defun*error*( msg )

(if(= ‘file (type des))

(close des)

)

(if(and(= ‘int (type dch))(<0 dch))

(unload_dialog dch)

)

(if(and(= ‘str (type dcl))(findfile dcl))

(vl-file-delete dcl)

)

(if(and msg (not(wcmatch(strcase msg t)"*break,*cancel*,*exit*")))

(princ(strcat"\nError: " msg))

)

(princ)

)

(if

(and

(setq dcl (vl-filename-mktempnilnil".dcl"))

(setq des (open dcl "w"))

(progn

(foreach x

‘(

"lst : list_box"

"{"

"    width = 40.0;"

"    height = 20.0;"

"    fixed_width = true;"

"    fixed_height = true;"

"    alignment = centered;"

"    multiple_select = true;"

"}"

"but : button"

"{"

"    width = 20.0;"

"    height = 1.8;"

"    fixed_width = true;"

"    fixed_height = true;"

"    alignment = centered;"

"}"

"getfiles : dialog"

"{"

"    key = \"title\"; spacer;"

"    : row"

"    {"

"        alignment = centered;"

"        : edit_box { key = \"dir\"; label = \"Folder:\"; }"

"        : button"

"        {"

"            key = \"brw\";"

"            label = \"Browse\";"

"            fixed_width = true;"

"        }"

"    }"

"    spacer;"

"    : row"

"    {"

"        : column"

"        {"

"            : lst { key = \"box1\"; }"

"            : but { key = \"add\" ; label = \"Add Files\"; }"

"        }"

"        : column {"

"            : lst { key = \"box2\"; }"

"            : but { key = \"del\" ; label = \"Remove Files\"; }"

"        }"

"    }"

"    spacer; ok_cancel;"

"}"

)

(write-line x des)

)

(setq des (close des))

(<0(setq dch (load_dialog dcl)))

)

(new_dialog"getfiles" dch)

)

(progn

(setq ext (if ext (LM:getfiles:str->lst (strcase ext)";") ‘("*")))

(set_tile"title"(if(member msg ‘(nil""))"Select Files" msg))

(set_tile"dir"

(setq dir

(LM:getfiles:fixdir

(if(or(member def ‘(nil""))(not(vl-file-directory-p(LM:getfiles:fixdir def))))

(getvar ‘dwgprefix)

def

)

)

)

)

(setq lst (LM:getfiles:updatefilelist dir ext nil))

(mode_tile"add"1)

(mode_tile"del"1)

(action_tile"brw"

(vl-prin1-to-string

‘(if(setq tmp (LM:getfiles:browseforfolder ""nil512))

(setq lst (LM:getfiles:updatefilelist (set_tile"dir"(setq dir tmp)) ext rtn)

rtn (LM:getfiles:updateselected dir rtn)

)

)

)

)

(action_tile"dir"

(vl-prin1-to-string

‘(if(=1$reason)

(setq lst (LM:getfiles:updatefilelist (set_tile"dir"(setq dir (LM:getfiles:fixdir $value))) ext rtn)

rtn (LM:getfiles:updateselected dir rtn)

)

)

)

)

(action_tile"box1"

(vl-prin1-to-string

‘(

(lambda(/ itm tmp )

(if(setq itm (mapcar ‘(lambda( n )(nth n lst))(read(strcat"("$value")"))))

(if(=4$reason)

(cond

(   (equal ‘("..") itm)

(setq lst (LM:getfiles:updatefilelist (set_tile"dir"(setq dir (LM:getfiles:updir dir))) ext rtn)

rtn (LM:getfiles:updateselected dir rtn)

)

)

(   (and

(not(vl-filename-extension(car itm)))

(vl-file-directory-p(setq tmp (LM:getfiles:checkredirect (strcat dir "\\"(car itm)))))

)

(setq lst (LM:getfiles:updatefilelist (set_tile"dir"(setq dir tmp)) ext rtn)

rtn (LM:getfiles:updateselected dir rtn)

)

)

(   (setq rtn (LM:getfiles:sort (append rtn (mapcar ‘(lambda( x )(strcat dir "\\" x)) itm)))

rtn (LM:getfiles:updateselected dir rtn)

lst (LM:getfiles:updatefilelist dir ext rtn)

)

)

)

(if(vl-some ‘vl-filename-extension itm)

(mode_tile"add"0)

)

)

)

)

)

)

)

(action_tile"box2"

(vl-prin1-to-string

‘(

(lambda(/ itm )

(if(setq itm (mapcar ‘(lambda( n )(nth n rtn))(read(strcat"("$value")"))))

(if(=4$reason)

(setq rtn (LM:getfiles:updateselected dir (vl-remove(car itm) rtn))

lst (LM:getfiles:updatefilelist dir ext rtn)

)

(mode_tile"del"0)

)

)

)

)

)

)

(action_tile"add"

(vl-prin1-to-string

‘(

(lambda(/ itm )

(if(setq itm

(vl-remove-if-not ‘vl-filename-extension

(mapcar ‘(lambda( n )(nth n lst))(read(strcat"("(get_tile"box1")")")))

)

)

(setq rtn (LM:getfiles:sort (append rtn (mapcar ‘(lambda( x )(strcat dir "\\" x)) itm)))

rtn (LM:getfiles:updateselected dir rtn)

lst (LM:getfiles:updatefilelist dir ext rtn)

)

)

(mode_tile"add"1)

(mode_tile"del"1)

)

)

)

)

(action_tile"del"

(vl-prin1-to-string

‘(

(lambda(/ itm )

(if(setq itm (read(strcat"("(get_tile"box2")")")))

(setq rtn (LM:getfiles:updateselected dir (LM:getfiles:removeitems itm rtn))

lst (LM:getfiles:updatefilelist dir ext rtn)

)

)

(mode_tile"add"1)

(mode_tile"del"1)

)

)

)

)

(if(zerop(start_dialog))

(setq rtn nil)

)

)

)

(*error*nil)

rtn

)

(defun LM:getfiles:listbox ( key lst )

(start_list key)

(foreach x lst (add_list x))

(end_list)

lst

)

(defun LM:getfiles:listfiles ( dir ext lst )

(vl-remove-if ‘(lambda( x )(member(strcat dir "\\" x) lst))

(cond

(   (cdr(assoc dir dirdata)))

(   (cdar

(setq dirdata

(cons

(cons dir

(append

(LM:getfiles:sortlist (vl-remove"."(vl-directory-files dir nil-1)))

(LM:getfiles:sort

(if(member ext ‘(("")("*")))

(vl-directory-files dir nil1)

(vl-remove-if-not

(function

(lambda( x / e )

(and

(setq e (vl-filename-extension x))

(setq e (strcase(substr e 2)))

(vl-some ‘(lambda( w )(wcmatch e w)) ext)

)

)

)

(vl-directory-files dir nil1)

)

)

)

)

)

dirdata

)

)

)

)

)

)

)

(defun LM:getfiles:checkredirect ( dir / itm pos )

(cond

(   (vl-directory-files dir) dir)

(   (and

(=  (strcase(getenv"UserProfile"))

(strcase(substr dir 1(setq pos (vl-string-position92 dir nilt))))

)

(setq itm

(cdr

(assoc(substr(strcase dir t)(+ pos 2))

‘(

("my documents" . "Documents")

("my pictures"  . "Pictures")

("my videos"    . "Videos")

("my music"     . "Music")

)

)

)

)

(vl-file-directory-p(setq itm (strcat(substr dir 1 pos)"\\" itm)))

)

itm

)

(   dir   )

)

)

(defun LM:getfiles:sort ( lst )

(apply ‘append

(mapcar ‘LM:getfiles:sortlist

(vl-sort

(LM:getfiles:groupbyfunction lst

(lambda( a b / x y )

(and

(setq x (vl-filename-extension a))

(setq y (vl-filename-extension b))

(=(strcase x)(strcase y))

)

)

)

(function

(lambda( a b / x y )

(and

(setq x (vl-filename-extension(car a)))

(setq y (vl-filename-extension(car b)))

(<(strcase x)(strcase y))

)

)

)

)

)

)

)

(defun LM:getfiles:sortlist ( lst )

(mapcar(function(lambda( n )(nth n lst)))

(vl-sort-i(mapcar ‘LM:getfiles:splitstring lst)

(function

(lambda( a b / x y )

(while

(and

(setq x (car a))

(setq y (car b))

(= x y)

)

(setq a (cdr a)

b (cdr b)

)

)

(cond

(   (null x) b)

(   (null y)nil)

(   (and(numberp x)(numberp y))(< x y))

(   (="." x))

(   (numberp x))

(   (numberp y)nil)

(   (< x y))

)

)

)

)

)

)

(defun LM:getfiles:groupbyfunction ( lst fun / tmp1 tmp2 x1 )

(if(setq x1 (car lst))

(progn

(foreach x2 (cdr lst)

(if(fun x1 x2)

(setq tmp1 (cons x2 tmp1))

(setq tmp2 (cons x2 tmp2))

)

)

(cons(cons x1 (reverse tmp1))(LM:getfiles:groupbyfunction (reverse tmp2) fun))

)

)

)

(defun LM:getfiles:splitstring ( str )

(

(lambda( l )

(read

(strcat"("

(vl-list->string

(apply ‘append

(mapcar

(function

(lambda( a b c )

(cond

(   (=92 b)

(list323492 b 3432)

)

(   (or(<47 b 58)

(and(=45 b)(<47 c 58)(not(<47 a 58)))

(and(=46 b)(<47 a 58)(<47 c 58))

)

(list b)

)

(   (list3234 b 3432))

)

)

)

(consnil l) l (append(cdr l) ‘(()))

)

)

)

")"

)

)

)

(vl-string->list(strcase str))

)

)

(defun LM:getfiles:browseforfolder ( msg dir flg / err fld pth shl slf )

(setq err

(vl-catch-all-apply

(function

(lambda(/ app hwd )

(if(setq app (vlax-get-acad-object)

shl (vla-getinterfaceobject app "shell.application")

hwd (vl-catch-all-apply ‘vla-get-hwnd(list app))

fld (vlax-invoke-method shl ‘browseforfolder (if(vl-catch-all-error-p hwd)0 hwd) msg flg dir)

)

(setq slf (vlax-get-property fld ‘self)

pth (LM:getfiles:fixdir (vlax-get-property slf ‘path))

)

)

)

)

)

)

(if slf (vlax-release-object slf))

(if fld (vlax-release-object fld))

(if shl (vlax-release-object shl))

(if(vl-catch-all-error-p err)

(prompt(vl-catch-all-error-message err))

pth

)

)

(defun LM:getfiles:full->relative ( dir path / p q )

(setq dir (vl-string-right-trim"\\" dir))

(cond

(   (and

(setq p (vl-string-position58  dir))

(setq q (vl-string-position58 path))

(/=(strcase(substr dir 1 p))(strcase(substr path 1 q)))

)

path

)

(   (and

(setq p (vl-string-position92  dir))

(setq q (vl-string-position92 path))

(=(strcase(substr dir 1 p))(strcase(substr path 1 q)))

)

(LM:getfiles:full->relative (substr dir (+2 p))(substr path (+2 q)))

)

(   (and

(setq q (vl-string-position92 path))

(=(strcase dir)(strcase(substr path 1 q)))

)

(strcat".\\"(substr path (+2 q)))

)

(   (="" dir)

path

)

(   (setq p (vl-string-position92 dir))

(LM:getfiles:full->relative (substr dir (+2 p))(strcat"..\\" path))

)

(   (LM:getfiles:full->relative ""(strcat"..\\" path)))

)

)

(defun LM:getfiles:str->lst ( str del / pos )

(if(setq pos (vl-string-search del str))

(cons(substr str 1 pos)(LM:getfiles:str->lst (substr str (+ pos 1(strlen del))) del))

(list str)

)

)

(defun LM:getfiles:updatefilelist ( dir ext lst )

(LM:getfiles:listbox "box1"(LM:getfiles:listfiles dir ext lst))

)

(defun LM:getfiles:updateselected ( dir lst )

(LM:getfiles:listbox "box2"(mapcar ‘(lambda( x )(LM:getfiles:full->relative dir x)) lst))

lst

)

(defun LM:getfiles:updir ( dir )

(substr dir 1(vl-string-position92 dir nilt))

)

(defun LM:getfiles:fixdir ( dir )

(vl-string-right-trim"\\"(vl-string-translate"/""\\" dir))

)

(defun LM:getfiles:removeitems ( itm lst / idx )

(setq idx -1)

(vl-remove-if ‘(lambda( x )(member(setq idx (1+ idx)) itm)) lst)

)

(vl-load-com)(princ)

时间: 2024-08-02 18:00:43

让博客园支持Autolisp语法的相关文章

博客园支持Mardown编辑了

开心 听说博客园支持Markdown了,作为程序员专业本能来做个测试. 图片 文章没图片怎么行呢 开始 接下来准备发一些文章,都会用Markdown来写的. 原文地址:https://www.cnblogs.com/BillySir/p/9690710.html

简单两步让博客园支持手机端显示

博客园的模板是没有兼容手机端显示的,阅读体验比较差.本文教你如何简单几步让你的博客支持手机端显示.找一个夜深人静,没有人浏览你博客的时间点,开始吧. 1.添加js代码 在博客园后台的“设置”菜单下,有一项页首Html代码,此处写js代码也是可以生效的,将如下代码复制过去: <script> var content = 'width=device-width, initial-scale=1 user-scalable=no'; var viewport = document.createEle

博客园支持latex直接输入哦

$$\sum_{n=1}^{\infty}\frac{1}{n^s}=\prod_{p\in\mathcal{P}}\frac{1}{1-p^{-s}}.$$ The Cauchy-Schwarz Inequality\[ \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \] A Cross Product Formula

博客园 Markdown编辑器简要教程

简介 ?? 在刚才的导语里提到,Markdown 是一种用来写作的轻量级「标记语言」,它用简洁的语法代替排版,而不像一般我们用的字处理软件 Word 或 Pages 有大量的排版.字体设置.它使我们专心于码字,用「标记」语法,来代替常见的排版格式.例如此文从内容到格式,甚至插图,键盘就可以通通搞定了.?? 目前来看,支持 Markdown 语法的编辑器有很多,包括很多网站(例如简书)也支持了 Markdown 的文字录入.Markdown 从写作到完成,导出格式随心所欲,你可以导出 HTML 格

博客园博客兼容手机浏览

一.动手实践.改造博客园 先看一下博客园官方博客的手机版本,在Chrome里面F12,使用移动模式. 今天看博客,看到吕大豹的文章:简单两步让博客园支持手机端显示, 之前自己把博客从博客园迁移到了github的issu中,也是考虑到博客园的博客不能很好的支持手机端浏览和评论.今天根据简单两步,确实把自己的博客能兼容手机显示了,记录一下. 我的博客模板是:http://www.cnblogs.com/SkinUser.aspx?SkinName=SimpleBlue 1.添加js代码,参照吕的博客

博客园安装jQuery返回顶部代码教程

博客园支持上传js文件,这给博主提供了很大的拓展空间,例如返回顶部的jQuery代码. 首先先上传返回顶部图片到博客园 topback.gif: 然后在scrolltopcontrol.js中找到topback.gif的地址,将其替换成上传至博客园中的文件地址(右键topback.gif → 复制链接地址) scrolltopcontrol.js 代码: var scrolltotop={ setting:{ startline:100, //起始行 scrollto:0, //滚动到指定位置

博客园美化教程大集合(超详细,看这篇就够了)

阅读目录: 1. 前言 2. 定制自己的博客 0. 美化整体效果 1. 准备工作 2. 自定义个性化导航栏 3. 添加顶部博主信息 4. 添加顶部滚动公告 5. 为博客文章添加目录导航 6. 添加分享功能按键 7. 定制推荐和反对按键的炫酷样式 8. 添加快速返回顶部的功能按键 9. 添加打赏功能按键 10. 添加页面放大缩小功能按键 11. 添加Github图标及链接 12. 添加公告栏图片 13. 添加公告栏文字信息 14. 添加公告栏个性时钟 15. 为公告栏添加访客来源统计 16. 为公

博客园添加目录索引

前面写博客一直没有添加目录,这样可能不能整体对文章内容一目了然,在参考博主"赵子清的技术文章"后,简单的修改了js代码,实现了博客的目录自动生成.参考博文地址在最后面.我的文章一般使用三级标题和四级标题,因此代码中修改成自动生成h3和h4目录,另外修改了li前面的图标为数字. 使用步骤 (1)确保博客园支持JS,没有就点击自动开通,一般需要等,着急可以给博客园发送邮件. (2)将JS脚本添加到页脚Html代码,在博客园的设置里面可以找到. 这样添加完成保存后,博客的文章就会更新目录内容

博客园添加markdown文章导航栏

博客园添加Markdown文章导航栏 我正在翻译Spring Framework文档,发布到博客园之后发现文章太密集,猛一看到比较懵,由于看到博客园支持自定义页面,我觉得添加一个导航栏,结构上会更加清晰一些. 所以在网上搜了搜关于添加导航栏的文章,搜到一个试了试,有些问题,所以就自己写了一个,实现功能如下: 主要搜索主页面中的h1-h6 根据1-6的级别设置字体大小和缩进宽度 滚动时页面最上方的标题对应导航将加粗 支持展开隐藏(默认隐藏,如果默认打开,就将js代码第6行display:none改