Author Topic: (entprev)  (Read 55594 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #75 on: November 27, 2013, 04:03:00 AM »
I think we might be talking in circles. The OP was about a function which operates in reverse from what entnext does.

So:
  • If supplied argument = nil (unfortunately ALisp doesn't allow for optional arguments in defuns), then get entlast (instead of the 1st entity in the DWG)
  • If supplied argument is an ename of an enetity contained either in the Model Space or any Paper Space then get the previous entity
    • That could be a joined entity like an attribute, not to be confused with nested entities like lines inside blocks.
    • Note entnext runs along all entities in MS/PS1/PS2 ... PSn as if they're all contained in one group (not each separately).
  • If the argument is an entity nested inside a complex entity like a block definition, then get the previous entity inside that block - stop at the block record itself.
Do you think that there is, at this time, a function that meets these three points?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #76 on: November 27, 2013, 04:05:54 AM »
Hi Marco,
Thank you a lot for taking the time to run the tests and doing the benchmarking.... for me I guess it is all about my contribution on this thread, was fun but I do not use autolisp nor I work with objectarx anymore or even use AutoCAD nowadays. My sample code is there open, so anyone can use it and update it and make it better!!!.

Have fun!
 :)
Grazie a te, spero di ritrovarti ancora.
Gracias a ti, espero encontrarte de nuevo.  :kewl:

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: (entprev)
« Reply #77 on: November 27, 2013, 05:16:32 AM »
Select the red line on magenta rectangle, is the (entlast) in model space,
results:
ssget generates selections set in a reversed order i.e. entlast is the first element. and still your function is iterating 2814 times. why? because it searches though all layouts.

entnext starts from the beginning and steps through all vertexes but doesn't go into layouts.

benchmark both function with (entnext (entnext)) as an argument  :)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #78 on: November 27, 2013, 06:25:15 AM »
ssget generates selections set in a reversed order i.e. entlast is the first element. and still your function is iterating 2814 times. why? because it searches though all layouts.
> entlast is the first element
I do not think so:
Comando: (setq kkkk (ssget "_X"))
<Selection set: 11b>
Comando: (ssname kkkk 0)
<Nome entità: 7ffffb60c70>
Comando: (entlast)
<Nome entità: 7ffffb61930>
Comando: (ssname kkkk 1)
<Nome entità: 7ffffb449f0>
Comando: (ssname kkkk (1- (sslength kkkk)))
<Nome entità: 7ffffb06700>
Comando: (ssname kkkk (sslength kkkk))
nil

entnext starts from the beginning and steps through all vertexes but doesn't go into layouts.
I think entnext steps through all entities (DWG with only 3 entities):
Code: [Select]
(defun VK_entprev1 (e / e1 e2 Countr)
  (setq Countr 0)
  (setq e1 (entnext))
  (while (and e1 (not (eq e (setq e2 (entnext e1)))))
    (setq e1 e2  Countr (1+ Countr))
    (princ "\n ") (princ (entget e2) )
  )
  (list e1 Countr)
)
>
((-1 . <Nome entità: 7ffffb60d60>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE8E) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1887.13 222.152 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0465439) (91 . 0) (70 . 0) (50 . 0.0))
 ((-1 . <Nome entità: 7ffffb60d70>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE8F) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1829.33 165.574 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0601886) (91 . 0) (70 . 0) (50 . 0.0))
