明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2334|回复: 2

一个不是很好的画双线的东西,希望大侠们给点意见,谢谢

[复制链接]
发表于 2012-11-25 20:15:48 | 显示全部楼层 |阅读模式
  1. ;-----超屏幕选择对象----------;
  2. (defun feng:more:ssget ( p1 p2 filter nn / pmax pmin li )
  3.   (setq pmax (MAPCAR '+ (list nn nn 0) (MAPCAR 'max p1 p2))
  4.   pmin (MAPCAR '+ (list (- nn) (- nn) 0) (MAPCAR 'min p1 p2))
  5.   li (list '(-4 . "<or") '(-4 . "<and") '(-4 . "<") (cons 10 pmax) '(-4 . ">") (cons 10 pmin) '(-4 . "and>")
  6.      '(-4 . "<and") '(-4 . "<") (cons 11 pmax) '(-4 . ">") (cons 11 pmin) '(-4 . "and>") '(-4 . "or>")
  7.      )
  8.   )
  9.   (if filter
  10.     (ssget "x" (append filter li))
  11.     (ssget "x" li)
  12.     )
  13.   )
  14. ;--------对对象进行交点判定端点修改---------
  15. (defun feng:wall:inters:sort ( slist sname )
  16.   (princ slist)
  17.   (if (>= (length slist) 3)
  18.     (cond
  19.       ((<= (- (last (cadr slist)) (last (car slist))) 300)
  20.        (setq slist (feng:wall:inters:sort (cdr slist) sname))
  21.        (if sname (vla-put-StartPoint sname (vlax-3d-point (car (car slist)))))
  22.        )
  23.       ((<= (- (last (last slist)) (last (cadr (REVERSE slist)))) 300)
  24.        (setq slist (feng:wall:inters:sort (REVERSE (cdr (REVERSE slist))) sname))
  25.        (if sname (vla-put-EndPoint sname (vlax-3d-point (car (last slist)))))
  26.        )
  27.       )
  28.     )
  29.   slist
  30.   )
  31. ;-------对对象进行交点修剪-------------
  32. (defun feng:wall:inters:trim ( ms slist sname tt / n s1 )
  33.   (cond
  34.     ((and (null tt) (> (length slist) 3))
  35.      (if sname (vla-Erase sname))
  36.      (repeat (/ (setq n (length slist)) 2)
  37.        (vla-put-layer (vla-addline ms (vlax-3d-point (car (nth (setq n (1- n)) slist))) (vlax-3d-point (car (nth (setq n (1- n)) slist)))) "wall")
  38.        )
  39.      )
  40.     (tt
  41.      (repeat (/ (setq n (length slist)) 2)
  42.        (vla-put-layer (vla-addline ms (vlax-3d-point (car (nth (setq n (1- n)) slist))) (vlax-3d-point (car (nth (setq n (1- n)) slist)))) "wall")
  43.        )
  44.      )
  45.     )
  46.   )
  47. ;------------主执行程序------------------
  48. (defun feng:wall:inters ( ms wlist / ss n sname slist inpo ll rl inpo1 )
  49.   (setq ss (feng:more:ssget (car (car wlist)) (last (car wlist)) '((0 . "LINE") (8 . "wall")) 70000)
  50.   ll (car wlist)
  51.   rl (last wlist)
  52.   )
  53.   (if ss
  54.     (repeat (setq n (sslength ss))
  55.       (setq sname (vlax-ename->vla-object (ssname ss (setq n (1- n))))
  56.       slist (MAPCAR '(LAMBDA (x) (vlax-safearray->list (vlax-variant-value ((EVAL x) sname)))) (list 'vla-get-StartPoint 'vla-get-EndPoint))
  57.       inpo (MAPCAR '(LAMBDA (x) (apply 'inters (append x slist))) (list ll rl))
  58.       )
  59.       (if (setq inpo1 (VL-REMOVE-IF 'null inpo))
  60.   (progn
  61.     (setq slist (vl-sort (MAPCAR '(LAMBDA (x) (list x (vlax-curve-getDistAtPoint sname x))) (append slist inpo1)) '(LAMBDA (x y) (<= (last x) (last y))))
  62.     slist (vl-remove-if '(LAMBDA (x) (null (last x))) slist)
  63.     )
  64.     (if (>= (length slist) 3) (feng:wall:inters:trim ms (setq slist (feng:wall:inters:sort slist sname)) sname nil))
  65.     (setq wlist (MAPCAR 'cons (MAPCAR '(LAMBDA (x y) (if x y nil))
  66.               (MAPCAR '(LAMBDA (x) (if (vl-remove-if 'null (MAPCAR '(LAMBDA (y) (EQUAL x y)) (MAPCAR 'car slist))) t nil)) inpo)
  67.               inpo
  68.               )
  69.             wlist))
  70.     )
  71.   )
  72.       )
  73.     )
  74.   (setq wlist (MAPCAR '(LAMBDA (x)
  75.        (vl-sort x '(LAMBDA (y z) (<= (last y) (last z))))
  76.        )
  77.           (MAPCAR '(LAMBDA (x y) (MAPCAR '(LAMBDA (z) (list z (DISTANCE z y))) x)) (MAPCAR '(LAMBDA (x) (VL-REMOVE-IF 'null x)) wlist) (list (car ll) (car rl)))
  78.           )
  79.   )
  80.   (MAPCAR '(LAMBDA (x) (feng:wall:inters:trim ms (feng:wall:inters:sort x nil) nil t)) wlist)
  81.   )
  82. ;-----------------对角点进行判定---------(有点问题,缩小到一定程度后就不正确)
  83. (defun feng:wall:point:inters ( ss polist po / n interslist templist s1 )
  84.   (cond
  85.     ((null ss) nil)
  86.     ((ssget po '((0 . "LINE") (8 . "wall"))) t)
  87.     ((progn
  88.        (repeat (setq n (sslength ss))
  89.    (setq s1 (entget (ssname ss (setq n (1- n))))
  90.          templist (list (cdr (assoc 10 s1)) (cdr (assoc 11 s1)))
  91.          interslist (cons (apply 'inters (append polist templist)) interslist)
  92.          )
  93.    )
  94.        (VL-REMOVE-IF 'null interslist)
  95.        ) t
  96.      )
  97.     (t nil)
  98.     )
  99.   )
  100. ;------------对角点周边的对象进行提前修改,以便进行超屏幕选择时对象有效--------------
  101. (defun feng:wall:point:trim ( ss temppoint plist1 plist2 po / n sname tempinters linepoint )
  102.   (repeat (setq n (sslength ss))
  103.     (setq sname (ssname ss (setq n (1- n)))
  104.     linepoint (list (cdr (assoc 10 (entget sname))) (cdr (assoc 11 (entget sname))))
  105.     )
  106.     (if (and (apply 'inters (append linepoint temppoint))
  107.        (null (apply 'inters (append linepoint plist1)))
  108.        )
  109.       (progn
  110.   (setq tempinters (apply 'inters (REVERSE (cons 'nil (append linepoint plist2)))))
  111.   (if (< (DISTANCE (car linepoint) tempinters) (DISTANCE (last linepoint) tempinters))
  112.     (vla-put-StartPoint (vlax-ename->vla-object sname) (vlax-3d-point tempinters))
  113.     (vla-put-EndPoint (vlax-ename->vla-object sname) (vlax-3d-point tempinters))
  114.     )
  115.   (setq po tempinters)
  116.   )
  117.       )
  118.     )
  119.   po
  120.   )
  121. ;----------------对角点周边对象进行提前修改的主执行程序--------------------
  122. (defun feng:wall:point ( p1 p2 lw rw / ang ll rl ss1 ss2 )
  123.   (setq ang (angle p1 p2)
  124.   ll (MAPCAR 'POLAR (list p1 p2) (MAPCAR '+ (list (/ pi 2) (/ pi 2)) (list ang ang)) (list lw lw))
  125.   rl (MAPCAR 'POLAR (list p1 p2) (MAPCAR '+ (list (/ pi 2) (/ pi 2)) (list ang ang)) (list rw rw))
  126.   ss1 (ssget "c" (POLAR p1 3.9 300) (POLAR p1 0.78 300) '((0 . "LINE") (8 . "wall")))
  127.   ss2 (ssget "c" (POLAR p2 3.9 300) (POLAR p2 0.78 300) '((0 . "LINE") (8 . "wall")))
  128.   )
  129.   (cond
  130.     ((and (null (feng:wall:point:inters ss1 ll (car ll))) (feng:wall:point:inters ss1 rl (car rl)))
  131.      (setq ll (list (feng:wall:point:trim ss1 (list (POLAR (car rl) ang -300) (cadr rl)) rl ll (car ll)) (last ll)))
  132.      )
  133.     ((and (null (feng:wall:point:inters ss1 rl (car rl))) (feng:wall:point:inters ss1 ll (car ll)))
  134.      (setq rl (list (feng:wall:point:trim ss1 (list (POLAR (car ll) ang -300) (cadr ll)) ll rl (car rl)) (last rl)))
  135.      )
  136.     )
  137.   (cond
  138.     ((and (null (feng:wall:point:inters ss2 ll (cadr ll))) (feng:wall:point:inters ss2 rl (cadr rl)))
  139.      (setq ll (list (car ll) (feng:wall:point:trim ss2 (list (car rl) (POLAR (last rl) ang 300)) rl ll (last ll))))
  140.      )
  141.     ((and (null (feng:wall:point:inters ss2 rl (cadr rl))) (feng:wall:point:inters ss2 ll (cadr ll)))
  142.      (setq rl (list (car rl) (feng:wall:point:trim ss2 (list (car ll) (POLAR (last ll) ang 300)) ll rl (last rl))))
  143.      )
  144.     )
  145.   (list ll rl)
  146.   )
  147. ;-----------------命令定义和参数传递------------------------------
  148. (defun c:hq ( / ms layers p1 p2 lw rw tt)
  149.   (setq ms (vla-get-ModelSpace (vla-get-activedocument (vlax-get-acad-object)))
  150.   layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  151.   tt t
  152.   lw 90
  153.   rw 90
  154.   )
  155.   (if (null (TBLSEARCH "LAYER" "wall")) (vla-put-color (vla-add layers "wall") 9))
  156.   (while (if (and (null p2) (null p1) tt) (setq p1 (getpoint "\n请选择墙的起点:")) tt)
  157.     (initget "w W")
  158.     (setq p2 (getpoint p1 "\n请选择墙的终点<设置墙宽-w>-左墙90,右墙90:"))
  159.     (cond
  160.       ((or (= p2 "w") (= p2 "W"))
  161.        (if (setq lw (getdist "\n请设置左墙宽度<90>:")) lw 90)
  162.        (if (setq rw (getdist "\n请设置右墙宽度<90>:")) rw 90)
  163.        )
  164.       ((null p2) (setq tt nil))
  165.       (t (feng:wall:inters ms (feng:wall:point p1 p2 lw (- rw))) (setq p1 p2))
  166.       )
  167.     )
  168.   )
===================================================================
这是一个画墙线的,采用的是超屏幕选择的,也就是说用全指定对象的判定,对象超过1000个时,会卡顿。
角点处理时,图形缩小到一定范围后就会出现角点处理不正确,很是奇怪。
===================================================================
希望各位大侠能给点建议,有没有什么优化的思路。

发表于 2012-11-25 22:42:52 | 显示全部楼层
mline不是就可以画双线?
发表于 2022-2-7 00:13:11 | 显示全部楼层
稍作修改,缩小不会出错了,但还有别的问题

本帖子中包含更多资源

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

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-14 14:31 , Processed in 0.309335 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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