看看我上周末做的这个例子,它现在运行得很好,但如果在一步一步地运行程序时,我可以看到在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)
- )
任何帮助都将不胜感激 |