Go Back   Cadalyst Discussion Forums > Forums > Hot Tip Harry: AutoCAD Customization
FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Notices

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  
Old 10-22-2008, 11:34 PM
khadree_shariff's Avatar
khadree_shariff khadree_shariff is offline
Junior Member
 
Join Date: Oct 2006
Posts: 26
Default selection order !(by coordinates)!

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  
Old 10-23-2008, 04:28 AM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

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  
Old 10-23-2008, 07:45 AM
Cap'n Mac's Avatar
Cap'n Mac Cap'n Mac is offline
Senior Member
 
Join Date: May 2002
Location: Bryan, Texas
Posts: 2,195
Default

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  
Old 10-23-2008, 07:59 AM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

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  
Old 10-23-2008, 09:36 AM
Cap'n Mac's Avatar
Cap'n Mac Cap'n Mac is offline
Senior Member
 
Join Date: May 2002
Location: Bryan, Texas
Posts: 2,195
Default

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  
Old 10-23-2008, 11:01 PM
khadree_shariff's Avatar
khadree_shariff khadree_shariff is offline
Junior Member
 
Join Date: Oct 2006
Posts: 26
Default

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  
Old 10-24-2008, 12:09 AM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

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  
Old 10-24-2008, 12:30 AM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

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  
Old 10-24-2008, 12:44 AM
wizman's Avatar
wizman wizman is offline
Senior Member
 
Join Date: Sep 2004
Location: Abu Dhabi / Philippines
Posts: 276
Default

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  
Old 10-24-2008, 07:37 AM
Cap'n Mac's Avatar
Cap'n Mac Cap'n Mac is offline
Senior Member
 
Join Date: May 2002
Location: Bryan, Texas
Posts: 2,195
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:24 AM.





Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.