...
 ((-1 . <Nome entità: 7ffffb60e50>) (0 . VERTEX) (330 . <Nome entità: 7ffffb60d50>) (5 . AE9D) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (100 . AcDbVertex) (100 . AcDb2dVertex) (10 1954.41 267.061 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0465439) (91 . 0) (70 . 0) (50 . 4.25351))
 ((-1 . <Nome entità: 7ffffb60e60>) (0 . SEQEND) (330 . <Nome entità: 7ffffb60d50>) (5 . AE9E) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (62 . 2) (-2 . <Nome entità: 7ffffb60d50>))
 ((-1 . <Nome entità: 7ffffb44a40>) (0 . VIEWPORT) (330 . <Nome entità: 7ffffb44a20>) (5 . 94D4) (100 . AcDbEntity) (67 . 1) (410 . L2) (8 . 0) (100 . AcDbViewport) (10 975.889 259.916 0.0) (40 . 396.146) (41 . 286.588) (68 . 1) (69 . 1) (12 975.889 259.916 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 286.588) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffb06170>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
 ((-1 . <Nome entità: 7ffffbf7cc0>) (0 . CIRCLE) (330 . <Nome entità: 7ffffb44a20>) (5 . B08C) (100 . AcDbEntity) (67 . 1) (410 . L2) (8 . 0) (100 . AcDbCircle) (10 891.453 209.204 0.0) (40 . 33.0551) (210 0.0 0.0 1.0))

benchmark both function with (entnext (entnext)) as an argument
Why?

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: (entprev)
« Reply #79 on: November 27, 2013, 06:49:58 AM »
I do not think so:
it's a well known fact

if you want to test (ssget "_X")
create an empty drawing
draw a line
draw a circle
switch to Layout1
draw a polyline
draw a point
switch to Layout2
draw an arc
draw a text
then inspect (ssname "_X") in vlide
you will see that you line is the last element because http://www.theswamp.org/index.php?topic=45732.msg508993#msg508993

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: (entprev)
« Reply #80 on: November 27, 2013, 08:16:37 AM »
Sorry new to this thread, but I would naturally assume ssget would select items in the same order as the draw order in ACAD essentially by their order in the DB.  So not only would it be dependent on when they where created but also edited or modified, you could also manipulate the order with the "draw order" command. 

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #81 on: November 27, 2013, 08:52:32 AM »
I do not think so:
it's a well known fact

if you want to test (ssget "_X")
create an empty drawing
draw a line
draw a circle
switch to Layout1
draw a polyline
draw a point
switch to Layout2
draw an arc
draw a text
then inspect (ssname "_X") in vlide
you will see that you line is the last element because http://www.theswamp.org/index.php?topic=45732.msg508993#msg508993

With your DWG
From MSpace:
Code: [Select]
Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfb1a0>) (0 . "TEXT") (330 . <Nome entità: 7ffffbfb060>) (5 . "19C2") (100 . "AcDbEntity") (67 . 1) (410 . "Layout2") (8 . "$XP_COM_NORM") (100 . "AcDbText") (10 10.0 10.0 0.0) (40 . 2.0) (1 . "123") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "$STD_ISO") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

Comando:   <Passaggio a: Layout1>
Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfb050>) (0 . "POINT") (330 . <Nome entità: 7ffffbfe8d0>) (5 . "19AD") (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "$XP_COM_NORM") (100 . "AcDbPoint") (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (50 . 0.0))

Comando:   <Passaggio a: Layout2>
Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfb1a0>) (0 . "TEXT") (330 . <Nome entità: 7ffffbfb060>) (5 . "19C2") (100 . "AcDbEntity") (67 . 1) (410 . "Layout2") (8 . "$XP_COM_NORM") (100 . "AcDbText") (10 10.0 10.0 0.0) (40 . 2.0) (1 . "123") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "$STD_ISO") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

From MSpace:
Comando: _line
Specificare primo punto: 20,20
Specificare punto successivo o [Annulla]: 30,30
Specificare punto successivo o [Annulla]:

Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfbb90>) (0 . "LINE") (330 . <Nome entità: 7ffffbfe820>) (5 . "1A59") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "$COM_NORM") (100 . "AcDbLine") (10 20.0 20.0 0.0) (11 30.0 30.0 0.0) (210 0.0 0.0 1.0))

Comando:   <Passaggio a: Layout1>
Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfb050>) (0 . "POINT") (330 . <Nome entità: 7ffffbfe8d0>) (5 . "19AD") (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "$XP_COM_NORM") (100 . "AcDbPoint") (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (50 . 0.0))

Comando:   <Passaggio a: Layout2>
Comando: (entget (entlast))
((-1 . <Nome entità: 7ffffbfb1a0>) (0 . "TEXT") (330 . <Nome entità: 7ffffbfb060>) (5 . "19C2") (100 . "AcDbEntity") (67 . 1) (410 . "Layout2") (8 . "$XP_COM_NORM") (100 . "AcDbText") (10 10.0 10.0 0.0) (40 . 2.0) (1 . "123") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "$STD_ISO") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))
(entlast) > the result may change going from one Layout to another Layout

LE3

  • Guest
Re: (entprev)
« Reply #82 on: November 27, 2013, 09:09:52 AM »
Hi Marco,
Thank you a lot for taking the time to run the tests and doing the benchmarking.... for me I guess it is all about my contribution on this thread, was fun but I do not use autolisp nor I work with objectarx anymore or even use AutoCAD nowadays. My sample code is there open, so anyone can use it and update it and make it better!!!.

Have fun!
 :)
Grazie a te, spero di ritrovarti ancora.
Gracias a ti, espero encontrarte de nuevo.  :kewl:
Grazie Marco, so che sarà difficile non partecipare...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #83 on: November 27, 2013, 09:11:34 AM »
Sorry new to this thread, but I would naturally assume ssget would select items in the same order as the draw order in ACAD essentially by their order in the DB.  So not only would it be dependent on when they where created but also edited or modified,
OK

