明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
123
返回列表 发新帖
楼主: 尘缘一生

庆祝明经论坛恢复,改造的Z轴归零程序,展示下

  [复制链接]
发表于 2022-2-12 11:31 | 显示全部楼层
感觉好长啊
发表于 2022-3-22 17:01 | 显示全部楼层
(defun c:zzz0 (/ s)
  (setq s (ssget))
  (zzz0 s)
)
;;Z坐标归零-------【开始】-----------------
;;----实体归零(一级)------------
(defun zero-ent (e / dxf new)
  (defun move-region-to-wcs-plan (ename / obj z)
    (setq obj (en2obj ename))
    (if (and
          (= "AcDbRegion" (vla-get-objectname obj))
          (/= 0.0 (setq z (caddr (car (get-box ename)))))
        )
      (vla-move obj (vlax-3d-point (list 0 0 z)) (vlax-3d-point (list 0 0 0)))
    )
  )
  ;;210组码处理---------------------
  (defun correct210 (ent / obj za)
    (setq obj (en2obj ent))
    (if (and (vlax-property-available-p obj 'normal t)
          (not (equal '(0 0 1) (setq za (vlax-safearray->list (vlax-variant-value (vla-get-normal obj))))))
        )
      (vl-catch-all-apply 'vla-put-normal (list obj (vlax-3d-point '(0 0 1))))
    )
  )
  ;;------------------------------------
  (defun zero-group (e)
    (cond
      ;; 处理 10-14 段,含 Z 坐标且非零组码,设置Z = 0.0
      ((and (>= (car e) 10)
         (<= (car e) 14)
         (> (length e) 3)
         (/= 0.0 (nth 3 e))
       )
        (setq c10 (1+ c10))
        (cons (car e) (list (cadr e) (caddr e) 0.0))
      )
      ;; 处理 38 段(标高属性)
      ((and (= (car e) 38) (/= 0.0 (cdr e)))
        (setq c38 (1+ c38))
        '(38 . 0.0)
      )
      ;; 其余组码原样返回
      (t e)
    )
  )
  (correct210 e) ;;210组码强制转换
  (setq dxf (entget e))
  (if (= (cdr (assoc 0 dxf)) "REGION")
    (move-region-to-wcs-plan e)
    (progn
      (setq new (mapcar 'zero-group dxf))
      (if (not (equal dxf new))
        (entmod new)
      )
    )
  )
  new
)
;;选择集归零---------(一级)------------------
(defun zzz0 (ss / c10 c38 dxf ent i len cmd)
  (setq len (sslength ss) i 0 c10 0 c38 0 cmd (getvar "cmdecho"))
  (_Undo1)
  (repeat len
    (setq ent (ssname ss i))
    (if (or (and (= (dxf1 ent 0) "ELLIPSE") (/= (dxf1 ent 41) 0)) ;椭圆弧BUG,采用二次归零处理
          (and (= (dxf1 ent 0) "ARC") (/= (dxf1 ent 370) nil))    ;370组码存在
        )
      (progn
        (princ "\n 二次归零...")
        (setvar "cmdecho" 0)
        (terpri)
        (command ".ucs" "w")
        (command ".move" ent "" '(0 0 1e99) "" ".move" "p" "" '(0 0 -1e99) "")   
      )  
      (if (/= (dxf1 ent 0) "INSERT")
        (zero-ent ent)
      )
    )
    (setq i (1+ i))
  )
  (_Undo2)
  (command "_.regen")
  (princ (strcat "\n 选择的 " (itoa len) " 个对象中,\n" (itoa c10) " 个非零Z坐标, \n" (itoa c38) " 个标高被强制清零-->图元Z坐标值已全部归零"))
  (setvar "cmdecho" cmd)
)
发表于 2022-4-13 17:41 | 显示全部楼层
yuan4399 发表于 2022-3-22 17:01
(defun c:zzz0 (/ s)
  (setq s (ssget))
  (zzz0 s)

研究精神可嘉
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-1 06:45 , Processed in 0.150916 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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