Author Topic: Using 'entdel' to delete a block definition  (Read 4631 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Using 'entdel' to delete a block definition
« on: June 09, 2008, 01:19:34 PM »
I'm on this kick of using the standard lisp functions in my codes now, and I saw a question that seems pretty simple, how to detach all xref overlays?, so I thought I would take it up with standard lisp.  My idea was to delete all inserted references, which wasn't hard, then delete the block definition, which I thought wouldn't be hard, but has proven to be hard.  I have tried to delete the block_record and block, but neither one seems to work.

Any/all help is appreciated.  Thanks in advance.

Code: [Select]
(defun c:Test (/ Ent tempData tempEnt tempList NewData tempName)
   
    (while (setq Ent (tblnext "block" (not Ent)))
        (if (equal (logand (cdr (assoc 70 Ent)) 8) 8)
            (progn
                (setq tempData
                    (entget
                        (cdr
                            (assoc
                                330
                                (entget (setq tempEnt (tblobjname "block" (setq tempName (cdr (assoc 2 Ent))))))
                            )
                        )
                    )
                )
                (if (setq tempList (member '(102 . "{BLKREFS") tempData))
                    (progn
                        (foreach i tempList
                            (if (equal (car i) 331)
                                (entdel (cdr i))
                            )
                        )
                        (setq NewData nil)
                        (foreach i tempData
                            (if (not (member i tempList))
                                (setq NewData (cons i NewData))
                            )
                        )
                        (if
                            (and
                                (entmod (reverse NewData))
                                (or
                                    (entdel (cdr (assoc -1 NewData)))
                                    (entdel (tblobjname "block" tempName))
                                )
                            )
                            (prompt (strcat "\n Overlay xref \"" tempName "\" has been deleted/detached."))
                            (prompt (strcat "\n Overlay xref \"" tempName "\" has NOT been deleted/detached."))
                        )
                    )
                )
            )
        )
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'entdel' to delete a block definition
« Reply #1 on: June 09, 2008, 02:22:10 PM »
Are you sure this is not what you need?
Code: [Select]
(= 4 (logand (cdr (assoc 70 ent)) 4))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #2 on: June 09, 2008, 02:26:37 PM »
Are you sure this is not what you need?
Code: [Select]
(= 4 (logand (cdr (assoc 70 ent)) 4))
That will tell you it's an xref, but 8 will let you know if it's an Overlay xref.

Quote
70
 Block-type flags (bit-coded values, may be combined):

0 = Indicates none of the following flags apply

1 = This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application

2 = This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all)

4 = This block is an external reference (xref)

8 = This block is an xref overlay

16 = This block is externally dependent

32 = This is a resolved external reference, or dependent of an external reference (ignored on input)

64 = This definition is a referenced external reference (ignored

on input)
 
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using 'entdel' to delete a block definition
« Reply #3 on: June 09, 2008, 03:46:45 PM »
Sorry I just got back & need to leave again.
Looking for a way I got this to work.
Not sure if it was your exact intent.
Back later.
Code: [Select]
(defun c:TestCAB (/ Ent tempData tempEnt tempList NewData tempName)
  (while (setq Ent (tblnext "block" (not Ent)))
    (if (= 4 (logand (cdr (assoc 70 ent)) 4))
      (progn
        (setq tempData
               (cons
                 (cdr
                   (assoc
                     330
                     (entget (setq tempEnt (tblobjname "block"
                                                       (setq tempName (cdr (assoc 2 Ent)))
                                           )
                             )
                     )
                   )
                 ) tempData
               )
        )
        (if (setq ss (ssget "X" (list (assoc 2 ent))))
          (progn ; delete al the xref Inserts
            (setq i -1)
            (while (setq ename (ssname ss (setq i (1+ i))))
              (entdel ename)
            )
          )
        )
      )
    )
  )
  (if tempData
    (foreach itm tempData
      (command "._xref" "D" (cdr (assoc 2 (entget itm))))
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #4 on: June 09, 2008, 03:58:27 PM »
Close, but I'm trying not to use command calls.  I know, I know, but still.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Using 'entdel' to delete a block definition
« Reply #5 on: June 09, 2008, 04:39:28 PM »
i've found this in the help
Quote
If all the instances of an xref are erased from the drawing, AutoCAD removes the xref definition the next time the drawing is opened.
i understand this will not help, but still...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #6 on: June 09, 2008, 04:46:22 PM »
i've found this in the help
Quote
If all the instances of an xref are erased from the drawing, AutoCAD removes the xref definition the next time the drawing is opened.
i understand this will not help, but still...
I remember that for another post now.  Thanks for the refresher.  I guess that could work then, even though if you look in the xref dialog it would show up after running the command.  I'll see if I can figure out anything else in the meantime.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: Using 'entdel' to delete a block definition
« Reply #7 on: June 10, 2008, 05:54:02 AM »
Hi Tim,

Have you tried using the Detach method? If so is there some reason I haven't thought of not to use it?

I know the docs say, "You cannot detach an xref that contains other xrefs", but it seems the docs are mistaken. I assume they are referring to nested xrefs. I just tried it in two different drawings using 2008 with an xref which has nested xrefs. The parent was detached in both cases.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #8 on: June 10, 2008, 11:18:13 AM »
Hi Tim,

Have you tried using the Detach method? If so is there some reason I haven't thought of not to use it?

I know the docs say, "You cannot detach an xref that contains other xrefs", but it seems the docs are mistaken. I assume they are referring to nested xrefs. I just tried it in two different drawings using 2008 with an xref which has nested xrefs. The parent was detached in both cases.
Only because I wanted a pure vanilla lisp code.  That would have been too easy Joe.  :wink:

I still haven't found a way with pure van. lisp.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Using 'entdel' to delete a block definition
« Reply #9 on: June 10, 2008, 01:36:23 PM »
i wonder...
insert an overlay xref
run this code
Code: [Select]
(progn
  (setq
    BlkName (cdr (assoc 2 (entget (car (entsel "\nSelect xref: ")))))
    EntName
    (tblobjname "BLOCK" BlkName)
  )
  (print (cdr
   (assoc 70
  (entget
    EntName
  )
   )
)
  )
  (command "_.-xref" "_D" BlkName)
  (terpri)
  (print (cdr
   (assoc 70
  (entget
    EntName
  )
   )
)
  )
)
why is code 70 increased by 128?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #10 on: June 10, 2008, 04:59:17 PM »
It looks like it can't be done like that.
Ref [ http://discussion.autodesk.com/thread.jspa?messageID=1119476 ]

Quote from: Uhden, John
Second, the entity returned via (tblobjname "block" ...) is not deletable
(sp?), but you may be able to (vla-delete) a block object that belongs to
the document's "Blocks" collection (presuming it's not being referenced).

And VovKa, I have no idea why it would do that.  The only guess I have is that it just added the next bit, so that if it is undid, then it knows the status it was.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: Using 'entdel' to delete a block definition
« Reply #11 on: June 11, 2008, 09:44:09 AM »
Tim,

Forgive me if I don't understand all the code posted.

It seems to me you started with an invalid assumption. That if an xref is not inserted, it's "unreferenced", you should be able to delete the block definition. Obviously xref blocks do not behave the same as regular blocks. Some form of detach is needed to do it while the file is open.

Also, the idea you want to use vanilla LISP without the command function just doesn't make sense.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Using 'entdel' to delete a block definition
« Reply #12 on: June 11, 2008, 10:17:48 AM »
Tim,

....

Also, the idea you want to use vanilla LISP without the command function just doesn't make sense.

He just wanted to see if it could be done... :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Using 'entdel' to delete a block definition
« Reply #13 on: June 11, 2008, 11:00:13 AM »
Tim,

Forgive me if I don't understand all the code posted.

It seems to me you started with an invalid assumption. That if an xref is not inserted, it's "unreferenced", you should be able to delete the block definition. Obviously xref blocks do not behave the same as regular blocks. Some form of detach is needed to do it while the file is open.

Also, the idea you want to use vanilla LISP without the command function just doesn't make sense.
The question on the Ad Ng was to detach ( delete ) xrefs that were overlay.  So I step through the block table and find which blocks are xref overlays.  I then delete all the inserted references to the definition, and then I try to delete the definition from the block table, which I thought would detach the xref.  I wasn't able to do it, and after a search here didn't see one thing about using entdel on block table records, so I thought I might be doing something wrong.  Then when no one knew for sure, I did a broader search, and found the link in my last post.  To me it was a challenge, not something I would use, but wanted to see if I could do it in plan Lisp, like Ron said here.
Tim,

....

Also, the idea you want to use vanilla LISP without the command function just doesn't make sense.

He just wanted to see if it could be done... :?

Hope that makes it a little clearer Joe.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: Using 'entdel' to delete a block definition
« Reply #14 on: June 13, 2008, 09:44:28 AM »
Hi Tim,

Am I right in thinking the conclusion is it can't be done without some form of detach, at least while the drawing is open?

Regards