Solved! Go to Solution.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@saitoib wrote:
....I think the value obtained by (ssname ss i) is the memory address of the variable.Is it possible to sort by this value order? ....
The value obtained by (ssname ss i) would be an entity name. I'm not on an AutoCAD computer right now, so I can't test whether those can be compared in a way that you could sort them by -- they sort of look numerical and/or like text, but they're not really numbers or text strings. But entity names can be different from one session to another, so I would expect that you could get different results at different times from sorting the same group of entities, selected in the same way, and using the same sorting function.
But you could sort by handles: (cdr (assoc 5 (entget (ssname ss i)))) Those don't change from one session to another. And though they are not always sequential [there can be gaps], I think they only increase as objects are added. If that's right, you should be able to sort things by their handles and always get drawing order. But they're hexadecimal "numbers" [actually text strings in hexadecimal format], so they would need to be converted for sorting [there are converter functions around].
@saitoib wrote:
....I think the value obtained by (ssname ss i) is the memory address of the variable.Is it possible to sort by this value order? ....
The value obtained by (ssname ss i) would be an entity name. I'm not on an AutoCAD computer right now, so I can't test whether those can be compared in a way that you could sort them by -- they sort of look numerical and/or like text, but they're not really numbers or text strings. But entity names can be different from one session to another, so I would expect that you could get different results at different times from sorting the same group of entities, selected in the same way, and using the same sorting function.
But you could sort by handles: (cdr (assoc 5 (entget (ssname ss i)))) Those don't change from one session to another. And though they are not always sequential [there can be gaps], I think they only increase as objects are added. If that's right, you should be able to sort things by their handles and always get drawing order. But they're hexadecimal "numbers" [actually text strings in hexadecimal format], so they would need to be converted for sorting [there are converter functions around].
@saitoib . As I can see , the SS,both by ssget or by activeselectionset order, is in reverse as it were add.
Handle is in the same order it were add.
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;; Copyleft 1995-2022 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM
;;
; Hecho por Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;; Copyleft 1995-2022 por Gabriel Calos De Vit
;; DEVITG@GMAIL.COM
;;;
;;************************************************************
;;;get-ss-order
(progn
;
;;-------------------------------------------------------------------------------------------------
;; hex2int.lsp
;; Hexadecimal to base-10 Integer converter [e.g. for entity handles]
;; Modified/simplified from Frank Oquendo's (basetodecimal) function.
;; Added negative-argument capability and argument validity controls.
;; Kent Cooper, January 2011
(DEFUN HEX2INT/HNDL$ (HNDL / RESULT NEG POWER TMP)
(IF (/= (TYPE HNDL) 'STR)
(PROGN
(ALERT "Requires string argument.")
(HEX2INT/HNDL$)
) ; end progn
) ; end if
(SETQ
HNDL (STRCASE HNDL)
RESULT 0
) ; end setq
(IF (= (SUBSTR HNDL 1 1) "-")
(SETQ NEG T
HNDL (SUBSTR HNDL 2))
) ; end if
(IF (/= (VL-STRING-TRIM "0123456789ABCDEF" HNDL) "")
(PROGN
(ALERT "Invalid hexadecimal string.")
(QUIT)
) ; end progn
) ; end if
(REPEAT (SETQ POWER (STRLEN HNDL))
(SETQ RESULT
(+
RESULT
(*
(-
(SETQ TMP (ASCII (SUBSTR HNDL 1 1)))
(IF (> TMP 64)
55
48)
) ; end -
(EXPT 16 (SETQ POWER (1- POWER)))
) ; end *
) ; end +
HNDL (SUBSTR HNDL 2)
) ; end setq
) ; end while
(IF NEG
(- RESULT)
RESULT)
) ; end defun - hex2int
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;************************************************************************************************
)
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
(DEFUN get-ss-order (/
ACAD-OBJ
ADOC
HND-$
HND-POINT
MODEL
OBJ
ORDER
POINT
SS
SS-0
SS-0-OBJ
SS-OBJ
SS-OBJ-0
UTILITY
)
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))
(setq UTILITY (VLA-GET-UTILITY adoc))
(setq ss (ssget "X" '((0 . "circle"))))
(setq ss-0 (ssname ss 0))
(setq ss-0-obj (VLAX-ENAME->VLA-OBJECT ss-0))
(setq ss-obj (VLA-GET-ACTIVESELECTIONSET adoc))
(setq ss-obj-0 (vla-item ss-obj 0)); just to compare is SS-ent , have the same order as activselectionset
(setq order 0)
;;;(setq obj ss-obj-0)
(VLAX-FOR
obj
ss-obj
(setq point (VLAX-CURVE-GETPOINTATPARAM obj 0))
(VLA-ADDTEXT model (itoa order) (VLAX-3D-POINT point) 200)
(setq hnd-point (VLAX-CURVE-GETPOINTATPARAM obj pi))
(setq
hnd-$ (VLA-ADDTEXT model (HEX2INT/HNDL$ (VLA-GET-HANDLE obj)) (VLAX-3D-POINT hnd-point) 100)
) ;_ setq
(vla-move
hnd-$
(VLAX-3D-POINT hnd-point)
(vla-polarpoint UTILITY (VLAX-3D-POINT hnd-point) pi 100)
) ;_ vla-move
(setq order (1+ order))
) ;_ VLAX-FOR
) ;end main defun
(DEFUN C:order# ()
(get-ss-order)
(prompt "Command Name : C:order#" )
(princ)
)
;|«Visual LISP© Format Options»
(100 2 1 2 T " " 100 6 0 0 1 nil T nil T)
;*** DO NOT add text below the comment! ***|;
@saitoib . As I can see , the SS,both by ssget or by activeselectionset order, is in reverse as it were add.
Handle is in the same order it were add.
;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
;;; Copyleft 1995-2022 by Gabriel Calos De Vit ; DEVITG@GMAIL.COM
;;
; Hecho por Gabo CALOS DE VIT de CORDOBA ARGENTINA
;;; Copyleft 1995-2022 por Gabriel Calos De Vit
;; DEVITG@GMAIL.COM
;;;
;;************************************************************
;;;get-ss-order
(progn
;
;;-------------------------------------------------------------------------------------------------
;; hex2int.lsp
;; Hexadecimal to base-10 Integer converter [e.g. for entity handles]
;; Modified/simplified from Frank Oquendo's (basetodecimal) function.
;; Added negative-argument capability and argument validity controls.
;; Kent Cooper, January 2011
(DEFUN HEX2INT/HNDL$ (HNDL / RESULT NEG POWER TMP)
(IF (/= (TYPE HNDL) 'STR)
(PROGN
(ALERT "Requires string argument.")
(HEX2INT/HNDL$)
) ; end progn
) ; end if
(SETQ
HNDL (STRCASE HNDL)
RESULT 0
) ; end setq
(IF (= (SUBSTR HNDL 1 1) "-")
(SETQ NEG T
HNDL (SUBSTR HNDL 2))
) ; end if
(IF (/= (VL-STRING-TRIM "0123456789ABCDEF" HNDL) "")
(PROGN
(ALERT "Invalid hexadecimal string.")
(QUIT)
) ; end progn
) ; end if
(REPEAT (SETQ POWER (STRLEN HNDL))
(SETQ RESULT
(+
RESULT
(*
(-
(SETQ TMP (ASCII (SUBSTR HNDL 1 1)))
(IF (> TMP 64)
55
48)
) ; end -
(EXPT 16 (SETQ POWER (1- POWER)))
) ; end *
) ; end +
HNDL (SUBSTR HNDL 2)
) ; end setq
) ; end while
(IF NEG
(- RESULT)
RESULT)
) ; end defun - hex2int
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;************************************************************************************************
)
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
(DEFUN get-ss-order (/
ACAD-OBJ
ADOC
HND-$
HND-POINT
MODEL
OBJ
ORDER
POINT
SS
SS-0
SS-0-OBJ
SS-OBJ
SS-OBJ-0
UTILITY
)
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))
(setq UTILITY (VLA-GET-UTILITY adoc))
(setq ss (ssget "X" '((0 . "circle"))))
(setq ss-0 (ssname ss 0))
(setq ss-0-obj (VLAX-ENAME->VLA-OBJECT ss-0))
(setq ss-obj (VLA-GET-ACTIVESELECTIONSET adoc))
(setq ss-obj-0 (vla-item ss-obj 0)); just to compare is SS-ent , have the same order as activselectionset
(setq order 0)
;;;(setq obj ss-obj-0)
(VLAX-FOR
obj
ss-obj
(setq point (VLAX-CURVE-GETPOINTATPARAM obj 0))
(VLA-ADDTEXT model (itoa order) (VLAX-3D-POINT point) 200)
(setq hnd-point (VLAX-CURVE-GETPOINTATPARAM obj pi))
(setq
hnd-$ (VLA-ADDTEXT model (HEX2INT/HNDL$ (VLA-GET-HANDLE obj)) (VLAX-3D-POINT hnd-point) 100)
) ;_ setq
(vla-move
hnd-$
(VLAX-3D-POINT hnd-point)
(vla-polarpoint UTILITY (VLAX-3D-POINT hnd-point) pi 100)
) ;_ vla-move
(setq order (1+ order))
) ;_ VLAX-FOR
) ;end main defun
(DEFUN C:order# ()
(get-ss-order)
(prompt "Command Name : C:order#" )
(princ)
)
;|«Visual LISP© Format Options»
(100 2 1 2 T " " 100 6 0 0 1 nil T nil T)
;*** DO NOT add text below the comment! ***|;
That's fine about sorting by handles, but what about the impact of spatial indexing (DRAWORDER)?
I think it may be a matter of perspective as to whether the chicken came before the egg.
Then again it does make sense to follow the old entnext system and To HELLo With draworder.
John F. Uhden
That's fine about sorting by handles, but what about the impact of spatial indexing (DRAWORDER)?
I think it may be a matter of perspective as to whether the chicken came before the egg.
Then again it does make sense to follow the old entnext system and To HELLo With draworder.
John F. Uhden
@john.uhden , Hi John, please clear me about the way handle could be changed by draworder
And to use entnext, how to know which one is the first ent ?
@john.uhden , Hi John, please clear me about the way handle could be changed by draworder
And to use entnext, how to know which one is the first ent ?
Just a quick dirty check draw order does not change the handle ID.
I think Kent is right with sort handle
((integervalueofhandle <Entity name: 23648c4d140>orHandle)(integervalueofhandle <Entity name: 23648c4d140>orHandle).......
Then no need to convert back to which entity.
Just a quick dirty check draw order does not change the handle ID.
I think Kent is right with sort handle
((integervalueofhandle <Entity name: 23648c4d140>orHandle)(integervalueofhandle <Entity name: 23648c4d140>orHandle).......
Then no need to convert back to which entity.
Gabe, I didn't mean that draworder changes handles, but it can change the perception of what is newer vs. older.
(setq e (entnext)) gets you the first entity in the drawing.
Say you have a number of entities and you want to know the order of their creation...
(defun findorder (lst / e order)
;; where lst is a list of enames
(setq e (entnext))
(while (and e (< (length order)(length lst)))
(if (vl-position e lst)
(setq order (cons e order))
)
(setq e (entnext e))
)
(reverse order)
)
John F. Uhden
Gabe, I didn't mean that draworder changes handles, but it can change the perception of what is newer vs. older.
(setq e (entnext)) gets you the first entity in the drawing.
Say you have a number of entities and you want to know the order of their creation...
(defun findorder (lst / e order)
;; where lst is a list of enames
(setq e (entnext))
(while (and e (< (length order)(length lst)))
(if (vl-position e lst)
(setq order (cons e order))
)
(setq e (entnext e))
)
(reverse order)
)
John F. Uhden
@john.uhden if you use this defun
;*****************************************************************
(DEFUN SS-->>ENT-LIST/ss (SS) ;_01
(Reverse(VL-REMOVE-IF-NOT '(LAMBDA (X) (= (TYPE X) 'ENAME)) (MAPCAR 'CADR (SSNAMEX SS))))
)
;;;*************************************************************;;;
It return form first to last as been drawn . Because SSGET return the selectionset from Lasta to first
No need to calc anything .
Any way I almost do not use this defun , I like to handle by VL-function by VLA-GET-ACTIVESELECTIONSET adoc
(defun get-all-circle-area-sum (/ ACAD-OBJ ADOC AREA CIRCLE-ENT-SS CIRCLE-OBJ-SS MODEL
)
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))
(setq circle-ent-ss (ssget "X" '((0 . "circle"))))
(setq circle-obj-ss (VLA-GET-ACTIVESELECTIONSET adoc))
;then
(setq area nil)
(VLAX-FOR
circle-obj
circle-obj-ss
(setq area (+ area (VLA-GET-area circle-obj)))
) ;_ VLAX-FOR circle-obj
)
No need to know sslength , no need to get a Index counter
. It is my way .
@john.uhden if you use this defun
;*****************************************************************
(DEFUN SS-->>ENT-LIST/ss (SS) ;_01
(Reverse(VL-REMOVE-IF-NOT '(LAMBDA (X) (= (TYPE X) 'ENAME)) (MAPCAR 'CADR (SSNAMEX SS))))
)
;;;*************************************************************;;;
It return form first to last as been drawn . Because SSGET return the selectionset from Lasta to first
No need to calc anything .
Any way I almost do not use this defun , I like to handle by VL-function by VLA-GET-ACTIVESELECTIONSET adoc
(defun get-all-circle-area-sum (/ ACAD-OBJ ADOC AREA CIRCLE-ENT-SS CIRCLE-OBJ-SS MODEL
)
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))
(setq circle-ent-ss (ssget "X" '((0 . "circle"))))
(setq circle-obj-ss (VLA-GET-ACTIVESELECTIONSET adoc))
;then
(setq area nil)
(VLAX-FOR
circle-obj
circle-obj-ss
(setq area (+ area (VLA-GET-area circle-obj)))
) ;_ VLAX-FOR circle-obj
)
No need to know sslength , no need to get a Index counter
. It is my way .
@devitg schriebIt return form first to last as been drawn . Because SSGET return the selectionset from Lasta to first
That statement isn't correct (I think you know it, but some other readers today or in future not)
1. The order inside a selectionset is the order of selection
2. If you are using selection methods like windows windowpolygon cross crosspolygon box all...
AutoCAD use the creation-order <this is what you are talking about, selection set created by these methods>,And this happen for each select while selection.
Sample selectionset, created by 4 selections
[selectionset; [s1;picked:one object][s2;window: creation order][s3;faun:faundirection order][s4;cross:creation order]]
>>"No need to calc anything . "
If you like to have the creation order and if you don't allow selectionmethods like
Multiple, Implie, faun, pick .. than it is right, in othewr cases (what are common) it is wrong.
Sebastian
@devitg schriebIt return form first to last as been drawn . Because SSGET return the selectionset from Lasta to first
That statement isn't correct (I think you know it, but some other readers today or in future not)
1. The order inside a selectionset is the order of selection
2. If you are using selection methods like windows windowpolygon cross crosspolygon box all...
AutoCAD use the creation-order <this is what you are talking about, selection set created by these methods>,And this happen for each select while selection.
Sample selectionset, created by 4 selections
[selectionset; [s1;picked:one object][s2;window: creation order][s3;faun:faundirection order][s4;cross:creation order]]
>>"No need to calc anything . "
If you like to have the creation order and if you don't allow selectionmethods like
Multiple, Implie, faun, pick .. than it is right, in othewr cases (what are common) it is wrong.
Sebastian
Can't find what you're looking for? Ask the community or share your knowledge.