Crones 发表于 2022-7-6 10:46:31

Lisp识别采购订单中的变更

好的,我已经完成了一个通过多段线(重多段线)的lisp。它在每个点上绘制一个圆,以表明它标识了每个点。现在,我必须修改这条多段线,但只要改变一些点的坐标,多段线仍然有相同数量的点。好的,我必须能够在lisp中创建一个例程,识别多段线的哪些点已经被更改,并且它绘制或插入这个修改点的坐标作为文本。绘制文本很容易,我很难识别折线的哪些点发生了变化。
 
我在想,也许有一种方法是修改例程并将其保存为另一个例程。一个例程是使用setq将原始多段线保存在一个变量中,然后第二个例程,即修改后的例程,将在两个变量之间进行比较(仅清楚地显示每个点的坐标),然后在文本中绘制差异,然而,这似乎不太方便用户使用,也不是一种真正有效的方法。
 
那么两个问题,有谁有更好的想法吗?有没有办法在lisp中只执行一个例程?

Tharwat 发表于 2022-7-6 11:02:05

你好
 
如果您支持代码,那么所有人都可以更容易地尝试提供帮助,如果您不想显示完整的例程。所以你可以把问题所在的部分带出来。
 
谢谢和问候
 
塔瓦特

Lee Mac 发表于 2022-7-6 11:14:19

可能使用ObjectReactor保存点/索引列表(在修改之前触发),并使用另一个回调(在修改之后触发)进行比较。

Crones 发表于 2022-7-6 11:32:24

 
下面是通过多段线的代码。
 
