还有一个解决方案。Higlight并返回已清理的选择集。
- ; The function below collects part number blocks (partid) to use in creating a schedule
- ; Define the Function
- (defun getpart ()
- ;;; Sets ID selection set ("SSID") to a list and gets every entity in the drawing and filters out to only ;;; blocks ("(cons 0 "INSERT")") and only blocks named "PARTID" ("(cons 2 "PARTID")")
- (SETQ SSID (ssget "X" (list (cons 0 "INSERT") (cons 2 "PARTID")(cons 66 1))))
- (if (= ssid nil)
- (progn
- (alert
- "\nCannot find any Item Blocks.
- \n Check your drawing."
- );alert
- (princ);clean
- );progn end
- (PROGN;;;Do the following.....
- (SETQ idCOUNT 0);;;Sets the counter to 0
- (setq EMAX(SSLENGTH SSID));;;Sets a "EMAX" to the length ("SSLENGTH") of the ID Selection Set ("SSID")
- (setq ssid2 (ssadd));creates ssid2 selection set
- (setq dupss (ssadd))
- (setq curcnt 0)
- (setq fnd t)
- (WHILE (< idCOUNT EMAX);;;While the count is less that "EMAX"....
- (setq tid (ssname ssid 0))
- (ssadd tid ssid2)
- (SSDEL TID SSID)
- (SETQ idcount(1+ idcount))
- );while
- (setq endlist (sslength ssid2))
- (setq endlist2 (sslength ssid2))
- (while (< curcnt endlist2)
- (progn
- (Setq nxtcnt 1)
- (setq tltcnt 0)
- (setq curid (ssname ssid2 0))
- (setq curnum (avalue curid "PARTNUMBER"))
- (while (<= tltcnt endlist)
- (progn
- (setq nxtid (ssname ssid2 nxtcnt))
- (if (/= nxtid nil)
- (progn
- (setq nxtnum (avalue nxtid "PARTNUMBER"))
- (if (equal curnum nxtnum)
- (ssdel curid ssid2)
- (setq nxtcnt (1+ nxtcnt))
- );if end
- );progn end
- );if end
- (setq tltcnt (1+ tltcnt))
- );progn end
- );while end
- (setq curcnt (1+ curcnt))
- (setq endlist2 (sslength ssid2))
- );progn end
-
- );while end
- )
- );if end
- (setq copcnt 0)
- (setq copmax (sslength ssid2))
- (WHILE (< copCNT copMAX);;;While the count is less that "EMAX"....
- (setq tid (ssname ssid2 0))
- (ssadd tid ssid)
- (SSDEL TID SSID2)
- (SETQ copcnt(1+ copcnt)))
- );progn end
- (princ);finish clean
- )
|