cheefeel 发表于 2024-1-10 10:52:44

求助:线偏移成一定宽度的填充,改成能批量操作

本帖最后由 cheefeel 于 2024-1-19 17:43 编辑

求助:将以下插件改成支持批量操作的。↓↓↓↓↓↓



执行命令后,输入一个宽度值,选择目标线(多段线或直线),
①若直接确定→则以目标线为中心生成指定宽度的填充
②若指定方向→则按指定方向生成填充。





;;★ 线条宽度填充 (保留对象)————————————————————————————————————————
(defun c:RV (/ d l l1 l2 l3 obj obj1 pt);;线条宽度填充(保留对象)
(setq oldlay (getvar "CLAYER"));把目前的图层记忆起来
      (setvar "cmdecho" 0)(command "undo" "be")
      (setq d (getdist "\n输入宽度:") l (car (entsel "\n选择对象:")) obj (vlax-ename->vla-object l) pt (getpoint"\n点击偏移方向 或【确定】居中:"))
      (if pt (progn (command "offset" d l "non" pt "") (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))) (progn (vla-Offset obj (* d 0.5))(setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))   (vla-Offset obj (* d -0.5)) (setq obj (vlax-ename->vla-object (setq l (entlast))))))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getEndPoint obj)) (cons 11 (vlax-curve-getEndPoint obj1)))) (setq l2 (entlast))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getstartPoint obj)) (cons 11 (vlax-curve-getstartPoint obj1))))         (setq l3 (entlast))
      (command "hatch" "p" "solid"(setq ss (ssadd) ss (ssadd l ss) ss (ssadd l1 ss) ss (ssadd l2 ss) ss (ssadd l3 ss)) "" "ERASE" (if pt (ssdel l ss) ss) "")   
      (command "change" "l" "" "p" "LA" "★819 可见线条" "")
      (command "undo" "e")(setvar "cmdecho" 1)
      (princ)
(setvar "clayer" oldlay);把刚刚记忆起来的图层→变成目前的图层
)
;;★ 线条宽度填充 (保留对象)————————————————————————————————————————
(defun c:VR (/ d l l1 l2 l3 obj obj1 pt);;线条宽度填充(保留对象)
(setq oldlay (getvar "CLAYER"));把目前的图层记忆起来
      (setvar "cmdecho" 0)(command "undo" "be")
      (setq d (getdist "\n输入宽度:") l (car (entsel "\n选择对象:")) obj (vlax-ename->vla-object l) pt (getpoint"\n点击偏移方向 或【确定】居中:"))
      (if pt (progn (command "offset" d l "non" pt "") (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))) (progn (vla-Offset obj (* d 0.5))(setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))   (vla-Offset obj (* d -0.5)) (setq obj (vlax-ename->vla-object (setq l (entlast))))))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getEndPoint obj)) (cons 11 (vlax-curve-getEndPoint obj1)))) (setq l2 (entlast))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getstartPoint obj)) (cons 11 (vlax-curve-getstartPoint obj1))))         (setq l3 (entlast))
      (command "hatch" "p" "solid"(setq ss (ssadd) ss (ssadd l ss) ss (ssadd l1 ss) ss (ssadd l2 ss) ss (ssadd l3 ss)) "" "ERASE" (if pt (ssdel l ss) ss) "")   
      (command "change" "l" "" "p" "LA" "★818 明装灯条" "")
      (command "undo" "e")(setvar "cmdecho" 1)
      (princ)
