明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2988|回复: 13

怎么得到用ssget选择的物体的最边界点

  [复制链接]
发表于 2003-8-28 15:59:00 | 显示全部楼层 |阅读模式
怎么得到用ssget选择的物体的最边界点
发表于 2003-8-28 16:07:00 | 显示全部楼层
看看这个帖子讨论,
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=8747
 楼主| 发表于 2003-8-28 20:12:00 | 显示全部楼层
谢谢!
 楼主| 发表于 2003-8-30 19:30:00 | 显示全部楼层
我发现那个程序对我上传的情况不适合,不知能否改进?
 楼主| 发表于 2003-8-30 19:32:00 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2003-8-31 14:30:00 | 显示全部楼层
这样的规则图形应该很容易获得吧,
 楼主| 发表于 2003-8-31 19:21:00 | 显示全部楼层
哦,我是说上次看的那个"maxmin.lsp"对此图形抓取不到其边界点
发表于 2003-9-1 09:59:00 | 显示全部楼层
在哪儿?
发表于 2003-9-1 11:03:00 | 显示全部楼层

回复

弧段的中心及半径信息也可以得到吧,那样也可以计算.
 楼主| 发表于 2003-9-1 12:00:00 | 显示全部楼层
;;
;; trap run-time error.
;;
(defun ai_error (errmsg)
   (if (not (member errmsg '("console break" "Function Cancelled"
        "bad argument type" "Function cancelled" "no function definition: DOS_GETPROGRESS"
          "bad argument" "函数被取消" "quit / exit abort"))
      ) ;_ end of not
      (princ (strcat "\nError: " errmsg))
   )
   (princ)
);_defun

;;
;; Get all nodes of the LWPolyline, Polyline.
;;
(defun GetListOfPline (EntityName / SSE_Pline N newEntityName)
(setq SSE_Pline (entget EntityName))
(setq LastList nil)
(if (= (cdr (assoc 0 SSE_Pline)) "LWPOLYLINE")
    (progn
      (setq LastList (LIST (LIST 0 0)))
      (setq N 0)
      (while (/= (nth N SSE_Pline) nil)
             (if (= (car (nth N SSE_Pline)) 10)
                 (setq LastList (append LastList (list (list (cadr (nth N SSE_Pline)) (caddr (nth N SSE_Pline)) )) ))
             )
             (setq N (+ N 1))
      )
      (setq LastList (cdr LastList))
    )
)
(if (= (cdr (ASSOC 0 SSE_Pline)) "OLYLINE")
    (PROGN
      (setq LastList (list (list 0 0)))
      (setq newEntityName (entnext EntityName))
      (while (= (cdr (assoc 0 (entget newEntityName))) "VERTEX")
             (setq LastList (append LastList (list (list (cadr (assoc 10 (entget newEntityName))) (caddr (assoc 10 (entget newEntityName))) ))))
             (setq newEntityName (entnext newEntityName))
      )
      (setq LastList (cdr LastList))
    )
)
(setq LastList LastList)
);_defun

;;
;; main function
;;
(defun c:maxmin ( / old_cmd old_osm sel_set i pt_list rad cen x0 y0 pt_minx pt_miny pt_maxx pt_maxy cen_x cen_y ret_val)
  (setq old_cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq old_osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq old_error  *error*                ; save current error function
        *error* ai_error                ; new error function
  )
  (prompt "\nSelect entity:")
  (setq sel_set (ssget))
  (if sel_set
    (progn
      (setq i 0)
      (repeat (sslength sel_set)
        (setq ent_name (ssname sel_set i))
        (setq ent_list (entget ent_name))
        (cond
          ((or (= (cdr (assoc 0 ent_list)) "LWPOLYLINE")(= (cdr (assoc 0 ent_list)) "OLYLINE"))
           (setq pt_list (append pt_list (GetListOfPline ent_name)))
          )
          ((= (cdr (assoc 0 ent_list)) "CIRCLE")
           (setq rad (cdr (assoc 40 ent_list)))
           (setq cen (cdr (assoc 10 ent_list)))
           (setq x0 (car cen)
                 y0 (cadr cen)
                 )
           (setq pt_list (append pt_list (list (list (- x0 rad) (+ y0 rad))(list (+ x0 rad) (- y0 rad)))))
          )
          (t)
        );_cond
        (setq i (+ i 1))
      );_repeat
      (if pt_list
        (progn
          (setq pt_minx (apply 'min (mapcar 'car pt_list))
                pt_miny (apply 'min (mapcar 'cadr pt_list))
                pt_maxx (apply 'max (mapcar 'car pt_list))
                pt_maxy (apply 'max (mapcar 'cadr pt_list))
                cen_x (/ (+ pt_minx pt_maxx) 2)
                  cen_y (/ (+ pt_miny pt_maxy) 2)
          )
          (setq ret_val (list (cons "10" (list pt_minx pt_miny))
                              (cons "11" (list pt_maxx pt_maxy))
                              (cons "cen" (list cen_x cen_y))
                        )
          )
        )
        (princ "\nNo 'Polyline' or 'Circle' entity!")
      );_if
    );_progn
    (alert "No entities selected!")
  );_if
  
  ; Draw a rectangle to mark the range of the selected entities( Pline or Circle).
  (if (and ret_val (/= (cdr (car ret_val)) (cdr (cadr ret_val))))
    (progn
      (command "rectang" (cdr (car ret_val)) (cdr (cadr ret_val)) 3)
    )
  );_if
  
  (setvar "cmdecho" old_cmd)
  (setvar "osmode" old_osm)
  (setq *error* old_error)
  (princ)
  ret_val        ;return list.
);_defun

以上是上次从“王咣生”那里下载的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-2 18:29 , Processed in 0.194884 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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