Ohnoto 发表于 2022-7-6 08:34:41

越简单越好
 
转到acad控制柄。我发现可以使用以下行代码获取信息:
 
(setq handle (cdr (assoc 5 (entget en))))
 
然而,当试图将setq变量放入属性块时,该变量不起作用。
 
(defun c:test ( / area en nm pt )
(if (setq en (ssget "_:S" '((0 . "LWPOLYLINE") (70 . 1))))
(if (vl-catch-all-error-p
      (setq area (vl-catch-all-apply 'vlax-curve-getarea (list (ssname en 0))))
   )
   (princ "\nInvalid Object.")
   )
(setq handle (cdr (assoc 5 (entget en))))
)

(setq area (rtos (/ area 144.0) 2 2))

(if (setq block (ssget "_:S" '((0 . "INSERT"))))
(progn
(setq block (ssname block 0))
(LM:vl-SetAttributeValue (vlax-ename->vla-object block) "NET_SQ_FEET" area)
(LM:vl-SetAttributeValue (vlax-ename->vla-object block) "ACAD_HANDLE" handle)
)
)

   (princ)
)
(vl-load-com) (princ)

;;----------------=={ Set Attribute Value }==-----------------;;
;;                                                            ;;
;;Populates the first attribute matching the tag specified;;
;;found within the block supplied with the value specified, ;;
;;if present.                                             ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;block - VLA Block Reference Object                        ;;
;;tag   - Attribute TagString                               ;;
;;value - Value to which the Attribute will be set          ;;
;;------------------------------------------------------------;;
;;Returns:Value the attribute was set to, else nil      ;;
;;------------------------------------------------------------;;

(defun LM:vl-SetAttributeValue ( block tag value )
   (setq tag (strcase tag))
   (vl-some
       (function
         (lambda ( attrib )
               (if (eq tag (strcase (vla-get-TagString attrib)))
                   (progn
                     (vla-put-TextString attrib value)
                     value
                   )
               )
         )
       )
       (vlax-invoke block 'GetAttributes)
   )
)

MSasu 发表于 2022-7-6 08:37:27

请注意,en变量存储的是选择集,而不是实体;还要在IF测试中包含多条语句,请检查PROGN的使用。
10

Ohnoto 发表于 2022-7-6 08:42:22

令人惊叹的谢谢你的帮助。这就是我所需要的设置。

MSasu 发表于 2022-7-6 08:47:23

听起来你已经完成了你的代码,这很好。很高兴我能帮助你!完全欢迎你!

Lee Mac 发表于 2022-7-6 08:48:39

我很高兴你能使用我的功能Ohnoto
 
对于此特定任务,您可能需要考虑使用我的“设置属性值”函数,该函数可以通过以下方式调用:
 
11
 
@米尔恰:一些非常详细和信息丰富的建议,做得好

GP_ 发表于 2022-7-6 08:53:11

 
 
也许最好使用Vlax曲线isClosed,或者考虑Plinegen。

MSasu 发表于 2022-7-6 08:56:51

如果您能详细介绍该功能将如何改进选择过程,我将不胜感激。
其次,PLINEGEN系统变量与OP的任务-选择闭合多段线无关。

Lee Mac 发表于 2022-7-6 08:57:33

 
考虑闭合LWPolyline的线型生成设置为ON的情况
 
12

MSasu 发表于 2022-7-6 09:01:39

你是对的;我现在理解了这个问题;这也可能来自于在属性中重写系统变量或通过PEDIT命令。
页: 1 [2]
查看完整版本: 到的多段线的面积和句柄