我正在为我的团队创建一些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)
)
)
)
应该发生什么:
[当AutoCAD STRETCH
命令发出使用交叉窗口(与要拉伸的线段交叉)选择对象的选择提示时,该提示是标准选择提示,STRETCH
命令随后将获得信息关于如何以与使用AutoLISP ssnamex
函数相同的方式获取选择的内容。
同样,我建议为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
)
)
)
使用这种方法,可以确保用户提供了两个点,这些点定义了一个交叉窗口,该交叉窗口与一个或多个对象相交,[STRETCH
命令。
ssget
交叉模式字符串(C
)的使用还确保您始终提供通过交叉选择方法获得的STRETCH
命令。关于this answer对象捕捉修饰符和_non
命令前缀的使用,您可能还希望参考_.
。>>