(defun c:rpoli()
   (setq spoli (car (entsel "\nSelec. poligono. ")))
   (setq bpoli (entget spoli))
   (setq poli1 spoli)
   (setq c (cdr (assoc 10 bpoli)))
   (while (/= "SEQEND" (cdr (assoc '0 bpoli)))
            (setq vert (cdr (assoc 10 bpoli)))
      (command "circle" vert "0.5")
            (setq spoli(entnext spoli) bpoli (entget spoli))
      );wh
)
 
我是Lisp新手,但对AutoCad并不陌生,但还是新手。所以我还不知道很多事情,比如ObjectReactor,不知道那是什么。
 
我有一个想法,但是在lisp中保存有用数据时遇到了问题。例如,我在思考一个辅助变量,它在poli1中保存了我的spoli,就像我在那里提出的那样,那么要比较的程序将是(不完整的)。
 
(defun c:dpoli()
   (setq spoli (car (entsel "\nSelec. poligono. ")))
   (setq bpoli (entget spoli))
   (setq poli2 poli1)
   (setq bpoli2 (entget poli2))
   (setq c (cdr (assoc 10 bpoli)))
   (while (/= "SEQEND" (cdr (assoc '0 bpoli)))
            (setq vert (cdr (assoc 10 bpoli)))
            (setq vert1 (cdr (assoc 10 bpoli2)))
            (setq p (car vert))
            (setq p1 (car vert1))
            (if (/= p p1)
                (progn
                (command "text" pause "1.5" "90" (car vert))
                (command "text" pause "1.5" "90" (cadr vert))
                )
            )                  
            (setq spoli(entnext spoli))
            (setq poli2(entnext poli2) bpoli (entget spoli) bpoli2 (entget poli2))
   );wh
)
(princ "\n Iniciar Rutina que recorre un pol�*gono:rpoli")
 
这意味着先做rpoli,然后再做dpoli,然而,spoli只是实体的标识符,因此,当我运行dpoli时,它没有发现任何更改,因为它按现在的状态遍历实体的数据库,该数据库被修改,这意味着数据库poli1=poli2=spoli,我想要它,所以数据库poli1=poli2/=spoli,其中spoli是修改后的多段线,poli1和2是旧多段线的数据库。如何在修改多段线之前将其整个数据库保存在变量中,然后将其与修改时的实体进行比较?

Lee Mac 发表于 2022-7-6 11:40:14

为了测试这个概念,我把它放在一起——它不是傻瓜式的,而且可能不适用于撤消,或者当对象被擦除时。
 

(defun c:PolyChange nil
(vl-load-com)
;; © Lee Mac 2010

((lambda ( data mod can / react objLst )
      (if (setq react
            (vl-some
            (function
                (lambda ( reactor )
                  (if (eq data (vlr-data reactor)) reactor)
                )
            )
            (cdar
                (vlr-reactors :vlr-object-reactor)
            )
            )
          )
      (if (vlr-added-p react)
          (progn
            (vlr-remove react)
            (setq *PolyData* nil)
          )
          (vlr-add react)
      )
      (setq react
          (vlr-object-reactor
            (progn
            (setq *PolyData*
                (mapcar
                  (function
                  (lambda ( obj )
                      (cons (vla-get-Handle obj)
                        (LM:Variant->2DPoints
                        (vla-get-Coordinates obj)
                        )
                      )
                  )
                  )
                  (setq objLst
                  (LM:ss->vla
                      (ssget "_:L" '((0 . "LWPOLYLINE")))
                  )
                  )
                )
            )
            objLst
            )
            data
            (list
            (cons :vlr-modifiedmod)
            (cons :vlr-cancelled can)
            )
          )
      )
      )
      (princ
      (if (vlr-added-p react)
          "\n** Reactor Activated **"
          "\n** Reactor Deactivated **"
      )
      )
      react
    )
   "Example-Reactor"
   'PolyChange-Mod
   'PolyChange-Can
)

(princ)
)

(defun PolyChange-Mod ( object reactor args / points verts hand )
(vl-load-com)

(if *CommandisCancelled*
   (setq *CommandisCancelled* nil)   
   
   (if (and (not (vlax-erased-p object))
            (setq points (cdr (assoc (setq hand (vla-get-Handle object)) *PolyData*))))
   (progn      
       (mapcar
         (function
         (lambda ( p q )
             (or (equal p q 1e-6)
               (entmakex (list (cons 0 "POINT") (cons 10 p)))
             )
         )
         )
         (setq verts (LM:Variant->2DPoints (vla-get-Coordinates object)))
         points
       )
       (setq *PolyData*
         (subst (cons hand verts) (assoc hand *PolyData*) *PolyData*)
       )
   )
   )
)
(princ)
)
   
(defun PolyChange-Can ( object reactor args )
(setq *CommandisCancelled* t)
(princ)
)

;;-------------------=={ Variant Value }==--------------------;;
;;                                                            ;;
;;Converts a VLA Variant into native AutoLISP data types    ;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;value - VLA Variant to process                            ;;
;;------------------------------------------------------------;;
;;Returns:Data contained within variant                   ;;
;;------------------------------------------------------------;;

(defun LM:VariantValue ( value )
;; © Lee Mac 2010
(cond
   ( (eq 'variant (type value))

   (LM:VariantValue (vlax-variant-value value))
   )
   ( (eq 'safearray (type value))

   (mapcar 'LM:VariantValue (vlax-safearray->list value))
   )
   ( value )
)
)

;;-----------------=={ Group by Number }==--------------------;;
;;                                                            ;;
;;Groups a list into a list of lists, each of length 'n'    ;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;l - List to process                                       ;;
;;n - Number of elements by which to group                  ;;
;;------------------------------------------------------------;;
;;Returns:List of lists, each of length 'n'               ;;
;;------------------------------------------------------------;;

(defun LM:GroupByNum ( l n / a b )
;; © Lee Mac 2010
(while l
   (
   (lambda ( i )
       (while (< 0 i)
         (setq a (cons (car l) a) l (cdr l) i (1- i))
       )
       (setq b (cons (reverse a) b) a nil)
   )
   n
   )
)
(reverse b)
)

;;----------------=={ Variant->2DPoints }==-------------------;;
;;                                                            ;;
;;Converts a Variant of Double type to a list of 2D Points;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;var - VLA Variant                                       ;;
;;------------------------------------------------------------;;
;;Returns:List of 2D Points                               ;;
;;------------------------------------------------------------;;

(defun LM:Variant->2DPoints ( var )
;; © Lee Mac 2010
(LM:GroupByNum (LM:VariantValue var) 2)
)

;;-----------------=={ SelectionSet -> VLA }==----------------;;
;;                                                            ;;
;;Converts a SelectionSet to a list of VLA Objects          ;;
;;------------------------------------------------------------;;
;;Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;ss - Valid SelectionSet (Pickset)                         ;;
;;------------------------------------------------------------;;
;;Returns:List of VLA Objects                           ;;
;;------------------------------------------------------------;;

(defun LM:ss->vla ( ss )
;; © Lee Mac 2010
(if ss
   (
   (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (setq l (cons (vlax-ename->vla-object e) l))
       )
       l
   )
   -1
   )
)
)

 
键入“PolyChange”激活反应器,选择要监控的LWPoly。
 
然后尝试修改多边形(更改夹点或其他)。应在修改点处创建点。
 
再次键入“PolyChange”以停用反应器。

Crones 发表于 2022-7-6 11:55:23

 
哇!很多命令我都不知道。非常感谢你,我会研究一下,看看如何让它为我工作。
页: [1]
查看完整版本: Lisp识别采购订单中的变更