明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: raimo

[资源] 预设常用填充V1.2——用LISP来快速完成常用填充

    [复制链接]
发表于 2013-12-12 09:51:22 | 显示全部楼层
很好,支持
发表于 2014-1-6 10:19:01 | 显示全部楼层
冷临梦 发表于 2013-5-8 23:01
楼主还在么?可不可以帮加句代码哪?可以实现填充至指定层(若是无指定层就新建),运行命令后,返回当前层 ...

这个应该能实现的。。但最近没空,天天在赶图纸。。下周抽空试试

这个不错,
发表于 2014-2-27 12:31:52 | 显示全部楼层
这个lsp还是很实用的,毕竟大家手头都有几个常用的填充
发表于 2014-4-12 14:53:11 | 显示全部楼层
呵呵,我改正了一下,增加了容错功能(原程序如果中途退出,图层颜色会默认设置为251,我增加了一个容错功能,即使中途退出,还是返回到随层),并增加到17个填充,当然,大家亦可以继续增加;当然还有好多不足!

;;预设常用填充H
;;V1.2      
;;增加记忆功能,提高填充的使用方便性
;;----------------------------------
(defun c:H (/ opt oldcolor *error*)
(defun *error* (msg)
(setvar "cecolor""bylayer") ;_ 恢复颜色随层;
(princ "错误信息: ")
(princ msg)      ;_ 打印错误信息
(princ)         
)
(setvar "measurement" 0)     ; 设置公制单位
(setvar "cmdecho" 0)         ; 关闭命令响应
(setvar "hpassoc" 0)         ;设置填充时不关联
(setq oldcolor (getvar "cecolor"))

(if *num_HType*
  (setq num_HType (getint (strcat "\n选择填充样式  ①砖墙 ②混凝土 ③素混凝土 ④玻璃 ⑤地砖600 ⑥地砖300 ⑦大理石 ⑧木纹 ⑨拉丝间距50 ⑩实体填充 ⑾水平胶合板 ⑿垂直胶合板 ⒀石膏板 ⒁石材 ⒂墙纸 ⒃磨砂 ⒄天花填充: <" (rtos *num_HType* 2 0) ">")))
  (setq num_HType (getint "\n选择填充样式  ①砖墙 ②混凝土 ③素混凝土 ④玻璃 ⑤地砖600 ⑥地砖300 ⑦大理石 ⑧木纹 ⑨拉丝间距50 ⑩实体填充 ⑾水平胶合板 ⑿垂直胶合板 ⒀石膏板 ⒁石材 ⒂墙纸 ⒃磨砂 ⒄天花填充: " ))
)
(if (not num_HType)
  (setq num_HType *num_HType*)
  (setq *num_HType* num_HType)
)
(setq opt num_HType)

(if (< 0 opt 18) (eval (read(strcat "(tianchong" (itoa opt) ")"))));根据选项参数执行填充样式

(if (setq ss (ssget))
  (command "bhatch" "s" ss "" "") ;如果选择集不为空,则执行对象填充
  (progn  ;如果选择集为空,则执行点选命令
  (prompt "\n请拾取填充内部点:\n")
  (command "bhatch" pause)
  (while (> (getvar "CMDACTIVE") 0) (command PAUSE))
))

(command "color" oldcolor)   ;设置为原有颜色
;;(setvar "cecolor""bylayer")  ;设置颜色随层
(princ)
)
(defun tianchong1 ()
(prompt "\n当前样式: ①砖墙 比例500\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "AN31B" "500" "0" "")
(command "color" "251")
)
(defun tianchong2 ()
(prompt "\n当前样式: ②混凝土\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "AN31C" "500" "0" "")
)
(defun tianchong3 ()
(prompt "\n当前样式: ③素混凝土\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "AN33C" "200" "0" "")
)
(defun tianchong4 ()
(prompt "\n当前样式: ④玻璃\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "AR-RROOF" "350" "45" "")
)
(defun tianchong5 ()
(prompt "\n当前样式: ⑤600x600地砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "U" "0" "600" "Y" "")
)
(defun tianchong6 ()
(prompt "\n当前样式: ⑥300x300地砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "U" "0" "300" "Y" "")
)
(defun tianchong7 ()
(prompt "\n当前样式: ⑦大理石\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "大理石" "100" "0" "")
)
(defun tianchong8 ()
(prompt "\n当前样式: ⑧木纹\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "木纹02" "30" "0" "")
)
(defun tianchong9 ()
(prompt "\n当前样式: ⑨拉丝间距50\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "U" "0" "50" "N" "")
)
(defun tianchong10 ()
(prompt "\n当前样式:  ⑩实体填充\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "SOLID" "0" "0" "")
)
(defun tianchong11 ()
(prompt "\n当前样式: ⑾水平胶合板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "胶合板" "4" "0" "")
)
(defun tianchong12 ()
(prompt "\n当前样式: ⑿垂直胶合板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "胶合板" "4" "90" "")
)
(defun tianchong13 ()
(prompt "\n当前样式: ⒀石膏板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "石膏板" "20" "0" "")
)
(defun tianchong14 ()
(prompt "\n当前样式: ⒁石材\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "石材" "50" "0" "")
)
(defun tianchong15 ()
(prompt "\n当前样式: ⒂墙纸\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "CROSS" "150" "0" "")
)
(defun tianchong16 ()
(prompt "\n当前样式: ⒃磨砂\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "DOTS" "1000" "0" "")
)
(defun tianchong17 ()
(prompt "\n当前样式: ⒄天花填充\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "ANSI33" "800" "0" "")
)
发表于 2014-9-26 10:24:46 | 显示全部楼层
嗯,试了下,楼上的不错,满足我的要求,谢谢了
发表于 2014-11-16 19:50:15 | 显示全部楼层
能否设置默认图层呢?
我加入command “.layer” 命令,好像没有用啊
发表于 2014-11-16 20:02:39 | 显示全部楼层
小毛草 发表于 2014-4-12 14:53
呵呵,我改正了一下,增加了容错功能(原程序如果中途退出,图层颜色会默认设置为251,我增加了一个容错功能 ...

能否加入填充到默认图层上,我加入command .layer语句,运行了不对
发表于 2014-11-16 21:08:15 | 显示全部楼层
可以的,这个我最终完成版,呵呵,代码有点不太完善,由高手指正!


;;预设常用填充H
;;V1.2      
;;增加记忆功能,提高填充的使用方便性
;;----------------------------------
(defun c:H (/ opt oldcolor *error*)
(defun *error* (msg)
(setvar "cecolor""bylayer") ;_ 恢复颜色随层;
(setvar "clayer" mylayer)   ;恢复原有图层
(princ "错误信息: ")
(princ msg)      ;_ 打印错误信息
(princ)         
)

(setvar "measurement" 0)     ; 设置公制单位
(setvar "cmdecho" 0)         ; 关闭命令响应
(setvar "hpassoc" 0)          ;设置填充时不关联
(setq mylayer (getvar "clayer"))    ;保存当前层
(setq oldcolor (getvar "cecolor"))   ;保存原有颜色
(if *num_HType*
  (setq num_HType (getint (strcat "\n选择填充样式  ①砖墙 ②钢筋混凝土 ③素混凝土 ④玻璃 ⑤地砖600 ⑥地砖300 ⑦大理石 ⑧木纹 ⑨拉丝间距50 ⑩实体填充 ⑾水平胶合板 ⑿垂直胶合板 ⒀石膏板 ⒁石材 ⒂墙纸 ⒃磨砂 ⒄天花填充 ⒅600X800墙面抛光砖 ⒆450x300釉面砖: <" (rtos *num_HType* 2 0) ">")))
  (setq num_HType (getint "\n选择填充样式  ①砖墙 ②钢筋混凝土 ③素混凝土 ④玻璃 ⑤地砖600 ⑥地砖300 ⑦大理石 ⑧木纹 ⑨拉丝间距50 ⑩实体填充 ⑾水平胶合板 ⑿垂直胶合板 ⒀石膏板 ⒁石材 ⒂墙纸 ⒃磨砂 ⒄天花填充 ⒅600X800墙面抛光砖 ⒆450x300釉面砖: " ))
)
(if (not num_HType)
  (setq num_HType *num_HType*)
  (setq *num_HType* num_HType)
)
(setq opt num_HType)

(if (< 0 opt 20) (eval (read(strcat "(tianchong" (itoa opt) ")"))));根据选项参数执行填充样式

(if (setq ss (ssget))
  (command "bhatch" "s" ss "" "") ;如果选择集不为空,则执行对象填充
  (progn  ;如果选择集为空,则执行点选命令
  (prompt "\n请拾取填充内部点:\n")
  (command "bhatch" pause)
  (while (> (getvar "CMDACTIVE") 0) (command PAUSE))
))

(command "color" oldcolor)   ;设置为原有颜色
;;(setvar "cecolor" "bylayer")  ;设置颜色随层

;;(setvar "color" "251")  ;设置颜色随层
(setvar "clayer" mylayer)
(princ)
)
(defun tianchong1 ()
(prompt "\n当前样式: ①砖墙 比例500\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "-bhatch" "p" "AN31B" "500" "0" "")
)
(defun tianchong2 ()
(prompt "\n当前样式: ②钢筋混凝土\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "AN31C" "500" "0" "")
)
(defun tianchong3 ()
(prompt "\n当前样式: ③素混凝土\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "AN33C" "200" "0" "")
)
(defun tianchong4 ()
(prompt "\n当前样式: ④玻璃\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
  (if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "AR-RROOF" "350" "45" "")
)
(defun tianchong5 ()
(prompt "\n当前样式: ⑤600x600地砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "U" "0" "600" "Y" "")
)
(defun tianchong6 ()
(prompt "\n当前样式: ⑥300x300地砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(command "color" "251")
(command "bhatch" "p" "U" "0" "300" "Y" "")
)
(defun tianchong7 ()
(prompt "\n当前样式: ⑦大理石\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "大理石" "100" "0" "")
)
(defun tianchong8 ()
(prompt "\n当前样式: ⑧木纹\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "木纹02" "30" "0" "")
)
(defun tianchong9 ()
(prompt "\n当前样式: ⑨拉丝间距50\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "U" "0" "50" "N" "")
)
(defun tianchong10 ()
(prompt "\n当前样式:  ⑩实体填充\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "SOLID" "0" "0" "")
)
(defun tianchong11 ()
(prompt "\n当前样式: ⑾水平胶合板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "胶合板" "4" "0" "")
)
(defun tianchong12 ()
(prompt "\n当前样式: ⑿垂直胶合板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "胶合板" "4" "90" "")
)
(defun tianchong13 ()
(prompt "\n当前样式: ⒀石膏板\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "石膏板" "30" "0" "")
)
(defun tianchong14 ()
(prompt "\n当前样式: ⒁石材\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "石材" "50" "0" "")
)
(defun tianchong15 ()
(prompt "\n当前样式: ⒂墙纸\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "CROSS" "150" "0" "")
)
(defun tianchong16 ()
(prompt "\n当前样式: ⒃磨砂\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "DOTS" "1000" "0" "")
)
(defun tianchong17 ()
(prompt "\n当前样式: ⒄天花填充\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "ANSI33" "800" "0" "")
)
(defun tianchong18 ()
(prompt "\n当前样式: ⒅800X600墙面抛光砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "800X600墙面抛光砖" "800" "0" "")
)
(defun tianchong19 ()
(prompt "\n当前样式: ⒆450x300釉面砖\n")
(prompt "\n请选择对象,跳过则为拾取内部点:\n")
(if (= (tblsearch "layer" "PUB_HATCH") nil)
    (Command "-layer" "m" "PUB_HATCH" "c" 251 "" "")
    (Command "-layer" "t" "PUB_HATCH" "")
  )
(setvar "clayer" "PUB_HATCH")
(command "bhatch" "p" "450x300釉面砖" "450" "0" "")
)
发表于 2014-11-26 23:14:17 | 显示全部楼层
感谢楼主无私奉献!!!
发表于 2014-12-20 10:54:59 | 显示全部楼层
谢谢分享!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 00:13 , Processed in 0.256218 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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