|
|||||||
| Hot Tip Harry: AutoCAD Customization Cadalyst's popular Hot Tip Harry and his entourage are here to assist you with AutoCAD customization. Request help with a programming problem, locate a needed routine, or just keep up with Harry's latest activities. You'll find Harry's archive of AutoLISP and VBA code and hatch patterns at www.cadalyst.com/cadtips. Moderated by R.K. McSwain. |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
hello every one !;
i am trying for a routine which will select all the objects on layer s-fndn in a selection set by crossing window.which is working fine but when i try to sort selected objects individually ( like f_1 , f_2.....) & get the data of each object, it is showing the object named "f_1 " but not in selected order . some times it is selecting the last object in selection set & sometimes somewhere in the middle !! ( i tried to use vl-sort but confusedddd) simply speaking i want to Sort selected objects by X/Y/Select-order ( like tcount in express tools) (DEFUN C:CFS() (SETQ Po1 (GETPOINT "\nPick top RIGHT corner" ) ; po2 (GETCORNER Po1 "\nPick bottom LEFT corner" )) ; (progn (setq FOOT(ssget "C" po1 po2 (list (cons 0 "LWPOLYLINE")(cons 8 "S-FNDN")))) ; (setq NOF (sslength FOOT)) (setq ENTER 0 ) (setq f+ (rtos enter 2 0)) (REPEAT NOF (PROGN (setq linc (ssname FOOT ENTER)) (setq ENTER (1+ ENTER)) (setq f+ (rtos enter 2 0)) (SETQ link (strcat "f_" f+)) (set (read link) linc ) (setq elst (entget linc)) (foreach item ELST (if (eq (car item) 10) (setq pts (cons (cdr item) PTS)))) (setq P1 (car PTS)) ;;;(setq P3 (caddr PTS)) ;;;(setq P2 (cadr PTS)) (setq P4 (cadddr PTS)) )) ))
__________________
no man is wise at all times. SHARIFF |
|
#2
|
||||
|
||||
|
here is for x & y:
Code:
(defun c:cSel ()
(defun wiz_run ()
(prompt "\nSelect Objects")
(setq wiz_set (ssget))
(setq wiz_sorted
(reverse
(mapcar '(lambda (z)
(mapcar 'cdr
(vl-remove-if-not
'(lambda (x) (= -1 (car x)))
z
) ;_ end_vl-remove-if-not
) ;_ end_mapcar
) ;_ end_lambda
(vl-sort
(mapcar '(lambda (y)
(entget y)
) ;_ end_lambda
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex wiz_set))
) ;_ end_setq
) ;_ end_mapcar
(function
(lambda (p1 p2)
(> ((eval (car wiz_get)) (assoc 10 p1))
((eval (car wiz_get)) (assoc 10 p2))
) ;_ end_<
) ;_ end_lambda
) ;_ end_function
) ;_ end_vl-sort
) ;_ end_mapcar
) ;_ end_reverse
) ;_ end_setq
) ;_ end_defun
(initget "X Y")
(setq wiz_kword (getkword "\nSort by [X/Y/]?: "))
(cond
((= wiz_kword "X") (setq wiz_get '(cadr)) (wiz_run))
((= wiz_kword "Y") (setq wiz_get '(caddr)) (wiz_run))
(t (exit))
) ;_ end_cond
(princ)
) ;_ end_defun
(princ)
|
|
#3
|
||||
|
||||
|
Wiz got you the sorting function sorted out.
Remember that ACAD always sorts by drawing creation sequence unless some other method is used. That's because all the Entities are in a list from first to last (not very surprising, that). You might look into the very useful (redraw) subr for this, too. (redraw [ename] 3) will highlight (if that is 'on' in ACAD) that entity. You need to un-highlight it when your are done with (redraw [ename] 4). This can be a nice visual cue for the User, too. |
|
#4
|
||||
|
||||
|
i've been playing with that toy also cap, here's what i came up for tracing a routines' result
Code:
(defun c:tras ()
(defun *error* (msg)
(princ msg)
(redraw ron_ent 4)
)
(setq ron_ent (entnext))
(setq counter 1)
(while ron_ent
(redraw ron_ent 3)
(prompt (strcat "highligted is " (itoa counter) " entity"))
(getint "\n>>>press spacebar for next entity<<<\n")
(princ)
(redraw ron_ent 4)
(setq ron_ent (entnext ron_ent))
(setq counter (1+ counter))
)
(alert "\n>>>looping done<<<\n")
(princ)
)
(princ)
|
|
#5
|
||||
|
||||
|
Works.
You can do this: (defun HL_UPI (j) ;highlight user-picked-item (redraw j 3) ) Now, that's old and modular, and trades on the fact that highlight by entity used to de-highlight when a different Entity is selected. Which is not (really) the case anymore. Remembering to add that (redraw [ename] 3) after a single entity is "captured" is the trick (that's why I stuck a copy in my boilerplate file, noname.lsp). This can also be needful, too: (if (= (getvar "SCREENMODE") 0)(graphscr)) Tough to highlight things that are not visible on screen <eyeroll>. What OP might also could use is a module that looks at the insert point of the entity looped "to" then peeks at the current vmin/vmax and asks if a Zoom, Center might be desired. |
|
#6
|
||||
|
||||
|
thanks wiz for u r routine !!
i tried it yesterday night but it is NOT SORTING the objects in a selection set ! ( i tried with both 'x' & 'y' directions for soting but i didnt get the desired results) i had tried the following way ! (progn (setq wiz_kword "X") (cond ((= wiz_kword "X") (setq wiz_get '(cadr)) (wiz_run)) ((= wiz_kword "Y") (setq wiz_get '(caddr)) (wiz_run)) (t (exit)) )) (defun wiz_run () (setq wiz_set FOOT) (setq wiz_sorted (reverse (mapcar '(lambda (z) (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= -1 (car x))) z) ;_ end_vl-remove-if-not ) ;_ end_mapcar ) ;_ end_lambda (vl-sort (mapcar '(lambda (y) (entget y) ) ;_ end_lambda (vl-remove-if 'listp (mapcar 'cadr (ssnamex wiz_set)) ) ;_ end_setq ) ;_ end_mapcar (function (lambda (p1 p2) (> ((eval (car wiz_get)) (assoc 10 p1)) ((eval (car wiz_get)) (assoc 10 p2)) ) ;_ end_< ) ;_ end_lambda ) ;_ end_function ) ;_ end_vl-sort ) ;_ end_mapcar ) ;_ end_reverse ) ;_ end_setq ) ;_ end_defun
__________________
no man is wise at all times. SHARIFF |
|
#7
|
||||
|
||||
|
wiz_sorted is the variable which contains a list of entity names based on x or y. from there you can now continue your routine.
|
|
#8
|
||||
|
||||
|
try this (not tested):
Code:
(DEFUN C:CFS ()
(defun wiz_run ()
(setq wiz_set FOOT)
(setq wiz_sorted
(mapcar '(lambda (z)
(mapcar 'cdr
(vl-remove-if-not
'(lambda (x) (= -1 (car x)))
z
) ;_ end_vl-remove-if-not
) ;_ end_mapcar
) ;_ end_lambda
(vl-sort
(mapcar '(lambda (y)
(entget y)
) ;_ end_lambda
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex wiz_set))
) ;_ end_setq
) ;_ end_mapcar
(function
(lambda (p1 p2)
(< ((eval (car wiz_get)) (assoc 10 p1))
((eval (car wiz_get)) (assoc 10 p2))
) ;_ end_<
) ;_ end_lambda
) ;_ end_function
) ;_ end_vl-sort
) ;_ end_mapcar
) ;_ end_setq
) ;_ end_defun
(SETQ Po1 (GETPOINT "\nPick top RIGHT corner") ;
po2 (GETCORNER Po1 "\nPick bottom LEFT corner")
) ;_ end_SETQ
(initget "X Y")
(setq wiz_kword (getkword "\nSort by [X/Y/]?: "))
;_ end_cond;
(if (setq FOOT (ssget "C" po1 po2 (list (cons 0 "LWPOLYLINE") (cons 8 "S-FNDN"))))
(progn
(cond
((= wiz_kword "X") (setq wiz_get '(cadr)) (wiz_run))
((= wiz_kword "Y") (setq wiz_get '(caddr)) (wiz_run))
(t (exit))
) ;_ end_cond
(setq NOF (sslength FOOT))
(setq ENTER 0)
(setq f+ (rtos enter 2 0))
(REPEAT NOF
(PROGN
;(setq linc (ssname FOOT ENTER))
(setq linc (nth ENTER wiz_sorted))
(setq ENTER (1+ ENTER))
(setq f+ (rtos enter 2 0))
(SETQ link (strcat "f_" f+))
(set (read link) linc)
(setq elst (entget linc))
(foreach
item
ELST
(if (eq (car item) 10)
(setq pts (cons (cdr item) PTS))
) ;_ end_if
) ;_ end_foreach
(setq P1 (car PTS))
;;;(setq P3 (caddr PTS))
;;;(setq P2 (cadr PTS))
(setq P4 (cadddr PTS))
) ;_ end_PROGN
) ;_ end_REPEAT
) ;_ end_progn
) ;_ end_if
) ;_ end_DEFUN
|
|
#9
|
||||
|
||||
|
I just saw that you're trying to sort Lwpolylines by x and y which makes it more complicated. the routine i posted was from my other program which sorts blocks having assoc 10. then better is way through bounding box of each object. i'll see what i can come up with later at home. sorry for confusing.
|
|
#10
|
||||
|
||||
|
May just flat out need more info here.
Like just what are we sorting--will it/they have ambiguous definitions (like some bigger, some smaller, requiring sorting assoc 11 as well as assoc 10)? Also, does this need a "pure" sort, as in least X .AND. least Y, as opposed to either least X or least Y. Almost sounds like what is needed is to make a list in a particular order, rather than an on-the-fly sorting of collected data. Which can make a difference in meeting the percieved needs. |
| Thread Tools | |
| Display Modes | |
|
|