you could also manipulate the order with the "draw order" command.

I do not think so:
Code: [Select]
(defun C:PrintSS ( / Countr SelSet)
  (setq SelSet (ssget "_X")   Countr 0)
  (repeat (sslength SelSet)
    (princ "\n ") (princ (entget (ssname SelSet Countr)))
    (setq Countr (1+ Countr))
  )
  (princ)
)

Comando: PRINTSS
 ((-1 . <Nome entità: 7ffffbfb050>) (0 . POINT) (330 . <Nome entità: 7ffffbfe8d0>) (5 . 19AD) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . $XP_COM_NORM) (100 . AcDbPoint) (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (50 . 0.0))
 ((-1 . <Nome entità: 7ffffbfb000>) (0 . POLYLINE) (330 . <Nome entità: 7ffffbfe8d0>) (5 . 19A8) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . $XP_COM_NORM) (100 . AcDb2dPolyline) (66 . 1) (10 0.0 0.0 0.0) (70 . 0) (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 . 0) (75 . 0))
 ((-1 . <Nome entità: 7ffffbfe8e0>) (0 . VIEWPORT) (330 . <Nome entità: 7ffffbfe8d0>) (5 . E) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbViewport) (10 128.5 97.5 0.0) (40 . 958.196) (41 . 693.198) (68 . 1) (69 . 1) (12 128.5 97.5 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 693.198) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffbbc1f0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
 ((-1 . <Nome entità: 7ffffbfb1a0>) (0 . TEXT) (330 . <Nome entità: 7ffffbfb060>) (5 . 19C2) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . $XP_COM_NORM) (100 . AcDbText) (10 10.0 10.0 0.0) (40 . 2.0) (1 . 123) (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . $STD_ISO) (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . AcDbText) (73 . 0))
 ((-1 . <Nome entità: 7ffffbfb170>) (0 . ARC) (330 . <Nome entità: 7ffffbfb060>) (5 . 19BF) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . $XP_COM_NORM) (100 . AcDbCircle) (10 20.0 20.0 0.0) (40 . 14.1421) (210 0.0 0.0 1.0) (100 . AcDbArc) (50 . 3.92699) (51 . 4.45059))
 ((-1 . <Nome entità: 7ffffbfb140>) (0 . VIEWPORT) (5 . 19BC) (102 . {ACAD_XDICTIONARY) (360 . <Nome entità: 7ffffbfb150>) (102 . }) (330 . <Nome entità: 7ffffbfb060>) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . 0) (100 . AcDbViewport) (10 31.6168 40.5766 0.0) (40 . 96.4091) (41 . 69.7462) (68 . 1) (69 . 1) (12 31.6168 40.5766 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 69.7462) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffbbc1f0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
 ((-1 . <Nome entità: 7ffffb05020>) (0 . LINE) (330 . <Nome entità: 7ffffbfe820>) (5 . 1A9A) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbLine) (10 1.0 1.0 0.0) (11 5.0 5.0 0.0) (210 0.0 0.0 1.0))
 ((-1 . <Nome entità: 7ffffbbced0>) (0 . CIRCLE) (330 . <Nome entità: 7ffffbfe820>) (5 . 199D) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbCircle) (10 10.0 10.0 0.0) (40 . 10.0) (210 0.0 0.0 1.0))
 ((-1 . <Nome entità: 7ffffbbcec0>) (0 . LINE) (330 . <Nome entità: 7ffffbfe820>) (5 . 199C) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbLine) (10 0.0 0.0 0.0) (11 10.0 10.0 0.0) (210 0.0 0.0 1.0))


Comando: AI_DRAWORDER ... bla ... bla ...