(setvar "clayer" oldlay);把刚刚记忆起来的图层→变成目前的图层
)
;;★ 线条宽度填充 (到当前层)(移除对象)————————————————————————————————————————
(defun c:RVV (/ d l l1 l2 l3 obj obj1 pt);;偏移填充->删除边线和原对象
(setq oldlay (getvar "CLAYER"));把目前的图层记忆起来
      (setvar "cmdecho" 0)(command "undo" "be")
      (setq d (getdist "\n输入宽度:") l (car (entsel "\n选择对象:")) obj (vlax-ename->vla-object l) pt (getpoint"\n点击偏移方向 或【确定】居中:"))
      (if pt (progn (command "offset" d l "non" pt "") (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))) (progn (vla-Offset obj (* d 0.5))(setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))   (vla-Offset obj (* d -0.5)) (vla-Delete obj) (setq obj (vlax-ename->vla-object (setq l (entlast))))))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getEndPoint obj)) (cons 11 (vlax-curve-getEndPoint obj1)))) (setq l2 (entlast))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getstartPoint obj)) (cons 11 (vlax-curve-getstartPoint obj1))))         (setq l3 (entlast))
      (command "hatch" "p" "solid"l l1 l2 l3 "" "ERASE" l l1 l2 l3 "")
      (command "change" "l" "" "p" "LA" "★819 可见线条" "")
      (command "undo" "e")(setvar "cmdecho" 1)
      (princ)
(setvar "clayer" oldlay);把刚刚记忆起来的图层→变成目前的图层
)
;;★ 线条宽度填充 (到当前层)(移除对象)————————————————————————————————————————
(defun c:VRR (/ d l l1 l2 l3 obj obj1 pt);;偏移填充->删除边线和原对象
(setq oldlay (getvar "CLAYER"));把目前的图层记忆起来
      (setvar "cmdecho" 0)(command "undo" "be")
      (setq d (getdist "\n输入宽度:") l (car (entsel "\n选择对象:")) obj (vlax-ename->vla-object l) pt (getpoint"\n点击偏移方向 或【确定】居中:"))
      (if pt (progn (command "offset" d l "non" pt "") (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))) (progn (vla-Offset obj (* d 0.5))(setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))   (vla-Offset obj (* d -0.5)) (vla-Delete obj) (setq obj (vlax-ename->vla-object (setq l (entlast))))))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getEndPoint obj)) (cons 11 (vlax-curve-getEndPoint obj1)))) (setq l2 (entlast))
      (entmake (list '(0 . "LINE") (cons 10 (vlax-curve-getstartPoint obj)) (cons 11 (vlax-curve-getstartPoint obj1))))         (setq l3 (entlast))
      (command "hatch" "p" "solid"l l1 l2 l3 "" "ERASE" l l1 l2 l3 "")
      (command "change" "l" "" "p" "LA" "★818 明装灯条" "")
      (command "undo" "e")(setvar "cmdecho" 1)
      (princ)
(setvar "clayer" oldlay);把刚刚记忆起来的图层→变成目前的图层
)




ssyfeng 发表于 2024-1-10 14:16:53

批量操作时以哪个对象确定方向呢

ljpnb 发表于 2024-1-10 22:38:37

;;★ 线条宽度填充 (保留对象)————————————————————————————————————————
(defun c:RV (/ d l l1 l2 l3 obj obj1 pt)
;;线条宽度填充(保留对象)
(setq oldlay (getvar "CLAYER"))        ;把目前的图层记忆起来
(setvar "cmdecho" 0)
(command "undo" "be")
(setq d (getdist "\n输入宽度:"))
(princ "\n选择对象直线或多段线:")
(setq
    ss (ssget
       '((-4 . "<OR") (0 . "line") (0 . "LWPOLYLINE") (-4 . "OR>"))
       )
)
(setq        pt (getpoint "\n点击偏移方向 或【确定】居中:")
)
(setq k 0)
(if ss
    (progn
      (repeat (sslength ss)
        (setq l (ssname ss k))
        (setq obj (vlax-ename->vla-object l))
        (if pt
          (progn (command "offset" d l "non" pt "")
               (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))
          )
          (progn (vla-Offset obj (* d 0.5))
               (setq obj1 (vlax-ename->vla-object (setq l1 (entlast))))
               (vla-Offset obj (* d -0.5))
               (setq obj (vlax-ename->vla-object (setq l (entlast))))
          )
        )
        (entmake (list '(0 . "LINE")
                     (cons 10 (vlax-curve-getEndPoint obj))
                     (cons 11 (vlax-curve-getEndPoint obj1))
               )
        )
        (setq l2 (entlast))
        (entmake (list '(0 . "LINE")
                     (cons 10 (vlax-curve-getstartPoint obj))
                     (cons 11 (vlax-curve-getstartPoint obj1))
               )
        )
        (setq l3 (entlast))
        (command "hatch"
               "p"
               "solid"
               (setq ss (ssadd)
                     ss (ssadd l ss)
                     ss (ssadd l1 ss)
                     ss (ssadd l2 ss)
                     ss (ssadd l3 ss)
               )
               ""
               "ERASE"
               (if pt
                   (ssdel l ss)
                   ss
               )
               ""
        )
        (command "change" "l" "" "p" "LA" "★819 可见线条" "")
        (setq k (1+ k))
      )
    )
)
(command "undo" "e")
(setvar "cmdecho" 1)
(princ)
(setvar "clayer" oldlay)                ;把刚刚记忆起来的图层→变成目前的图层
)


