cletero 发表于 2022-7-5 22:29:31

关于VisualLISP调试/vie

大家好,
 
我想知道这是否可能(或者可能太简单了,我没有看到):
 
我有一些LISP代码,上面有一个WHILE循环,在这个循环过程中,一个接一个地在图形中创建了许多对象(比如说圆)。然而,当我一步一步地运行程序来检查它时,我必须等到程序再次进入while循环后,对象才会显示在屏幕上。
 
有没有什么方法可以在我遍历创建对象的代码行时一个一个地显示这些对象?
 
我希望我说得有道理
 
干杯

Tharwat 发表于 2022-7-5 22:40:49

您可能需要发布代码,以便我们为您检查

cletero 发表于 2022-7-5 22:51:50

看看我上周末做的这个例子,它现在运行得很好,但如果在一步一步地运行程序时,我可以看到在FOREACH循环中创建的每个偏移对象,而不必等到它返回到WHILE,因为这时屏幕上突然出现了一堆对象,很难识别它们,这会有很大帮助。
 

;Alfredo Rodriguez, 18 May 2014
;This will offset an object multiple times
;It will offset to the inside/outside, up/down, left/right depending on the drawing direction
;So it's better to always set a maximum number of offsets or else it could offset indefinitely
;For this reason, if use default is chosen, it will offset the object 20 times, or you can
;choose how many times to offset. If object is offset to the wrong side, enter a negative distance (ej: -3 instead of 3)
;I'm not a lisp professional, so I can't guaranty any results obtained with this code, so use with care.
(defun c:cntoffset (/ ename dist vobj obj objlist objlist2 how_many count maxcount)
(vl-load-com)

       (null (initget 7))

       (while (setq ent (ssget))
         (setq dist (getdist "\nEnter offset distance: "))
         (setq how_many (sslength ent))
         (setq count 0)
      
            (or
         (setq maxcount (getdist "\nEnter number of offsets (or press Enter to use default): "))
         (setq maxcount 20)
         )
         
         (while (/= count how_many)
               (setq ename (ssname ent count))
               (setq obj (list (vlax-ename->vla-object ename)))
               (setq objlist (append obj objlist))
               (setq count (+ count 1))
         )
         (setq count 0)
         (while (and (/= count maxcount) (/= objlist nil))
               (setq count (+ count 1))
               (foreach vobj objlist
                   (if (vlax-method-applicable-p vobj "Offset")
                     (if (vl-catch-all-error-p
                           (setq objlist2 (vl-catch-all-apply 'vlax-invoke
                           (list vobj 'Offset (- dist)))))
                           (setq objlist2 nil)
                     )
                   (prompt "\n*** Can not offset that object, try again. ***")
                   )
                   (setq objlist (append (cdr objlist) objlist2))
               )
      
         )
             (setq objlist nil)
             (setq objlist2 nil)
       )

   (princ)
)

 
任何帮助都将不胜感激

hmsilva 发表于 2022-7-5 22:57:35

单向

(defun c:demo (/ N PT R X)
(setq        n5
pt '(0.0 0.0)
r5.
)
(while (> n 0)
   (entmake
   (list
'(0 . "CIRCLE")
(cons 10 pt)
(cons 40 r)
   )
   )
   (setq pt (mapcar '(lambda (x) (+ x 3)) pt))
   (alert "\nJust for testing!!!")
   (setq n (1- n))
)
(princ)
)

 
HTH公司
亨里克

cletero 发表于 2022-7-5 23:06:27

你好
谢谢hmsilva,它确实可以处理您提供的代码,但我尝试将这一行放在代码的不同位置,但无法以相同的方式工作。有什么想法吗?我正在你回答之前发布的代码中尝试。

hmsilva 发表于 2022-7-5 23:07:54

 
不客气,克莱特罗!
尝试
(未经测试)

;Alfredo Rodriguez, 18 May 2014
;This will offset an object multiple times
;It will offset to the inside/outside, up/down, left/right depending on the drawing direction
;So it's better to always set a maximum number of offsets or else it could offset indefinitely
;For this reason, if use default is chosen, it will offset the object 20 times, or you can
;choose how many times to offset. If object is offset to the wrong side, enter a negative distance (ej: -3 instead of 3)
;I'm not a lisp professional, so I can't guaranty any results obtained with this code, so use with care.
(defun c:cntoffset (/ ename dist vobj obj objlist objlist2 how_many count maxcount)
(vl-load-com)

       (null (initget 7))

       (while (setq ent (ssget))
         (setq dist (getdist "\nEnter offset distance: "))
         (setq how_many (sslength ent))
         (setq count 0)
      
            (or
         (setq maxcount (getdist "\nEnter number of offsets (or press Enter to use default): "))
         (setq maxcount 20)
         )
         
         (while (/= count how_many)
               (setq ename (ssname ent count))
               (setq obj (list (vlax-ename->vla-object ename)))
               (setq objlist (append obj objlist))
               (setq count (+ count 1))
         )
         (setq count 0)
         (while (and (/= count maxcount) (/= objlist nil))
               (setq count (+ count 1))
               (foreach vobj objlist
                   (if (vlax-method-applicable-p vobj "Offset")
              (progn
                  (alert "\nJust for testing!!!")
                     (if (vl-catch-all-error-p
                           (setq objlist2 (vl-catch-all-apply 'vlax-invoke
                           (list vobj 'Offset (- dist)))))
                           (setq objlist2 nil)
                     )
                   (prompt "\n*** Can not offset that object, try again. ***")
                   )
              )
                   (setq objlist (append (cdr objlist) objlist2))
               )
      
         )
             (setq objlist nil)
             (setq objlist2 nil)
       )

   (princ)
)

 
HTH公司
亨里克

cletero 发表于 2022-7-5 23:16:43

成功了!!
 
不确定这是怎么回事,但确实如此。
 
非常感谢您的帮助!!:拇指支撑:
 
祝你今天愉快

hmsilva 发表于 2022-7-5 23:22:59

不客气,克莱特罗
很高兴我能帮忙
 
亨里克

cletero 发表于 2022-7-5 23:32:19

只是一个更新,以防对任何人有所帮助,在创建对象后插入这一行似乎也可行:
(vla-update (vlax-ename->vla-object (entlast)))
页: [1]
查看完整版本: 关于VisualLISP调试/vie