leventi 发表于 2022-7-6 08:14:19

多偏移代码帮助

大家好,
 
我需要的是在这张图片中解释的:
 
http://i.imgur.com/qggW0.png
 
假设我在绘图中有一条多段线/圆/直线/圆弧。我想在我选择的方向和我输入的距离上偏移它两次。所以它就像法线偏移命令一样,但我需要在同一方向上执行两次。我需要的另一件事是改变颜色。选定对象的颜色必须为“青色”,第一个偏移必须为白色,第二个偏移必须再次为“青色”。这就是全部。
 
这是我在互联网上找到的代码(我想是在这个论坛上)。我把它改成只有2个偏移量,这是一个多偏移量代码。它工作得很好,我只需要在混合中添加颜色更改代码:
 
(defun c:test (/ s i d p v)
;;; Tharwat 14. Dec. 2011 ;;;
(if (and (setq s (car (entsel "\n Select entity :")))
          ;(member (cdr (assoc 0 (entget s))) '("LINE" "CIRCLE" "ARC" "ELLIPSE")) ;I had to removed this part (wasnt working with polylines)
          (setq i 2)
          (setq d (getdist "\n Distance of offset :"))
          (setq p (getpoint "\n Specify point on side to offset :"))
          (setq v d)
   )
   (repeat i (command "_.offset" d s p "") (setq d (+ d v)))
   (princ)
)
(princ)
)

Tharwat 发表于 2022-7-6 08:24:19

看看这个。。。。
 

(defun c:TesT (/ s d p)
(vl-load-com)
;;; Tharwat 24. Feb. 2012 ;;;
(if
   (and
   (setq s (car (entsel "\n Select entity :")))
   (member (cdr (assoc 0 (entget s)))
             '("LWPOLYLINE" "POLYLINE" "LINE" "CIRCLE" "ARC" "ELLIPSE")
   )
   (setq d (getdist "\n Distance of offset :"))
   (setq p (getpoint "\n Specify point on side to offset :"))
   )
    (progn
      (command "_.offset" d s p "")
      (command "_.chprop" (entlast) "" "color" "WHITE" "")
      (command "_.offset" (+ d d) s p "")
      (command "_.chprop" (entlast) "" "color" "CYAN" "")
    )
    (princ)
)
(princ)
)

leventi 发表于 2022-7-6 08:28:22

我需要将选定实体的颜色也更改为青色。我试着用:
 
(command "_.chprop" (s) "" "color" "CYAN" "")但不起作用。据我所知,您将所选实体的“名称”存储在“s”中。Entlast还返回最后添加的实体的“名称”,因此它应该可以工作,但可能是不兼容的数据类型?
 
编辑:哦,没关系,我明白了,我不需要括号。现在可以工作了。谢谢。
编辑2:修复末尾缺少的paren。
 
(defun c:TesT (/ s d p)
(vl-load-com)
;;; Tharwat 24. Feb. 2012 ;;;
(if
   (and
   (setq s (car (entsel "\n Select entity :")))
   (member (cdr (assoc 0 (entget s)))
             '("LWPOLYLINE" "POLYLINE" "LINE" "CIRCLE" "ARC" "ELLIPSE")
   )
   (setq d (getdist "\n Distance of offset :"))
   (setq p (getpoint "\n Specify point on side to offset :"))
   )
    (progn
      (command "_.offset" d s p "")
      (command "_.chprop" s "" "color" "CYAN" "")
      (command "_.chprop" (entlast) "" "color" "WHITE" "")
      (command "_.offset" (+ d d) s p "")
      (command "_.chprop" (entlast) "" "color" "CYAN" "")
    )
    (princ)
)
(princ)
)

Tharwat 发表于 2022-7-6 08:33:41

 
不客气。
 
您修改的例程最后缺少一个paren。

pBe 发表于 2022-7-6 08:35:03

另一个
 

(defun c:test ( / clr ss e d)
(setq dist (cond ((getdist
                                    (strcat
                                          "\nSpecify Offset Distance"
                                          (if (numberp dist)
                                                (strcat " <"
                                                          (rtos dist 2 2)
                                                          ">: ")
                                                ": "
                                                ))))
                               (dist)))
(while (and dist
         (setq ss (ssget "_:S:E:L"))
    (vlax-method-applicable-p (vlax-ename->vla-object (setq e (ssname ss 0))) 'Offset)
         (setq clr "7" d distpt (getpoint "\nSide to Offset")))
         (repeat 2
(command "_.offset"d e pt "" "_chprop" (entlast) "" "_color" clr"")
                (setq clr "4" d (+ d dist))
         
               )
       (command "_chprop" e "" "_color" clr "")
       )
(princ)      
)

 
HTH公司

Tharwat 发表于 2022-7-6 08:40:27

 
 
你好,pBe。
 
需要一行代码

pBe 发表于 2022-7-6 08:47:01

我更新了帖子。。在匆忙编写代码时,这总是一个问题

Tharwat 发表于 2022-7-6 08:53:51

 
同意。
 
顺便说一句,这是一种很好的编码方式。

pBe 发表于 2022-7-6 08:54:27

 
谢谢tharwat
 
我养成了不检查语法就复制和粘贴其他代码片段的习惯。因此编码错误
无论如何。。。
 
干杯

leventi 发表于 2022-7-6 09:00:06

 
嘿,也谢谢你。我喜欢它记住最后一个偏移距离并继续偏移命令,直到你们点击回车键,但它仍然不会将选定实体的颜色更改为青色。
页: [1] 2
查看完整版本: 多偏移代码帮助