为每个o创建新列表
嗨,我会尽量说清楚的。我有一个lisp,可以多次偏移对象。为了进一步处理,我需要按lisp创建的相反顺序列出对象,这有点容易,但如果偏移量从原始对象创建了2个对象,我还需要将对象作为不同的列表进行区分或分组。在附件中,你可以看到一个随机对象的结果(见上图),不同的颜色代表我需要分离的不同组,我正在运行的代码将首先创建红色偏移,然后是最大的蓝色偏移和最大的绿色偏移,其余的蓝色偏移,最后是剩余的绿色偏移。在底部对象上也会发生类似的情况
我曾想过每次创建两个以上的对象时都要创建一个新列表,但我找不到给每个列表一个唯一名称的方法(例如:list1、list2、list3等),因为无法告诉将创建多少个对象。
我已经没有主意了,所以任何帮助都将不胜感激。
抵消图纸 如果有帮助,这是我用来抵消的lisp:
;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 thisdrawing size listname)
(vl-load-com)
(setqthisdrawing (vla-get-activedocument (vlax-get-acad-object))) ;Thismakes the Undo command erase only what's drawn in this lisp
(vla-StartUndoMark thisdrawing) ;This makes the Undo command erase only what's drawn in this lisp
(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 50)
)
(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))
(setq vobj (car objlist))
(if (vlax-method-applicable-p vobj "Offset")
;(progn ;Activate this line during testing to see order in which objects are drawn
(if (vl-catch-all-error-p
(setq objlist2 (vl-catch-all-apply 'vlax-invoke
(list vobj 'Offset (- dist)))))
(progn (setq objlist2 nil)
(prompt "\n*** Can not offset that object, try again. ***")
(setq count 0)
)
(setq size (length objlist2));To see if more than one object was created
)
;(prompt "\nDone") ;Activate this line during testing to see order in which objects are drawn
;(alert "\nJust for testing!!!") ;Activate thisline during testing to see order in which objects are drawn
;Activate this line during testing to see order in which objects are drawn
)
(if (> size 1);To create a different list name for each object, but this seens to be going nowhere
(progn (setq count2 1)
(while (< count2 size)
(setq count2 (+ count2 1))
(setq listname (strcat "polylist" (itoa count2)))
)
)
)
(setq objlist (append objlist2 (cdr objlist)))
)
(setq objlist nil)
(setq objlist2 nil)
)
(vla-EndUndoMark thisdrawing) ;This makes the Undo command erase only what's drawn in this lisp
(princ)
) 也许可以参考一下这个句柄,它是增量十六进制还是唯一的名称?
_$(handent“e23”)
每一步都连接/附加到一个列表中 像hanhphuc一样,只需使用(Entlast)创建每个偏移量,并将对象添加到选择集,然后就可以检索每个偏移量。根据需要重复多个选择集。 嗨,伙计们。谢谢你的回答。
然而,我不确定我是否理解你的建议。。。问题是,在某个点上,偏移创建了多个实体,因此第一个实体将被追加到列表中,其他实体必须存储起来,以便在第一个实体进一步偏移后添加到列表中。
例如:A创建B,B创建C,D和E,C创建F和G(然后返回“nil”),D创建H和I(然后返回“nil”),E创建J(和“nil”),因此最终列表必须是(A B C F G)(D H I)(E J)。这可以在任何级别重复多次。
所以我做的是这样的:
将创建的对象存储在临时列表中,如果其大小大于1,则将临时列表的car附加到mylist,然后将临时列表设置为其自身的cdr。一旦返回“nil”,就会在mylist中插入一个标记,并附加临时列表的car,然后再次将临时列表设置为其自身的cdr。直到不再创建任何对象为止。
然后使用该标记创建一个列表,该列表由我的函数处理,然后删除,创建另一个包含项目的列表,直到下一个标记,依此类推。
这是我写的代码中处理这个问题的部分,以防它对任何人有帮助,或者如果有任何关于如何改进它的建议。
“polylist”是我要找的列表。
(setq count 0)
(while (and (/= count maxcount) (/= objlist nil))
(setq count (+ count 1))
(setq vobj (car objlist))
(if (vlax-method-applicable-p vobj "Offset")
;(progn ;Activate this line during testing to see order in which objects are drawn
(if (vl-catch-all-error-p
(setq objlist2 (vl-catch-all-apply 'vlax-invoke
(list vobj 'Offset (- dist)))))
(progn (setq objlist2 nil)
(prompt "\n*** Can not offset that object, try again. ***")
(setq count 0)
(setq polylist (append polylist (list "p" (car polylist2))))
(setq polylist2 (cdr polylist2))
)
(setq size (length objlist2));To see if more than one object was created
)
;(prompt "\nDone") ;Activate this line during testing to see order in which objects are drawn
;(alert "\nJust for testing!!!") ;Activate this line during testing to see order in which objects are drawn
;Activate this line during testing to see order in which objects are drawn
)
(if (> size 1);To separate list if more than one object was created
(progn
(setq polylist (append polylist (list (car objlist2))))
(setq polylist2 (append polylist2 (cdr objlist2)))
)
(setq polylist (append polylist objlist2))
)
(setq objlist (append objlist2 (cdr objlist)))
)
页:
[1]