记录学习成果 : 指定图层批量偏移到当前图层
(vl-load-com)(defun c:oo (/ oo_ss ss_length temp_i ss_i_ename ename_list p1 p3 p3_nth ss_i_object oo_py_fs_str oo_py_dict_d ename_type)
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(and (not oo_py_fs_str_s) (setq oo_py_fs_str_s "n"))
(setq oo_py_fs_str (getstring (strcat "\nn/w:<" oo_py_fs_str_s ">\n")))
(if (= oo_py_fs_str "")
(setq oo_py_fs_str oo_py_fs_str_s)
(setq oo_py_fs_str_s oo_py_fs_str)
)
(if (not oo_py_dict)
(setq oo_py_dict 0))
(setq oo_py_dict_s (rtos oo_py_dict 2 4))
(setq oo_py_dict_d (getreal (strcat "\n偏移距离:<" oo_py_dict_s ">\n")))
(setq oo_ss_layer_str (cdr (assoc 8 (entget (car (entsel "\n获取图型所在图层:\n"))))))
;创建选择集oo_ss,设置图层过滤器()
(setq oo_ss (ssget (list (cons 8 oo_ss_layer_str))))
;or 判断是否需要输入偏移距离,输入则切换,无输入则保持
; (or
; (oo_py_dict)
; (setq oo_py_dict(getreal ))
; )
(if (and (/= oo_py_dict_d "") (/= oo_py_dict_d "0") (/= oo_py_dict_d 0) (/= oo_py_dict_d nil))
(setq oo_py_dict oo_py_dict_d)
)
(setq ss_length (sslength oo_ss))
(setq temp_i 0)
;偏移后置为当前图层
(command "offset" "l" "c" "" "")
;将选择集遍历赋值给ss_i_ename (ename) 取出单个图元
(repeat ss_length
(setq ss_i_ename (ssname oo_ss temp_i))
;对每个ename需要操作的内容,取出list,用于提取数据
(setq ename_list (entget ss_i_ename))
(setq ename_type (assoc 0 ename_list))
;如果是圆形(圆心y+半径)
(if (equal ename_type (cons 0 "CIRCLE"))
(progn
(if (or (= oo_py_fs_str "n") (= oo_py_fs_str "N"))
(setq oo_py_fs_center_point (cdr (assoc 10 ename_list))))
(if (or (= oo_py_fs_str "w") (= oo_py_fs_str "W"))
(setq oo_py_fs_center_point (list (car (cdr (assoc 10 ename_list))) (+ (* 2 (cdr (assoc 40 ename_list))) (cadr (cdr (assoc 10 ename_list)))))))
(command "offset" oo_py_dict ss_i_ename "_non" oo_py_fs_center_point "")
)
)
;如果是矩形(矩形中心点,y轴半高)
(if (equal ename_type (cons 0 "LWPOLYLINE"))
(progn
;p1&p3赋值
;object转换
(setq ss_i_object (vlax-ename->vla-object ss_i_ename))
(setq pl_point_i 0);;计数器赋初值
;p1/p3初始化
(setq pl_i_point (vlax-curve-getpointatparam ss_i_object 0))
(setq p1 pl_i_point)
(setq p3 pl_i_point)
(while
(setq pl_i_point (vlax-curve-getpointatparam ss_i_object (setq pl_point_i (1+ pl_point_i))));;沿曲线返回指定参数值处的点 。
;最小xy的点=p1
(and
(<= (car pl_i_point) (car p1))
(<= (cadr pl_i_point) (cadr p1))
(setq p1 (list (setq p1x (car pl_i_point)) (setq p1y (cadr pl_i_point))))
)
;最大xy的点=p3
(and
(>= (car pl_i_point) (car p3))
(>= (cadr pl_i_point) (cadr p3))
(setq p3 (list (setq p3x (car pl_i_point)) (setq p3y (cadr pl_i_point))))
)
)
;矩形中心点
;矩形半高 (/ (- p1y p3y) 2)
(if (or (= oo_py_fs_str "n") (= oo_py_fs_str "N"))
(setq oo_py_fs_center_point
(list
(+ p3x (* -1 (/ (- p3x p1x) 2)))
(+ p3y (* -1 (/ (- p3y p1y) 2)))))
)
(if (or (= oo_py_fs_str "w") (= oo_py_fs_str "W"))
(setq oo_py_fs_center_point (list (+ p3x (* (- p3x p1x) 2)) (+ p3y (* (- p3y p1y) 2))))
;(PRINC (list "\NW里面的偏移点:" oo_py_fs_center_point "\N点表:" (CONS (+ p3x (* (- p3x p1x) 2)) (+ p3y (* (- p3y p1y) 2))) "\n点表里面的参数:" (+ p3x (* (- p3x p1x) 2)) (+ p3y (* (- p3y p1y) 2))))
)
; (PRINC (LIST "\np1:" p1 "\np2:" p3 "\n偏移方式:" oo_py_fs_str "\n目标点:" oo_py_fs_center_point))
(command-s "offset" oo_py_dict ss_i_ename "_non" oo_py_fs_center_point "")
)
(princ)
)
;矩形判断-结束
;(subst (cons 8 (getvar "clayer")) (assoc 8 (entget (entlast))) (entget (entlast)))
(setq temp_i (+ 1 temp_i))
)
;清除选择集
(setq oo_ss nil)
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
)
这命名方式,不像是手打的 liuhe 发表于 2024-2-7 11:58
这命名方式,不像是手打的
写长点自己认得,太简化了自己记不清他是干嘛用的 学习了,谢谢分享
页:
[1]