Comando: PRINTSS
 ((-1 . <Nome entità: 7ffffbfb050>) (0 . POINT) (330 . <Nome entità: 7ffffbfe8d0>) (5 . 19AD) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . $XP_COM_NORM) (100 . AcDbPoint) (10 0.0 0.0 0.0) (210 0.0 0.0 1.0) (50 . 0.0))
 ((-1 . <Nome entità: 7ffffbfb000>) (0 . POLYLINE) (330 . <Nome entità: 7ffffbfe8d0>) (5 . 19A8) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . $XP_COM_NORM) (100 . AcDb2dPolyline) (66 . 1) (10 0.0 0.0 0.0) (70 . 0) (40 . 0.0) (41 . 0.0) (210 0.0 0.0 1.0) (71 . 0) (72 . 0) (73 . 0) (74 . 0) (75 . 0))
 ((-1 . <Nome entità: 7ffffbfe8e0>) (0 . VIEWPORT) (330 . <Nome entità: 7ffffbfe8d0>) (5 . E) (100 . AcDbEntity) (67 . 1) (410 . Layout1) (8 . 0) (100 . AcDbViewport) (10 128.5 97.5 0.0) (40 . 958.196) (41 . 693.198) (68 . 1) (69 . 1) (12 128.5 97.5 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 693.198) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffbbc1f0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
 ((-1 . <Nome entità: 7ffffbfb1a0>) (0 . TEXT) (330 . <Nome entità: 7ffffbfb060>) (5 . 19C2) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . $XP_COM_NORM) (100 . AcDbText) (10 10.0 10.0 0.0) (40 . 2.0) (1 . 123) (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . $STD_ISO) (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . AcDbText) (73 . 0))
 ((-1 . <Nome entità: 7ffffbfb170>) (0 . ARC) (330 . <Nome entità: 7ffffbfb060>) (5 . 19BF) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . $XP_COM_NORM) (100 . AcDbCircle) (10 20.0 20.0 0.0) (40 . 14.1421) (210 0.0 0.0 1.0) (100 . AcDbArc) (50 . 3.92699) (51 . 4.45059))
 ((-1 . <Nome entità: 7ffffbfb140>) (0 . VIEWPORT) (5 . 19BC) (102 . {ACAD_XDICTIONARY) (360 . <Nome entità: 7ffffbfb150>) (102 . }) (330 . <Nome entità: 7ffffbfb060>) (100 . AcDbEntity) (67 . 1) (410 . Layout2) (8 . 0) (100 . AcDbViewport) (10 31.6168 40.5766 0.0) (40 . 96.4091) (41 . 69.7462) (68 . 1) (69 . 1) (12 31.6168 40.5766 0.0) (13 0.0 0.0 0.0) (14 10.0 10.0 0.0) (15 10.0 10.0 0.0) (16 0.0 0.0 1.0) (17 0.0 0.0 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 69.7462) (50 . 0.0) (51 . 0.0) (72 . 100) (90 . 819232) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Nome entità: 7ffffbbc1f0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))
 ((-1 . <Nome entità: 7ffffb05020>) (0 . LINE) (330 . <Nome entità: 7ffffbfe820>) (5 . 1A9A) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbLine) (10 1.0 1.0 0.0) (11 5.0 5.0 0.0) (210 0.0 0.0 1.0))
 ((-1 . <Nome entità: 7ffffbbced0>) (0 . CIRCLE) (330 . <Nome entità: 7ffffbfe820>) (5 . 199D) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbCircle) (10 10.0 10.0 0.0) (40 . 10.0) (210 0.0 0.0 1.0))
 ((-1 . <Nome entità: 7ffffbbcec0>) (0 . LINE) (330 . <Nome entità: 7ffffbfe820>) (5 . 199C) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . $COM_NORM) (100 . AcDbLine) (10 0.0 0.0 0.0) (11 10.0 10.0 0.0) (210 0.0 0.0 1.0))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: (entprev)
« Reply #84 on: November 27, 2013, 09:24:47 AM »
Selection sets may be influenced by the Layouts, I don't truly know, but that's not the point of this thread is it?

But I do know that entnext and entlast is not affected by them at all. E.g. I started a new blank DWG from acadiso.dwt. Then drew a circle and a line in the model space. Then swapped to Layout 1 and placed a text, selected it copy-pasted into Layout 2. Then swapped back to Model and drew an arc. So the circle is the 1st entity drawn, and the arc the last. And that is exactly what entnext and entlast shows - no matter what layout is current:
Code: [Select]
Command: (setq en (entnext))
<Entity name: 7ffffb95cc0>
Command: (while en (setq ed (entget en) en (entnext en)) (print (strcat (cdr (assoc 0 ed)) " on " (cdr (assoc 410 ed)))))
"CIRCLE on Model"
"LINE on Model"
"VIEWPORT on Layout1"
"MTEXT on Layout1"
"ARC on Model" "ARC on Model"
Command: (setq ed (entget (entlast)))
((-1 . <Entity name: 7ffffb961d0>) (0 . "ARC") (330 . <Entity name: 7ffffb929f0>) (5 . "28D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle") (10 4054.01 380.296 0.0) (40 . 1618.93) (210 0.0 0.0 1.0) (100 . "AcDbArc") (50 . 1.09233) (51 . 3.0848))
Then swap to a Layout tab and try again
Code: [Select]
Command: CTAB
Enter new value for CTAB <"Model">: Layout1
Restoring cached viewports - Regenerating layout.
Command: (setq en (entnext))
<Entity name: 7ffffb95cc0>
Command: (while en (setq ed (entget en) en (entnext en)) (print (strcat (cdr (assoc 0 ed)) " on " (cdr (assoc 410 ed)))))
"CIRCLE on Model"
"LINE on Model"
"VIEWPORT on Layout1"
"MTEXT on Layout1"
"ARC on Model" "ARC on Model"
Command: (setq ed (entget (entlast)))
((-1 . <Entity name: 7ffffb961d0>) (0 . "ARC") (330 . <Entity name: 7ffffb929f0>) (5 . "28D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle") (10 4054.01 380.296 0.0) (40 . 1618.93) (210 0.0 0.0 1.0) (100 . "AcDbArc") (50 . 1.09233) (51 . 3.0848))
Exact same result.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: (entprev)
« Reply #85 on: November 27, 2013, 09:46:06 AM »
(entlast) > the result may change going from one Layout to another Layout
that's an old bug
and i think it's somehow bugged because of this:


ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: (entprev)
« Reply #86 on: November 27, 2013, 09:57:48 AM »
My current version, regards the fact that (entnext) is going and inspecting all entities from all Layouts is this version of VovKa's code - only mods is if checking entity is the first one in database - it should return nil...

