首页 > 解决方案 > 我的代码有效,虽然只在我的机器上

问题描述

我正在为我的团队创建一些 AutoLisp 命令,现在我已经完成了,代码在他们的计算机中崩溃了,我不知道为什么。在我的工作正常。

代码的想法是拉伸折线并更新分组的块属性。代码要求选择块、折线的实际宽度和应该采用的分数(例如:0.75 减少到 75%)。然后,这就是问题的开始,选择要拉伸的边。在他们的电脑上,他不允许选择,它只是跳到前面。

(defun c:MRV (/ a b c d e)
;ungroup
(command "pickstyle" 0)
;variables
(setq blk (entsel "\nSelect block to modify: "))
(initget (+ 1 2 4))
(setq a (getreal "\nWidth?"))
(initget (+ 1 2 4))
(setq b (getreal "\nNew module fraction? (>0;1<)"))


    ;distance to reduce
    (setq c (- 1 b))
    (setq d (* a c -0.5))
    (setq e (* -1 d))

    ;stretch
    (command "stretch" pause pause "" "0,0" (polar '(0 0) (/ pi 2) d))

    (command "stretch" pause pause "" "0,0" (polar '(0 0) (/ pi 2) e))

    ;open layer
    (setq LayerTable (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(if (and (tblsearch "LAYER" "MC_BLOCO_INFO_AREAS")
         (setq layname (vla-item layertable "MC_BLOCO_INFO_AREAS"))
         (= (vlax-get-property layname 'lock) :vlax-true)
         )
  (vla-put-lock layname :vlax-false))
    ;change attribute
    (setq l (cons "CAMPO_6" (rtos b 2 2)))
    (LM:SetAttributeValues (car blk) (list l))



    ;close layer
    (setq LayerTable (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(if (and (tblsearch "LAYER" "MC_BLOCO_INFO_AREAS")
         (setq layname (vla-item layertable "MC_BLOCO_INFO_AREAS"))
         (= (vlax-get-property layname 'lock) :vlax-false)
         )
  (vla-put-lock layname :vlax-true))


    ;update block width
    (command "regenall")
    ;regroup
    (command "pickstyle" 1)
    (print "Modulo modificado.")
    (princ)
    )
(defun LM:SetAttributeValues ( blk lst / enx itm )
    (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
        (if (setq itm (assoc (strcase (cdr (assoc 2 enx))) lst))
            (progn
                (if (entmod (subst (cons 1 (cdr itm)) (assoc 1 enx) enx))
                    (entupd blk)
                )
                (LM:SetAttributeValues blk lst)
            )
            (LM:SetAttributeValues blk lst)
        )
    )
)

应该发生什么:

应该发生什么

标签: autocadautolisp

解决方案


当 AutoCADSTRETCH命令发出提示以选择使用交叉窗口(交叉要拉伸的线段)选择的对象时,该提示是标准选择提示,该STRETCH命令随后将获取有关如何在与使用 AutoLISPssnamex函数的方式相同。

因此,我建议为STRETCH命令提供已使用交叉窗口选择方法获取的选择集。

例如,您可以定义一个函数,例如:

(defun mystretch ( dis / pt1 pt2 sel )
    (while
        (and
            (setq pt1 (getpoint "\nSpecify first point of crossing window: "))
            (setq pt2 (getcorner pt1 "\nSpecify opposite point of crossing window: "))
            (not (setq sel (ssget "_C" pt1 pt2)))
        )
        (princ "\nNo objects were found within the crossing window.")
    )
    (if sel
        (progn
            (command "_.stretch" sel "" "_non" '(0 0) "_non" (list 0 dis))
            t
        )
    )
)

然后,您可以使用您希望在 Y 方向上拉伸对象的距离来评估上述函数,例如:

(mystretch 10.0)

或者,使用代码中的变量:

(mystretch d)
(mystretch e)

t如果用户提供了两个有效点并且已发出命令,则该函数将返回(True) STRETCH- 您可以在继续之前在程序中对此进行测试。

使用这种方法,您可以确保用户在发出 AutoCAD命令之前提供了两个点来定义与一个或多个对象相交的交叉窗口。STRETCH

ssget交叉模式字符串 ( )的使用C还确保您始终提供STRETCH使用交叉选择方法获得的命令。

您可能还希望参考this answer关于_non对象捕捉修改器的使用以及_.上述示例代码中的命令前缀。


推荐阅读