cheefeel 发表于 2024-1-19 17:38:37

ssyfeng2024-1-10 14:16


cheefeel 发表于 2024-1-19 17:39:37

ljpnb2024-1-10 22:38
;;() ...

cheefeel 发表于 2024-1-19 17:41:46

ssyfeng 发表于 2024-1-10 14:16
批量操作时以哪个对象确定方向呢

确实是个问题!
如果单选,则可选偏移方式。
如果多选,则直接按居中处理结束命令可行否?

xyp1964 发表于 2024-1-19 18:34:55

本帖最后由 xyp1964 于 2024-1-22 19:17 编辑


(defun c:tt ()
"线条宽度填充(保留对象)"
(defun udist (bit kwd msg def bpt / inp)
    (if def
      (setq msg (strcat "\n" msg "<" (rtos def) ">: ")
            bit (* 2 (fix (/ bit 2)))
      )
      (setq msg (strcat "\n" msg ": "))
    )
    (initget bit kwd)
    (setq inp (if bpt (getdist msg bpt) (getdist msg)))
    (if inp inp def)
)
(command "undo" "be")
(or dd (setq dd 10.))
(setq dd (Udist 7 "" "宽度<输入或鼠标直接量取>" dd nil))
(princ "\n选择对象直线或多段线:")
(setq i -1)
(if (setq ss (ssget '((0 . "line,LWPOLYLINE,arc"))))
    (while (setq s1 (ssname ss (setq i (1+ i))))
      (setq ob (vlax-ename->vla-object s1))
      (vla-Offset ob (* dd 0.5))
      (setq s2 (entlast))
      (vla-Offset ob (* dd -0.5))
      (setq s3 (entlast)
            s4 (entmakex (list '(0 . "LINE")
                               (cons 10 (vlax-curve-getStartPoint s2))
                               (cons 11 (vlax-curve-getStartPoint s3))
                         )
               )
            s5 (entmakex (list '(0 . "LINE")
                               (cons 10 (vlax-curve-getEndPoint s2))
                               (cons 11 (vlax-curve-getEndPoint s3))
                         )
               )
      )
      (command "-hatch" "p" "solid" "s" s2 s3 s4 s5 "" "")
      (command "ERASE" s2 s3 s4 s5 "")
    )
)
(command "undo" "e")
(princ)
)

cheefeel 发表于 2024-1-20 14:22:29

xyp1964 发表于 2024-1-19 18:34


这个确实是,居中偏移批量偏移了。
但是,能否同时支持单选的话允许指定偏移方向呢?


edsion24 发表于 2024-1-22 08:30:44

填充样式改成ANSI31为什么就执行不起来了呢
页: [1]
查看完整版本: 求助:线偏移成一定宽度的填充,改成能批量操作