AutoLisp 绘制服装折线

Posted

技术标签:

【中文标题】AutoLisp 绘制服装折线【英文标题】:AutoLisp drawing costum polyline 【发布时间】:2022-01-01 18:31:42 【问题描述】:

我有这个 AutoLisp 代码,我想问两个问题:

1.如何在绘制期间(或在选择点时)使折线可见?

2。如何更改折线而不是图层的颜色?

如果我得到答案,非常感谢。

(defun c:nyomvodal (/ osmode clayer celtype)
  ;; save the current osmode, clayer and  celtype
  (setq osmode (getvar "osmode"))
  (setq clayer (getvar "clayer"))
  (setq celtype (getvar "celtype"))

  ;; create a new layer and make it current
  (command "_layer" "_make" "nyomvodal" "_color" 3 "nyomvodal" "")
  ;; set the current osmode and line type
  (setvar "osmode" 0)
  (setvar "celtype" "16-os cso")

  ;; use vla-catch-all-apply to avoid exiting code if user cancels
  (vl-catch-all-apply
    '(lambda (/ pt lst)
       ;; get points form user
       (while (setq pt (getpoint "\nPick point: "))
     (setq lst (cons pt lst))
       )
       (if (< 2 (length lst))
     (progn
       ;; create the polyline
       (command "_pline")
       (foreach p (reverse lst)
         (command p)
       )
       (command "")
     )
       )
     )
  )
  
  ;; restore the previous system variables values
  (setvar "osmode" osmode)
  (setvar "clayer" clayer)
  (setvar "celtype" celtype)
  (princ)
)

【问题讨论】:

【参考方案1】:
    最简单的方法是运行命令PLINE 并等待用户结束。 颜色可以通过系统变量CECOLOR进行更改。

通过系统变量恢复默认值您可以使用错误捕获(如果用户单击 Esc ),当用户以 [enter] [space] 结束时,您将通过调用 (*error*) 函数恢复默认值

(defun c:nyomvodal (/ osmode clayer celtype 
    *error* )   (defun *error* ( msg / ) 
        (if (not (null msg ) )  (progn (princ "\nname:*error*: " ) (princ msg ) (princ "\n")    ) )
        
        (setvar "osmode" osmode)
        (setvar "clayer" clayer)
        (setvar "celtype" celtype)
        (setvar 'CECOLOR cecolor)
    )
  ;; save the current osmode, clayer and  celtype
  (setq osmode (getvar "osmode"))
  (setq clayer (getvar "clayer"))
  (setq celtype (getvar "celtype"))
  (setq cecolor (getvar "CECOLOR"))

  ;; create a new layer and make it current
  (command "_layer" "_make" "nyomvodal" "_color" 3 "nyomvodal" "")
  ;; set the current osmode and line type
  (setvar "osmode" 0)
  (setvar "CECOLOR" "1")
  ;(setvar "celtype" "16-os cso")

  (command "_pline" pause)       
  
  (*error* nil) ; to restore default color, layer ... 
  
  (princ)
)

【讨论】:

以上是关于AutoLisp 绘制服装折线的主要内容,如果未能解决你的问题,请参考以下文章

使用AutoLISP生成新的尺寸样式

AutoLisp 选择对象函数 ssget 用法

AutoLisp 返回字符串中某一子串首次出现的位置的函数

CAD AUTOLISP 当中 (action_tile "accept" (done_dialog 1))

vba在cad中画直线和圆弧多段线

lisp"^“是啥运算符号