Author Topic: Erase Reactor for XREF  (Read 2677 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Erase Reactor for XREF
« on: April 11, 2008, 01:51:32 PM »
Hi all,..

I'm trying to make a simple routine to detach XREF when user delete it.
But i can't find how to make my code working.

any help will be appreciated.  thanks.

Code: [Select]
;;(vlr-remove-all)
(if EraseEnded (vlr-remove EraseEnded))
(if EraseStarted (vlr-remove EraseStarted))

;;Start Reactor
(setq EraseEnded
(vlr-command-reactor nil '((:vlr-commandEnded . *EraseEnded*)))
)

(setq EraseStarted
(vlr-command-reactor nil '((:vlr-commandWillStart . *EraseStarted*)))
)

;;Check If Deleted and Detach if was Xref
(defun checkIFdeleted (XRefList)
  (foreach xr XRefList
     (if (vlax-erased-p xr)
         (vla-Detach xr)
    )
   )
 (setq XRLi nil)
)


;;Create Xref List
(defun XRerList (/ blocks actdoc)
(setq XRLi ())
(setq actdoc (vla-get-activeDocument (vlax-get-acad-object)))
(setq blocks (vla-get-blocks actdoc))
  (vlax-for xref blocks
    (if (eq :vlax-true (vla-get-IsXRef xref))
          (setq XRLi (append XRLi (list xref)))
    )
  )
)



 

;;Reactor on Start ERASE
(defun *EraseStarted* (call-reactor scI )
  (if (= (nth 0 scI ) "ERASE") (XRerList))
)


;;Reactor on ended ERASE
(defun *EraseEnded* (call-reactor scI)
   (if (= (nth 0 scI ) "ERASE") (if XRLi (checkIFdeleted XRLi)))
)

« Last Edit: April 11, 2008, 02:06:15 PM by Andrea »
Keep smile...

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Erase Reactor for XREF
« Reply #1 on: April 11, 2008, 02:13:27 PM »
Won't the xref detach itself when the drawing is reopened if it is unreferenced?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Erase Reactor for XREF
« Reply #2 on: April 11, 2008, 02:18:36 PM »
Won't the xref detach itself when the drawing is reopened if it is unreferenced?
Not on mine system it doesn't.  It just says it's unreferenced.
Tim

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

Please think about donating if this post helped you.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Erase Reactor for XREF
« Reply #3 on: April 11, 2008, 02:22:44 PM »
Won't the xref detach itself when the drawing is reopened if it is unreferenced?

Yes, but for some reason, user here dont want to close the drawing and reopen-it.
they load over than 30 xref per drawings... :ugly:
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Erase Reactor for XREF
« Reply #4 on: April 11, 2008, 02:23:51 PM »
Won't the xref detach itself when the drawing is reopened if it is unreferenced?
Not on mine system it doesn't.  It just says it's unreferenced.

your right, same on my PC..
maybe is a variable !?
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Erase Reactor for XREF
« Reply #5 on: April 11, 2008, 02:32:57 PM »
The problem is in this function
Code: [Select]
;;Check If Deleted and Detach if was Xref
(defun checkIFdeleted (XRefList)
  (foreach xr XRefList
     (if (vlax-erased-p xr)
         (vla-Detach xr)
    )
   )
 (setq XRLi nil)
)

You are testing to see if the block record is erased, not if the inserts are all erased.  You will have to make sure that no more inserts reference the block record, then you can detach it.  One way is with an ssget call with the name, an other way is to step through all the layouts and see if it exists, or you can get the information from the dxf code of the block record.
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Erase Reactor for XREF
« Reply #6 on: April 11, 2008, 02:43:44 PM »
It's probably because I automatically purge every drawing when opened.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Erase Reactor for XREF
« Reply #7 on: April 11, 2008, 02:54:37 PM »
It's probably because I automatically purge every drawing when opened.
I see a message on my screen after opening a drawing that has an unreferenced xref that said it was purged.  Not sure if that is some custom routine my company wrote, or if it is default in Acad.  Never noticed it before Ron.  Nice of you to point it out.
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Erase Reactor for XREF
« Reply #8 on: April 11, 2008, 03:07:20 PM »
  :-) I think it is an AutoCAD thing.....I see the same message and the prompt is before my purge

"xrefname" is unreferenced and has been purged.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Erase Reactor for XREF
« Reply #9 on: April 11, 2008, 03:23:14 PM »
hhmm...
I don't know why....
in some station here...all the deleted Xref is detached when the drawing was reopened.
all without loading any application.  :|
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Erase Reactor for XREF
« Reply #10 on: April 21, 2008, 11:39:19 AM »
there we go..

Code: [Select]
;| XREF DETACH ON DELETE COMMAND ;;
By: Andrea Andreetti |;

(if EraseEnded
  (vlr-remove EraseEnded)
)


;;Start Reactor
(setq EraseEnded
       (vlr-command-reactor
nil
'((:vlr-commandEnded . *EraseEnded*))
       )
)


(defun release-vla-object ()
  (if (not (vlax-object-released-p actdoc))
    (vlax-release-object actdoc)
  )
  (if (not (vlax-object-released-p blocks))
    (vlax-release-object blocks)
  )
)




;;Create Xref List
(defun checkIFdeleted (/ blocks XRNL ss2)
  (setq blocks (vla-get-blocks
(vla-get-activeDocument (vlax-get-acad-object))
       )
  )
  (vlax-for xref blocks
    (if (eq :vlax-true (vla-get-IsXRef xref))
      (setq XRNL
     (append XRNL (list (cons xref (list (vla-get-name xref)))))
      )
    )
  )
  (release-vla-object)
  (foreach n XRNL
    (setq ss2 (ssget "X"
     (list
       '(0 . "INSERT")
       (cons 2 (nth 1 n))
     )
      )
    )
    (if (not ss2)
      (vla-Detach (nth 0 n))
    )
  )
)



;;Reactor on ended ERASE
(defun *EraseEnded* (call-reactor scI / ERE)
  (setq ERE (nth 0 scI))
  (if (= ERE "ERASE")
    (checkIFdeleted)
  )
)

Keep smile...