明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1768|回复: 9

[求助]请高手帮忙,编个小程序

[复制链接]
发表于 2006-3-29 17:56 | 显示全部楼层 |阅读模式

我想保留"-bhatch"命令的特性和选择功能,绘制一个填充图案,并将其加入到另一个特定图层,最后返回一开始的图层。

我搞了半天也搞不出来
;|(defun C:YJ_Tiancong ()
  (initget "s  ")
  (setq p1 (getpoint "\n指定内部点或选择(S):"))
  (cond ((= s0 "s")((princ "\n指 择(S):" )))
 ((= s0 "") nil)
        (t (cond (
  (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  (command "-BHATCH" "P" "SOLID" p1 "")
  (command "chprop" (entlast) "" "layer" "COLUFILL" ""))))
  )
  (princ)
)|;
;|

(defun C:YJ_Tiancong ()
  (setq p1 (getpoint "\n指定内部点或选择(S):")) 
  (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  (command "-BHATCH" "P" "SOLID" p1 "") 
  (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  (princ)
)
  (setq ss (ssget))
  (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  (command "-BHATCH" "P" "SOLID" "s" ss "" "") 
  (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  (princ)
  |;
(defun C:yjxd ()
  (setq ss nil n 0)
  (while (setq ss1 (getpoint "\n指定内部点或选择(S):"))
         (setq ss (cons ss1 ss)
  (setq n (+ n 1))
)
  (command "-BHATCH" "P" "SOLID" ss ""))
(while (> n 0)
  ((nth n ss)
    (setq n (- n 1)

失败!

发表于 2006-3-29 18:23 | 显示全部楼层
  1. (defun C:test ()
  2.   (setq ol (getvar "clayer"))
  3.   (command "-layer" "m" "COLUFILL" "c" "4" "COLUFILL" "")
  4.   (while (setq pt (getpoint "\n指定内部点: "))
  5.     (command "-BHATCH" "P" "SOLID" pt "")
  6.   )
  7.   (setvar "clayer" ol)
  8.   (princ)
  9. )
发表于 2006-3-29 18:32 | 显示全部楼层
  1. (defun C:yjxd ()
  2.   (if (= (tblobjname "layer" "COLUFILL") nil)
  3.     (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  4.   )
  5.   (command "-bhatch" "p" "SOLID" (getpoint "\n指定内部点"))
  6.   (while (setq point (getpoint "\n指定内部点"))
  7.     (command point)
  8.   )
  9.   (command "")
  10.   (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  11.   (princ)
  12. )
发表于 2008-6-22 13:07 | 显示全部楼层

楼上两位大侠的代码只能点选内部,不能按S就是交叉窗选对象啊。

有办法实现吗?

发表于 2008-6-23 09:24 | 显示全部楼层
楼主是否要这种效果
  1. (defun C:yjxd ( / point ss n m en ent )
  2.    (if (= (tblobjname "layer" "COLUFILL") nil)
  3.      (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  4.    )
  5.    (initget "s")
  6.    (while (setq point (getpoint "\n指定内部点(选择物体[s])"))
  7.      (cond
  8.      ((or (= point "s") (= point "S"))
  9.          (progn
  10.     (SETQ SS (SSGET '((0 . "*POLYLINE,circle,REGION"))))
  11.     (setq n 0 m (SSlength ss))
  12.       (repeat m
  13.         (setq en (ssname ss n))
  14.         (setq ent (entget en))
  15.         (IF (and (OR (= (CDR (ASSOC 0 ent)) "POLYLINE") (= (CDR (ASSOC 0 ent)) "LWPOLYLINE"))
  16.                         (= (cdr (assoc 70  ent)) 0))
  17.                        (command "change" en "" "p" "la" "0" "")
  18.           (progn
  19.            (command "-bhatch" "p" "SOLID" "s" en "" "")
  20.            (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  21.           )
  22.                )
  23.         (setq n (+ 1 n))
  24.       )
  25.     )
  26.       )
  27.        ( (= (type point) 'list)
  28.   (progn
  29.           (command "-bhatch" "p" "SOLID"  point "")
  30.           (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  31.    )
  32.        )
  33.        (t nil)
  34.    )
  35.      (initget "s")
  36.      )
  37.    (princ)
  38. )
发表于 2008-6-23 17:45 | 显示全部楼层
本帖最后由 作者 于 2008-6-23 17:48:05 编辑

非常感谢呀。。不错。

只是能不能再完善一下这个问题:byghbcx这种方式填充完是每个封闭区域相当于一个个单独的填充,我个人很喜欢这种,比如用于节点图,比我想象中完美。但有时候这样又会太碎了,填充完后如果要修改不方便,比如用于立面图或平面图等。

能不能这样:加一个开关(比如HATCHMODE),当这个开关设为“1”时就是5楼这种效果。当开关设为"2"时,填充完就是执行一次命令虽然选择的封闭区域有很多,但是一个整体的填充(就像系统内置的HATCH一样)。之所以说要加开关,是因为有很多的填充图案要做成这样“自动化处理”的,根据不同的填充图案可能要的这个效果不同。我又不懂怎么改。这样就我可以简单的改改这个开关(如:setq hatchmode 1 等)和各种填充图案的名称、比例、角度就可以行了。不会编程没办法啊。。。。不知我表达清楚了没有

能再帮帮吗?

发表于 2008-6-23 18:28 | 显示全部楼层
  1. (defun C:yjxd ( / point ss n m en ent hatchmode)
  2.   (setvar "cmdecho" 0)
  3.   (if (= (tblobjname "layer" "COLUFILL") nil)
  4.     (command "-layer" "N" "COLUFILL" "c" "9" "COLUFILL" "")
  5.   )
  6.   (setq hatchmode (getstring "\n请输入填充类型(整体[Z]/分散[F]):"))
  7.   (if (not hatchmode)
  8.     (setq hatchmode "F")
  9.   )
  10.   (initget "s")
  11.   (while (setq point (getpoint "\n指定内部点(选择物体[s])"))
  12.     (cond
  13.       ((or (= point "s") (= point "S"))
  14.        (progn
  15.   (SETQ SS (SSGET '((0 . "*POLYLINE,circle,REGION"))))
  16.   (setq n 0
  17.         m (SSlength ss)
  18.   )
  19.   (if (= (strcase hatchmode) "Z")
  20.     (command "-bhatch" "p" "SOLID" "s")
  21.   )
  22.   (repeat m
  23.     (setq en (ssname ss n))
  24.     (setq ent (entget en))
  25.     (IF (and (OR (= (CDR (ASSOC 0 ent)) "POLYLINE")
  26.    (= (CDR (ASSOC 0 ent)) "LWPOLYLINE")
  27.       )
  28.       (= (cdr (assoc 70 ent)) 0)
  29.         )
  30.       (command "change" en "" "p" "la" "0" "")
  31.       (if (= (strcase hatchmode) "F")
  32.         (progn
  33.    (command "-bhatch" "p" "SOLID" "s" en "" "")
  34.    (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  35.         )
  36.         (command en)
  37.       )
  38.     )
  39.     (setq n (+ 1 n))
  40.   )
  41.   (if (= (strcase hatchmode) "Z")
  42.     (progn (command "" "")
  43.     (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  44.     )
  45.   )
  46.        )
  47.       )
  48.       ((= (type point) 'list)
  49.        (progn
  50.   (command "-bhatch" "p" "SOLID" point "")
  51.   (command "chprop" (entlast) "" "layer" "COLUFILL" "")
  52.        )
  53.       )
  54.       (t nil)
  55.     )
  56.     (initget "s")
  57.   )
  58.   (setvar "cmdecho" 1)
  59.   (princ)
  60. )
发表于 2008-6-23 18:51 | 显示全部楼层

大侠,还有点问题:

如果是点选内部分的话,整体填充就失效,也就是说填充的还是散的

如果是按要S按选择对象的话,整体填充就是整体的。

还是那句话,感谢啊。。。

发表于 2008-6-23 20:42 | 显示全部楼层
点选后,随即填充,就是分散的
发表于 2008-6-26 08:13 | 显示全部楼层
樓主的功能Autolayer程序就可解決
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 16:24 , Processed in 0.380926 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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