Author Topic: ??  (Read 4566 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
??
« on: June 30, 2004, 11:35:03 AM »
What, no hacks today? Is it a holiday 'over there'?

Hmmm, ok here's an easy one: When ENTDEL can both delete and undelete an entity, why can this not be used to both delete all and restore all objects?
Code: [Select]
(defun deleteall (/ ent first)
  (setq ent (entnext))        ;get first entity
                              ;continue until entnext returns nil
  (while ent
    (entdel ent)              ;delete (or restore??) entity
    (setq ent (entnext ent))  ;get next entity
  )
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
??
« Reply #1 on: June 30, 2004, 11:41:48 AM »
<guess=on>

I believe internally a linked list type structure is employed, that's why entnext works as it does. As soon as an entity is deleted the linked list pointers are updated, negating the ability to navigate deleted entities via entnext type iteration methods.

If you created a list of the entity names as you deleted them you could use that data to "undelete" 'em later.

<guess=off>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
??
« Reply #2 on: June 30, 2004, 12:04:26 PM »
Heh, "easy one" ...?!

Because your deleting it out of the database?

You can undelete if you store only the name?!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: ??
« Reply #3 on: June 30, 2004, 02:11:54 PM »
It is quiet today in almost all forums that I frequent.
As for the code, I agree with MP. Store the enames in a list and then entdel each of those to restore them.

Quote from: SMadsen
What, no hacks today? Is it a holiday 'over there'?

Hmmm, ok here's an easy one: When ENTDEL can both delete and undelete an entity, why can this not be used to both delete all and restore all objects?
Code: [Select]
(defun deleteall (/ ent first)
  (setq ent (entnext))        ;get first entity
                              ;continue until entnext returns nil
  (while ent
    (entdel ent)              ;delete (or restore??) entity
    (setq ent (entnext ent))  ;get next entity
  )
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
??
« Reply #4 on: June 30, 2004, 02:13:50 PM »
Well my first thougt would be to use entity handles, since you can increment them as hex numbers.

Something along the lines of
Code: [Select]

(setq index (cdr(assod 5 (entlast))))
(while (> index 0)
(setq enthandle (hex index))
(if enthandle
 (entdel (handent enthandle))
)
(setq index (1- index))
)


OF course the HEX function is not defined and I do not have the time at the moment to do so...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
??
« Reply #5 on: June 30, 2004, 02:29:48 PM »
Told ya it was an easy one :)

ENTNEXT retrieves the next non-deleted entity. Which is fine on the way to deletion but bad on the way to recovery.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
??
« Reply #6 on: June 30, 2004, 02:32:00 PM »
...so there is essetialy a database kept of deleted items. Soooo using MP's method you could then re-create the entity.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
??
« Reply #7 on: June 30, 2004, 02:33:54 PM »
Well, I have not seen many people using handles in lisp programming, but it is quite easy considering that they don't change until you wblock a drawing.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
??
« Reply #8 on: June 30, 2004, 02:39:04 PM »
Quote from: Se7en
...so there is essetialy a database kept of deleted items. Soooo using MP's method you could then re-create the entity.

Yes, entities are merely 'tagged' as undeleted, not removed from the drawing database until the drawing closes.
The tag prevents functions such as ENTNEXT, ENTLAST and ENTGET to access it but not - as Keith points out - HANDENT because they still reside in the database with all the data intact.

Selection sets can also hold deleted entities so in addition to Michael's list, you can also create an empty sset, fill it with entities as they are deleted and later restore the entire selection set.

SMadsen

  • Guest
??
« Reply #9 on: June 30, 2004, 03:02:14 PM »
By the way. MP, I'm guessing the same thing - that the pointer is removed from a linked list of pointers (and inserted again).

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
??
« Reply #10 on: June 30, 2004, 07:21:56 PM »
Quote from: Keith
Well my first thougt would be to use entity handles, since you can increment them as hex numbers.

If I'm not mistaken the difference is that hex incrementing would allow you to truly iterate the database entity by entity (testing for null results where there are holes, and there are holes), which includes things like non-graphical objects (table entries, dictionaries etc.), whereas entnext iterates only graphical objects like lines, arcs, blocks, attributes ... so (and this is my point) the behavior of an iterator based on handles would not be the same as one based on enames (in this context).

Quote from: Keith
OF course the HEX function is not defined and I do not have the time at the moment to do so...

I wrote the following fugly awhile ago to provide the ability to increment HUGE hex numbers, something the other hex incrementers I've seen will not do, as they temporarilly convert to an integer for the incrementation, and then back to hex for the result, meaning there is a ceiling of 2^30. It looks fugly but it does work (did the last time I tried it anyway) ... oh yea, forgive the coding, it really wasn't meant for public consumption; nominal comments to be found. :(

Code: [Select]

(defun hex++ ( hex / __put lst i j a b )

    ;;
    ;;  Copyright © 2004 Michael Puckett
    ;;

    (defun __put ( item position lst / i )
        (setq i -1)
        (mapcar
           '(lambda (x)
                (if (eq position (setq i (1+ i)))
                    item
                    x
                )
            )
            lst
        )
    )
     
    ;;
    ;;  main ...
    ;;

    (setq lst
        (cons
            (1+
                (car
                    (setq lst
                        (reverse
                            (vl-string->list
                                (strcase hex)
                            )
                        )
                    )
                )
            )
            (cdr lst)
        )
    )

    (setq i -1)

    (while (setq a (nth (setq i (1+ i)) lst))
        (cond
            (   (< 70 a) ;; "G" and greater
                (setq lst
                    (if (setq b (nth (setq j (1+ i)) lst))
                        (__put (1+ b) j (__put 48 i lst))
                        (append (__put 48 i lst) (list 49))
                    )
                )
            )
            (   (eq 58 a) ;; ":"
                (setq lst (__put 65 i lst)) ;; replace w/"A"
            )
        )
    )
   
    ;;
    ;;  return the fruit of our labours ...
    ;;

    (vl-list->string (reverse lst))

)


Oh yeah, there is no hand holding, Hex++ expect you to provide a valid hex number as the sole argument. Passing anything else results in an undefined result.

(Hex++ "FFFFFFFFFFFFFFFF")  ==>  "10000000000000000"

And now for some fun.

Think you know lisp? What should this result be:

(abs (expt 2 31))

A really large postive integer right? lol, try it.

<hoping some portion of this post is useful>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
??
« Reply #11 on: June 30, 2004, 07:27:36 PM »
Quote from: SMadsen
By the way. MP, I'm guessing the same thing - that the pointer is removed from a linked list of pointers (and inserted again).

The behavior of entnext, tblnext, dictnext ... sure suggests linked lists are the under pinning to me, but I've been wrong too many times, so perhaps not! :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SMadsen

  • Guest
??
« Reply #12 on: July 01, 2004, 04:04:14 AM »
Or
(1+ 2147483648) = 2147483649

while
(1+ 2147483647) = -2147483648

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
??
« Reply #13 on: July 01, 2004, 08:30:23 AM »
belly interestink
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
??
« Reply #14 on: July 01, 2004, 09:51:12 AM »
Quote from: SMadsen
(1+ 2147483648) = 2147483649

Whoops, that should of course have been
(1+ 2147483648) = 2147483649.0