明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2156|回复: 7

外国 lisp 实例,求助修改

[复制链接]
发表于 2005-1-2 15:01:00 | 显示全部楼层 |阅读模式
原文: ;; Save System Varibles
(defun SSV (savelist)
(mapcar
'(lambda (sysvar)
(list sysvar (getvar sysvar))
)
savelist)
)
(setq lista '("blipmode" "cecolor" "clayer" "cmdecho"
"orthomode" "osmode" "snapmode")) ;; Reset System Varibles
(defun RSV (savelist)
(mapcar
'(lambda (sysvar)
(setvar (car sysvar)(cadr sysvar))
(car sysvar)
)
savelist)
) ;; Error handler
(defun err ()
(command ".undo" "mark")
(setq olderr *error*)
(defun *error* (errstr)
(print errstr)(princ)
(setq lista (RSV lista))
(setq *error* olderr)
(princ)
)
(setq lista (SSV lista))
(setvar "blipmode" 0)
(setvar "cmdecho" 0)
(setvar "orthomode" 0)
(setvar "snapmode" 0)
) (defun reset ()
(setq lista (RSV lista))
(setq *error* olderr)
) ;; GetMidpoint routine
(defun gm ( / lst lpt1 lpt2 mx my midp )
(setq lst (entget (entlast)))
(setq lpt1 (cdr (assoc 10 lst)))
(setq lpt2 (cdr (assoc 11 lst)))
(setq lpt1 (car (list lpt1 lpt2)))
(setq lpt2 (cadr (list lpt1 lpt2)))
(setq mx (* (+ (nth 0 lpt1) (nth 0 lpt2)) 0.5))
(setq my (* (+ (nth 1 lpt1) (nth 1 lpt2)) 0.5))
(setq midp (list mx my))
) ;; Main Defun
(defun win ( / cl ce pb ap line1 pt#1 pt#2 pt#3 pt#4 pm#1 pm#2 pm#3 pm#4
ang1 ang2 wan1 wan2 jm#1 jm#2 mp#1 mp#2 i# mdst fstm nxtm
ml#1 gp#1 gp#2 cla tla l70) (setq cl (getvar "clayer")
ce (getvar "cecolor")
) ;; Save variables for next time
(if (not wsz) (setq wsz *wsz) (setq *wsz wsz))
(if (not mlx) (setq mlx *mlx) (setq *mlx mlx))
(if (not mly) (setq mly *mly) (setq *mly mly))
(if (not lit) (setq lit *lit) (setq *lit lit)) ;; Find the wall points (setq line1 (entsel "\nSelect first wall line to be opened: ")
pt#1 (nth 1 line1))
(setvar "osmode" 128)
(setq pt#2 (getpoint pt#1 "\nSelect opposite face to be opened: ")
ang1 (angle pt#1 pt#2)
ang2 (angle pt#2 pt#1))
(setvar "osmode" 0)
(cond
((= lmr "Left") (setq wan1 (+ ang1 1.5708)
wan2 (+ ang2 1.5708)))
((= lmr "Right") (setq wan1 (+ ang1 4.71239)
wan2 (+ ang2 4.71239)))
((= lmr "Middle") (setq wang (+ ang1 1.5708)
pt#1 (polar pt#1 wang (* wsz 0.5))
pt#2 (polar pt#2 wang (* wsz 0.5))
wan1 (+ ang1 4.71239)
wan2 (+ ang2 4.71239)))
)
(setq pt#3 (polar pt#1 wan1 wsz)
pt#4 (polar pt#2 wan1 wsz)
mp#1 (polar pt#1 wan1 (* wsz 0.5))
mp#2 (polar pt#2 wan1 (* wsz 0.5))
) ;; Cut the opening
(setq l1_list (entget (car line1)))
(setvar "clayer" (cdr (assoc 8 l1_list)))
(cond
((setq c_list (assoc 62 l1_list))
(setq color (cdr cr_list))
(command ".color" color)
)
) ;; Check for locked layer
(setq cla (getvar "clayer")
tla (tblsearch "layer" cla)
l70 (cdr (assoc 70 tla))
)
(if (= l70 68)
(command "layer" "unlock" cla "")
) (command ".break" pt#1 pt#3 ".break" pt#2 pt#4)
(setvar "osmode" 512)
(command ".line" pt#1 pt#2 "")
(setq jm#1 (gm))
(command ".line" pt#3 pt#4 "")
(setq jm#2 (gm)) (if (= l70 68)
(command "layer" "lock" cla "")
)
(setvar "clayer" cl)
(setvar "cecolor" ce)
(setvar "osmode" 0) ;; Build the mullions
(setq pm#1 (polar jm#1 ang1 (* mly 0.5))
pm#2 (polar pm#1 wan1 mlx)
pm#3 (polar pm#2 ang2 mly)
pm#4 (polar pm#3 wan2 mlx)
jm#1 (polar pm#2 ang2 (* mly 0.5))
)
(command ".pline" pm#1 pm#2 pm#3 pm#4 "close")
(setq ml#1 (entlast)) ;; Build the rest of the mullions & glass
(setq i# 0
mdst (/ (- wsz mlx) lit)
fstm (polar jm#1 wan2 (* mlx 0.5))
nxtm (polar fstm wan1 mdst)
gp#1 (polar fstm wan1 (* mlx 0.5))
gp#2 (polar nxtm wan2 (* mlx 0.5))
) (While (< i# lit)
(command "copy" "single" ml#1 fstm nxtm )
(setq ml#1 (entlast))
(command "line" gp#1 gp#2 "")
(setq fstm nxtm
nxtm (polar fstm wan1 mdst)
gp#1 (polar fstm wan1 (* mlx 0.5))
gp#2 (polar nxtm wan2 (* mlx 0.5)) )
(Setq i# (1+ i#))
) ) ;; --Command line functions-- (defun c:win ( / aslu lmr wsz lit mlx mly ) (err)
(initget "Left Middle Right")
(setq aslu (getvar "lunits")
lmr (getkword "\nInsertion point Left, Middle or <Right>: "))
(if (= lmr nil)
(setq lmr "Right")
) ;; Window size
(if (not *wsz) (setq *wsz 48.0))
(princ "\nEnter size of window opening <")
(princ (rtos *wsz aslu))
(setq wsz (getdist ">: ")) ;; Number of Windows
(if (not *lit) (setq *lit 1))
(princ "\nEnter number of window lites <")
(princ *lit)
(initget 6)
(setq lit (getint ">: ")) ;; Mullion size
(if (not *mlx) (setq *mlx 2.0))
(if (not *mly) (setq *mly 4.0))
(princ "\nEnter length of mullion <")
(princ (rtos *mlx aslu))
(setq mlx (getdist ">: "))
(princ "\nEnter size of window opening <")
(princ (rtos *mly aslu))
(setq mly (getdist ">: "))
(win)
(reset)
(princ)
) ;原文结束 希望绘制窗子的pt#1时候能够确定在某一个具体的位置,比如在距离这条线与其他线的焦点后者这条线的端点有n个单位远的位置。
 楼主| 发表于 2005-1-2 15:29:00 | 显示全部楼层
图片在这里 请高手指点。 更多外国lisp 欢迎交流。 电邮或雅虎通 mrhdf@yahoo.com.cn
 楼主| 发表于 2005-1-2 15:30:00 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2005-1-4 10:13:00 | 显示全部楼层
;;;自编的中点插窗,大家分享。再帮忙改进一下。 ;;;中点插窗,由此生成的窗为非块实体,可以直接拉伸
(defun c:CC (/ angd angb cmdech osm la rmode pt1 pt2 ss1 ss2 wall1
wall2 ang dist pt3 pt4 pt5 pt6 lt3 lt4 lt5 lt6)
(setq angd (getvar "angdir"))
(setq angb (getvar "angbase"))
(setq cmdech (getvar "CMDECHO"))
(setq osm (getvar "osmode"))
(SETQ LA (getvar "clayer"))
(setq rmode (getvar "regenmode"))
(setvar "regenmode" 1)
(setvar "CMDECHO" 0)
(setvar "angdir" 0)
(setvar "angbase" 0)
(setq no12 (@User2 1 "" "\n输入窗宽度:" no12))
(command "-layer" "m" "门窗" "c" "4" "门窗" "l" "continuous" "" "")
(setvar "clayer" "墙体")
(setvar "osmode" 34)
(command "-layer" "f" "轴线" "")
(while
(setq pt1 (getpoint "\n输入第一条墙线的中点:"))
(setvar "osmode" 160)
(setq pt2 (getpoint pt1 "\n输入第二条墙线的插入点:"))
(command "-layer" "t" "轴线" "")
(setvar "osmode" osm)
(setvar "clayer" LA)
(command "_.undo" "be")
(setvar "osmode" 0)
(setq ss1 (ssget pt1)
ss2 (ssget pt2)
)
(setq wall1 (ssname ss1 0)
wall2 (ssname ss2 0)
)
(setq ang (angle pt1 pt2)
dist1 (distance pt1 pt2)
)
(setq pt3 (polar pt1 (+ ang (/ pi 2)) (/ no12 2))
pt4 (polar pt2 (+ ang (/ pi 2)) (/ no12 2))
pt5 (polar pt1 (- ang (/ pi 2)) (/ no12 2))
pt6 (polar pt2 (- ang (/ pi 2)) (/ no12 2))
)
(setq lt3 (polar pt3 ang (- (/ dist1 2) 30))
lt4 (polar pt4 ang (- 30 (/ dist1 2)))
lt5 (polar pt5 ang (- (/ dist1 2) 30))
lt6 (polar pt6 ang (- 30 (/ dist1 2)))
)
(setvar "clayer" "墙体")
(command "_.line" pt3 pt4 "")
(command "_.line" pt5 pt6 "")
(command "_.break" wall1 pt3 pt5)
(command "_.break" wall2 pt4 pt6)
(setvar "clayer" "门窗")
(command "_.line" pt3 pt5 "")
(command "_.line" pt4 pt6 "")
(command "_.line" lt3 lt5 "")
(command "_.line" lt4 lt6 "")
(command "-layer" "f" "轴线" "")
(setvar "osmode" 34)
(command "_.undo" "e")
)
(command "-layer" "t" "轴线" "")
(princ)
(setvar "angdir" angd)
(setvar "angbase" angb)
(setvar "CMDECHO" cmdech)
(setvar "osmode" osm)
(setvar "clayer" LA)
(setvar "regenmode" rmode)
(princ "\n76067133@qq.com")
)
(defun @User2 (bit kwd msg def / inp)
(if def
(setq msg (strcat "\n" msg "<" (rtos def 2) ">: ")
bit (* 2 (fix (/ bit 2))))
(setq msg (strcat "\n" msg ": ")))
(initget bit kwd)
(setq inp (getreal msg))
(if inp inp def)
)
 楼主| 发表于 2005-1-5 13:04:00 | 显示全部楼层
大侠你这个不错       


我也想自己建立门窗的lisp,正在学习中。


我用你的cc的时候被拒绝         [U]utoCAD 变量设置被拒绝: "clayer" "墙体"[/U]


最好绘制图元时候可以创建图层,如果不行创建到但前途层也可以。


                                         (COMMAND "LAYER" "M" "WINDOW" "C" "YELLOW" "" "")


       


这句可以创建一个新的图层
发表于 2005-1-5 14:21:00 | 显示全部楼层
(setvar "clayer" "墙体")
楼上的你把这儿的“墙体”改成你自己的墙体图层就可,"轴线" 改成你自己的图中轴线所对应的图层就行。其他的不用改。
发表于 2005-1-6 00:42:00 | 显示全部楼层
  1. ;;;自编的中点插窗,大家分享。再帮忙改进一下。
  2. ;;;中点插窗,由此生成的窗为非块实体,可以直接拉伸
  3. (defun c:win (/       angd   angb   cmdech       osm   la       rmode pt1
  4.            pt2     ss1   ss2     wall1 wall2 ang   dist   pt3     pt4
  5.            pt5     pt6   lt3     lt4     lt5     lt6
  6.          )
  7.    (setq angd (getvar "angdir"))
  8.    (setq angb (getvar "angbase"))
  9.    (setq cmdech (getvar "CMDECHO"))
  10.    (setq osm (getvar "osmode"))
  11.    (SETQ LA (getvar "clayer"))
  12.    (setq rmode (getvar "regenmode"))
  13.    (setvar "regenmode" 1)
  14.    (setvar "CMDECHO" 0)
  15.    (setvar "angdir" 0)
  16.    (setvar "angbase" 0)
  17.    (setq no12 (@User2 1 "" "\n输入窗宽度" no12))
  18.    ;(command "-layer" "m"  "门窗" "c" "4" "门窗" "l" "continuous" "" "")
  19.    (mkla"门窗"4)
  20.    (mkla"墙体"2)
  21.    (mkla"轴线"1)
  22.    ;(setvar "clayer" "墙体")
  23.    (setvar "osmode" 34)
  24.    (command "-layer" "f" "轴线" "")
  25.    (while
  26.        (setq pt1 (getpoint "\n输入第一条墙线的中点:"))
  27.          (setvar "osmode" 160)
  28.          (setq pt2 (getpoint pt1 "\n输入第二条墙线的插入点:"))
  29.          (command "-layer" "t" "轴线" "")
  30.          (setvar "osmode" osm)
  31.          (setvar "clayer" LA)
  32.          (command "_.undo" "be")
  33.          (setvar "osmode" 0)
  34.          (setq ss1 (ssget pt1)
  35.        ss2 (ssget pt2)
  36.          )
  37.          (setq wall1 (ssname ss1 0)
  38.        wall2 (ssname ss2 0)
  39.          )
  40.          (setq ang   (angle pt1 pt2)
  41.        dist1 (distance pt1 pt2)
  42.          )
  43.          (setq pt3 (polar pt1 (+ ang (/ pi 2)) (/ no12 2))
  44.        pt4 (polar pt2 (+ ang (/ pi 2)) (/ no12 2))
  45.        pt5 (polar pt1 (- ang (/ pi 2)) (/ no12 2))
  46.        pt6 (polar pt2 (- ang (/ pi 2)) (/ no12 2))
  47.          )
  48.          (setq lt3 (polar pt3 ang (- (/ dist1 2) 30))
  49.        lt4 (polar pt4 ang (- 30 (/ dist1 2)))
  50.        lt5 (polar pt5 ang (- (/ dist1 2) 30))
  51.        lt6 (polar pt6 ang (- 30 (/ dist1 2)))
  52.          )
  53.          (setvar "clayer" "墙体")
  54.          (command "_.line" pt3 pt4 "")
  55.          (command "_.line" pt5 pt6 "")
  56.          (command "_.break" wall1 pt3 pt5)
  57.          (command "_.break" wall2 pt4 pt6)
  58.          (setvar "clayer" "门窗")
  59.          (command "_.line" pt3 pt5 "")
  60.          (command "_.line" pt4 pt6 "")
  61.          (command "_.line" lt3 lt5 "")
  62.          (command "_.line" lt4 lt6 "")
  63.          (command "-layer" "f" "轴线" "")
  64.          (setvar "osmode" 34)
  65.          (command "_.undo" "e")
  66.    )
  67.    (command "-layer" "t" "轴线" "")
  68.    (princ)
  69.    (setvar "angdir" angd)
  70.    (setvar "angbase" angb)
  71.    (setvar "CMDECHO" cmdech)
  72.    (setvar "osmode" osm)
  73.    (setvar "clayer" LA)
  74.    (setvar "regenmode" rmode)
  75.    ;(princ "\n76067133@qq.com")
  76. )
  77. (defun @User2 (bit kwd msg def / inp)
  78.    (if def
  79.        (setq msg (strcat "\n" msg "<" (rtos def 2) ">: ")
  80.      bit (* 2 (fix (/ bit 2)))
  81.        )
  82.        (setq msg (strcat "\n" msg ": "))
  83.    )
  84.    (initget bit kwd)
  85.    (setq inp (getreal msg))
  86.    (if inp
  87.        inp
  88.        def
  89.    )
  90. )
  91. (defun mkla (name color)
  92.    (If (= (Tblsearch "layer" name) nil)
  93.        (Command "layer" "m" name "c" color name "")
  94.        (Command "layer" "t" name "s" name "c" color name "")
  95.    )
  96. )
发表于 2005-1-6 08:26:00 | 显示全部楼层
xyp1964的这个子函数不错,呵呵,可以让程序减肥好多。谢谢提示。呵呵。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-18 00:00 , Processed in 0.176690 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表