Code - Auto/Visual Lisp: [Select]
  1. (defun VovKa-MR-entprev (e / e1 e2)
  2.   (if (eq (type e) 'ename)
  3.     (if (eq e (entnext))
  4.       nil
  5.       (progn
  6.         (setq e1 (entnext))
  7.         (while (and e1 (not (eq e (setq e2 (entnext e1)))))
  8.           (setq e1 e2)
  9.         )
  10.         e1
  11.       )
  12.     )
  13.     (progn (prompt "\n; error: bad argument type: lentityp ")(princ e)(princ))
  14.   )
  15. )
  16.  

So, please when benchmarking, take this code in consideration among others that are correct (I don't know much ab. arx and other languages)...

OP, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #87 on: November 27, 2013, 10:10:52 AM »
...
"CIRCLE on Model"
"LINE on Model"
"VIEWPORT on Layout1"
"MTEXT on Layout1"
"ARC on Model" "ARC on Model"
...

...and where is "TEXT on Layout2"?

I get this (AutoCAD 2013 Mech.):
Code: [Select]
Comando: (setq en (entnext))
<Nome entità: 7ffffbca340>

Comando: (while en (setq ed (entget en) en (entnext en)) (print (strcat (cdr (assoc 0 ed)) " on " (cdr (assoc 410 ed)))))

"CIRCLE on Model"
"LINE on Model"
"VIEWPORT on Layout2"
"TEXT on Layout2"
"ARC on Model" "ARC on Model"

Comando: (setq ed (entget (entlast)))
((-1 . <Nome entità: 7ffffbca700>) (0 . "ARC") (330 . <Nome entità: 7ffffbaff10>) (5 . "E8") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbCircle") (10 577.904 218.872 0.0) (40 . 60.8391) (210 0.0 0.0 1.0) (100 . "AcDbArc") (50 . 1.47854) (51 . 2.12479))

Comando: CTAB

Digitare nuovo valore per CTAB <"Model">: Layout1
Ripristino finestre memorizzate nella cache in corso - Rigenerazione layout in corso.

Comando: (setq en (entnext))
<Nome entità: 7ffffbca340>

Comando: (while en (setq ed (entget en) en (entnext en)) (print (strcat (cdr (assoc 0 ed)) " on " (cdr (assoc 410 ed)))))

"CIRCLE on Model"
"LINE on Model"
"ARC on Model"
"VIEWPORT on Layout1"
"TEXT on Layout1" "TEXT on Layout1"

Comando: (setq ed (entget (entlast)))
((-1 . <Nome entità: 7ffffbca550>) (0 . "TEXT") (330 . <Nome entità: 7ffffbafed0>) (5 . "CD") (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "0") (100 . "AcDbText") (10 -203.743 43.1176 0.0) (40 . 23.0115) (1 . "123") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #88 on: November 27, 2013, 10:18:07 AM »
(entlast) > the result may change going from one Layout to another Layout
that's an old bug
and i think it's somehow bugged because of this:

this is mine


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: (entprev)
« Reply #89 on: November 27, 2013, 10:37:44 AM »
...
So, please when benchmarking, take this code in consideration among others that are correct (I don't know much ab. arx and other languages)...

OP, M.R.
Remember that the code in VovKa-MR-entprev do not work if you select
a block (not the attribs).