[分享]类似天正电气均匀布灯的程序
总共两个lsp,lplace.lsp,undo.lsp,只能在R14里运行,不能在2007里运行,哪位能否帮忙修改一下!多谢! 受益匪浅,但无LIGHT.INI。能否分享一下? <p>;;; LPLACE.LSP made by piggy<br/>;;;<br/>;;; DESCRIPTION<br/>;;; Place and connect lights<br/>;;;<br/>;;; DATE: 12/18/98; <br/>;;;<br/>;;; HISTORY: NONE<br/>;----------------------------------------------------------------------------<br/>; GLOBALS:<br/>; light_layer -- layer of light<br/>; wire_layer -- layer of wire<br/>;----------------------------------------------------------------------------<br/>(defun lplace(/ m n insblk insang inspt olyr)<br/> (if (and (not undo_init) (equal -1 (load "undo.lsp" -1)))<br/> (progn (alert "Error:\n Cannot find UNDO.LSP.") (exit))<br/> );if<br/>;;; (err_init '("CMDECHO" "OSMODE" "BLIPMODE" "REGENMODE") T '(setq l_s nil))<br/>;;; (var_set '(("CMDECHO" 0) ("OSMODE" 0) ("BLIPMODE" 0) ("REGENMODE" 0)))<br/> (setvar "osmode" (logior (getvar "osmode") 16384));关辅捉<br/> ;; Get information<br/> <br/> (cond ((numberp light_scale)) (T (setq light_scale 1)))<br/> (cond (light_layer) (T (setq light_layer (getvar "CLAYER"))))<br/> <br/> (prompt (strcat "\n默认图层:\"" light_layer "\"。" ))<br/> (prompt (strcat "\n默认比例:\"" (rtos light_scale 2 2) "\"。"))<br/> (cond <br/> ((= (cdar (laychk light_layer)) "No")<br/> (laychk (setq light_layer (getvar "CLAYER")))<br/> (prompt (strcat "\n图层被设为当前层:\"" light_layer "\"。" ))<br/> )<br/> ); cond<br/> <br/> (while (not insblk)<br/> (initget "Layer Scale Name")<br/> (setq insblk (getkword "\n图层 L / 比例 S / 图块名 N:"))<br/> (cond <br/> ((= "Scale" insblk)<br/> (initget 6)<br/> (setq light_scale<br/> (cond ((getreal (strcat "\n请输入图块比例:<"<br/> (rtos light_scale 2 2)<br/> "> ")))<br/> (T light_scale)<br/> ); cond<br/> insblk nil<br/> ); setq<br/> )<br/> ((= "Layer" insblk)<br/> (setq olyr light_layer insblk nil)<br/> (setq light_layer (getstring (strcat "\n请选择图层:<"<br/> light_layer "> ")))<br/> (cond ((= light_layer "") (setq light_layer olyr)))<br/> (cond ((= (cdar (laychk light_layer )) "No")<br/> (setq light_layer olyr)<br/> (prompt (strcat "\n图层仍为:\"" light_layer "\"。" )))<br/> ); cond<br/> )<br/> (T<br/> (cond<br/> ((= (getvar "INSNAME") "")<br/> (setq insblk (getstring "\n请输入图块名:"))<br/> (cond ((tblsearch "BLOCK" insblk) (setvar "INSNAME" insblk))<br/> (T (setq insblk nil))); cond<br/> )<br/> (T<br/> (setq insblk (getstring (strcat "\n请输入图块名:<"<br/> (getvar "INSNAME") "> ")))<br/> (cond ((= insblk "") (setq insblk (getvar "INSNAME")))); cond<br/> (cond ((tblsearch "BLOCK" insblk) (setvar "INSNAME" insblk))<br/> (T (setq insblk nil))); cond<br/> )<br/> ); cond<br/> (cond (insblk) (T (prompt "\n无效的图块!"))); cond<br/> )<br/> ); cond<br/> ); while <br/> <br/> (setq insang (getangle "\n请输入图块的角度:<0> "))<br/> (cond ((not insang) (setq insang 0)))<br/> (setq inspt (gettrs))<br/> <br/> (setq n 0) <br/> (while (< n (length inspt)) <br/> (setq m 0)<br/> (while (< m (length (car inspt)))<br/> (apply '(lambda (iname ilayer ipoint iscale iangle)<br/> (entmake (list (cons 0 "INSERT") <br/> (cons 2 iname)<br/> (cons 8 ilayer)<br/> (cons 10 ipoint)<br/> (cons 41 iscale)<br/> (cons 42 iscale)<br/> (cons 43 iscale)<br/> (cons 50 iangle)<br/> )<br/> ); entmake <br/> ); lambda<br/> (list insblk light_layer (nth m (nth n inspt)) light_scale insang) <br/> ); apply<br/> (setq m (1+ m))<br/> ); while<br/> (setq n (1+ n))<br/> ); while<br/> <br/> (initget 1 "Yes No")<br/> (cond ((= "Yes" (getkword "\n是否需要连线 ?(Y/N) "))<br/> (connect insblk insang light_scale inspt))<br/> ); cond</p><p> (layres)<br/>;;; (err_restore)<br/> (princ)<br/>); defun lplace</p><p>(defun gettrs(/ ulpt lrpt row col inspt deltax deltay n)<br/> (initget 1)<br/> (setq ulpt (getpoint "\n请选择右上角:"))<br/> (initget 1) <br/> (setq lrpt (getcorner ulpt "\n请选择左下角:"))<br/> (grdraw ulpt (list (nth 0 lrpt) (nth 1 ulpt)) 2 1)<br/> (grdraw (list (nth 0 lrpt) (nth 1 ulpt)) lrpt 2 1)<br/> (grdraw lrpt (list (nth 0 ulpt) (nth 1 lrpt)) 2 1)<br/> (grdraw (list (nth 0 ulpt) (nth 1 lrpt)) ulpt 2 1)</p><p> (initget 7)<br/> (setq row (getint "\n请输入行数:"))<br/> (initget 7)<br/> (setq col (getint "\n请输入列数:"))<br/> (setq deltax (/ (- (car lrpt) (car ulpt)) col)<br/> deltay (/ (- (cadr ulpt) (cadr lrpt)) row)<br/> ); setq</p><p> ;; Try to find the transformer of points<br/> <br/> (repeat col<br/> ; new_first_row = (cons ((old_point) - deltax) old_first_row<br/> (cond (inspt<br/> ((lambda (x)<br/> (setq inspt (subst (cons (list (- (nth 0 (car x)) deltax) <br/> (nth 1 (car x)) <br/> (nth 2 (car x))) x) <br/> x<br/> inspt))<br/> ); lambda<br/> (car inspt))<br/> )<br/> (T<br/> (setq inspt (list (list (list (- (nth 0 lrpt) (/ deltax 2.0)) <br/> (- (nth 1 ulpt) (/ deltay 2.0))<br/> (nth 2 ulpt))))); setq<br/> )<br/> ); cond<br/> <br/> (setq n 0)<br/> (while (< n (1- row))<br/> ; new_row_information = (cons new_list old_row_information)<br/> ; or (subst new_row_information old_row_information)<br/> ; new_list = (car old_row_information) - deltay <br/> <br/> (apply<br/> '(lambda (x y)<br/> (cond ( y<br/> (setq inspt (subst (cons (list (nth 0 (car x)) <br/> (- (nth 1 (car x)) deltay)<br/> (nth 2 (car x))) y) <br/> y<br/> inspt))<br/> )<br/> (T (setq inspt (append inspt (list (cons (list (nth 0 (car x))<br/> (- (nth 1 (car x)) deltay)<br/> (nth 2 (car x)) ) y))))<br/> )<br/> ); cond<br/> ); lambda<br/> (list (nth n inspt) (nth (1+ n) inspt))<br/> )<br/> (setq n (1+ n))<br/> ); while <br/> ); repeat<br/> inspt<br/>); defun gettrs</p><p>(defun turntrs(otrs / ntrs m n) <br/> (setq n 0)<br/> (while (< n (length otrs))<br/> ((lambda (x)<br/> (setq m (1- (length x)))<br/> (while (>= m 0)<br/> (cond <br/> (ntrs<br/> ((lambda (y)<br/> (if y<br/> (setq ntrs (subst (cons (nth m x) y)<br/> y<br/> ntrs))<br/> (setq ntrs (append ntrs (list (cons (nth m x) y))))<br/> ); if<br/> ); lambda<br/> (nth (- (length x) m 1) ntrs) ; new row information<br/> )<br/> )<br/> (T (setq ntrs (list (list (nth m x)))))<br/> ); cond<br/> (setq m (1- m))<br/> ); while<br/> ); lambda<br/> (nth n otrs)<br/> )<br/> (setq n (1+ n))<br/> ); while<br/> ntrs<br/>); defun turntrs</p><p>(defun connect(insblk insang inscale inspt / fp blkinf flag temp ppair hor m n offset ) <br/> ; fetch available information of blocks<br/> ((lambda (f)<br/> (cond <br/> (f <br/> (setq fp (open f "r") temp (read-line fp))<br/> (while (and temp (not blkinf))<br/> ((lambda(x)<br/> (if (and (listp x) x)<br/> (if (= (strcase (cdr (assoc 0 x))) (strcase insblk)) <br/> (setq blkinf x))<br/> ); if<br/> ); lambda<br/> (read temp)<br/> )<br/> (setq temp (read-line fp))<br/> ); while<br/> (close fp)<br/> )<br/> (T (alert "无法打开文件 \"LIGHT.INI\" !"))<br/> ); cond <br/> ); lambda <br/> (findfile "LIGHT.INI")<br/> )<br/> <br/> (cond <br/> (blkinf<br/> (cond (wire_layer) (T (setq wire_layer (getvar "CLAYER"))))<br/> (prompt (strcat "\n默认图层:\"" wire_layer "\"。" ))<br/> (cond <br/> ((= (cdar (laychk wire_layer)) "No")<br/> (laychk (setq wire_layer (getvar "CLAYER")))<br/> (prompt (strcat "\n图层被设为当前层:\"" wire_layer "\"。" ))<br/> )<br/> ); cond<br/> <br/> (while (not flag)<br/> (initget 1 "Layer Hor Ver")<br/> (setq flag (getkword "\n图层 L / 垂直 V / 水平 H:"))<br/> (cond <br/> ((= "Layer" flag)<br/> (setq temp wire_layer flag nil)<br/> (setq wire_layer (getstring (strcat "\n请选择图层:<"<br/> wire_layer "> ")))<br/> (cond ((= wire_layer "") (setq wire_layer temp)))<br/> (cond <br/> ((= (cdar (laychk wire_layer )) "No")<br/> (setq wire_layer temp)<br/> (prompt (strcat "\n图层仍为:\"" wire_layer "\"。" ))<br/> )<br/> ); cond<br/> )<br/> ((= "Hor" flag) (setq hor T))<br/> ((= "Ver" flag) (setq inspt (turntrs inspt)) (setq hor nil))<br/> ); cond<br/> ); while <br/> <br/> (setq offset '(1 2 3 4))<br/> (repeat (fix (+ (/ (* insang 2) pi) 0.1)) ; Ajust offset according<br/> (setq offset (reverse (cdr (reverse (cons (last offset) offset))))) ; to angle<br/> ); repeat </p><p> (setq offset<br/> (mapcar<br/> '(lambda (x)<br/> (cdr (assoc x blkinf))<br/> ); lambda<br/> (cond (hor (list (nth 0 offset) (nth 2 offset))) <br/> (T (list (nth 1 offset) (nth 3 offset)))) ; cond<br/> ); mapcar<br/> ); setq<br/> (setq offset (list (* inscale (nth 0 offset)) (* -1 inscale (nth 1 offset))))<br/> <br/> ((lambda (y)<br/> (cond (hor (setq m 0)) (T (setq m 1))); cond<br/> (cond<br/> ((> (nth m (nth 0 y)) (nth m (nth 1 y))) <br/> (setq offset (mapcar '(lambda (x)<br/> (* -1.0 x)<br/> ); lambda<br/> offset<br/> ); mapcar<br/> ); setq<br/> )<br/> ); cond<br/> ); lambda<br/> (car inspt))<br/> <br/> (mapcar <br/> '(lambda (x)<br/> (setq m 0)<br/> (while (< m (1- (length x)))<br/> (setq ppair <br/> (mapcar <br/> '(lambda (x dx)<br/> (cond (hor (list (+ (nth 0 x) dx) (nth 1 x) (nth 2 x)))<br/> (T (list (nth 0 x) (+ (nth 1 x) dx) (nth 2 x)))<br/> ); cond<br/> ); lambda<br/> (list (nth m x) (nth (1+ m) x)) offset<br/> ); mapcar <br/> ); setq<br/> (apply '(lambda (llayer spoint epoint)<br/> (entmake (list (cons 0 "LINE") <br/> (cons 8 llayer)<br/> (cons 10 spoint)<br/> (cons 11 epoint)<br/> )<br/> ); entmake <br/> ); lambda<br/> (list wire_layer (car ppair) (cadr ppair)) <br/> ); apply<br/> (setq m (1+ m))<br/> ); while<br/> ); lambda<br/> inspt<br/> ); mapcar<br/> )<br/> (T (alert "该图块未被正确配置!"))<br/> ); cond<br/>); defun connect</p><p>(defun c:lp() (lplace))<br/>(defun c:lplace() (lplace))<br/></p> 多谢版主,这下我又可以很顺利的画图了!不知道是哪里修改了呢,能否告知啊? 主要程序开头是那些置程序运行前的一些系统变量(关捕捉之类的)那一两个涵数,到了高版本就水土不服,所以改一下就好了. <p>试了一下还不错,只是图块的选择如果增加框选为默认,其他三个选项为备选,使用上会更方便;还有捕捉关闭后框选区域会比较麻烦,而且步骤好像多了点;完成后亮选没有取消;希望能改进下</p> BDYCAD发表于2007-12-8 14:57:00static/image/common/back.gif主要程序开头是那些置程序运行前的一些系统变量(关捕捉之类的)那一两个涵数,到了高版本就水土不服,所以改一下就好了.<p></p>确实有这些问题,不过我不会编程,希望版主帮忙改改吧,再次多谢! <p>楼主花了多长时间啊</p><p></p> jxw221发表于2007-12-15 20:57:00static/image/common/back.gif楼主花了多长时间
程序不是我编的,是同事编的,估计应该花了不少时间哦! 谢谢,受益很多啊 谢谢,受益很多啊
页:
[1]
2