Author Topic: Detach unloaded xrefs  (Read 14358 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
Re: Detach unloaded xrefs
« Reply #15 on: December 15, 2005, 11:23:29 AM »
further info;

if an xref is unloaded but nested (attached) in an xref that is loaded (attached), i get the same error message.

is there a way to skip nested xrefs?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Detach unloaded xrefs
« Reply #16 on: December 15, 2005, 12:00:53 PM »
I can look into it when I have time.  I'm not sure how to check to see if something is nested, unless you search all the xref's defenitions for other xrefs.

Maybe if you seach each layout instead of the block collection.  I think you only get the top level xref's that way, and then you can detach unloaded one from there.
Untested code.
Code: [Select]
(defun XrefDetach ()
(vlax-for Layout (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-for i (vla-get-Block Layout)
  (if
   (and
    (= (vla-get-ObjectName i) "AcDbBlockReference")
    (vlax-property-available-p i 'Path)
    (vl-catch-all-error-p
     (vl-catch-all-apply 'vla-get-XrefDatabase (list i))
    )
   )
   (vla-Detach i)
  )
)
)
(princ)
)
Tim

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

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Detach unloaded xrefs
« Reply #17 on: December 15, 2005, 01:27:55 PM »
hmmm... that one didn't work at all

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Detach unloaded xrefs
« Reply #18 on: December 15, 2005, 02:27:51 PM »
Here you go.  I have had some time now.  The reason why the last one didn't work it because some of the tests that were run could only be run on objects for the block collection.  So we shall combind both.
Code: [Select]
(defun XrefDetach (/ tmpObj)
(vlax-for Layout (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for i (vla-get-Block Layout)
  (if
   (and
    (= (vla-get-ObjectName i) "AcDbBlockReference")
    (vlax-property-available-p i 'Path)
    (setq tmpObj (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vla-get-Name i)))
   (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-get-XrefDatabase (list tmpObj))
   )
   )
   (vla-Detach tmpObj)
  )
)
)
(princ)
)
This worked here, but you can't use it after a reload.  I think that once you reload it keeps the reference to the XrefDatabase property.  I don't see a way around it.
Looking back into this thread I saw this.
Michael, you can find unloaded xrefs only by looking for code 71. If present, the xref is unloaded. Otherwise it'll be missing no matter if it's unresolved or not.
But it isn't the case after you reload, at least is wasn't in my drawing.
Quote from: Autocad Command Line
Command: -xref

Enter an option [?/Bind/Detach/Path/Unload/Reload/Overlay/Attach] <Attach>: u

Enter xref name(s) to unload: NORT-003-E-RFPWR

Xref "NORT-003-E-RFPWR": NORT-003-E-RFPWR.DWG
"NORT-003-E-RFPWR" is unloaded.

Command: (TBLSEARCH "BLOCK" "NORT-003-E-RFPWR")
((0 . "BLOCK") (2 . "NORT-003-E-RFPWR") (70 . 12) (4 . "") (10 0.0 0.0 0.0) (1
. "NORT-003-E-RFPWR.DWG") (-2 . <Entity name: 7effc480>))
Tim

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

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Detach unloaded xrefs
« Reply #19 on: December 15, 2005, 04:13:44 PM »
Tim, did you know that (tblsearch) does NOT return a complete elist?
Quote from: CommandLine
Command: -xref

Enter an option [?/Bind/Detach/Path/Unload/Reload/Overlay/Attach] <Attach>: u

Enter xref name(s) to unload: test

Xref "test": C:\Base Maps\Jeffs Test Files\test.dwg
"test" is unloaded.

Xref "notch": C:\Base Maps\Jeffs Test Files\junk\notch.dwg
"notch" is orphaned.

Xref "sink": C:\Base Maps\Jeffs Test Files\junk\sink.dwg
"sink" is orphaned.

Command: (tblsearch "block" "test")
((0 . "BLOCK") (2 . "test") (70 . 4) (4 . "") (10 0.0 0.0 0.0) (1 . "C:\\Base
Maps\\Jeffs Test Files\\test.dwg") (-2 . <Entity name: 7e834258>))

Command: (entget (tblobjname "block" "test"))
((-1 . <Entity name: 7e834250>) (0 . "BLOCK") (330 . <Entity name: 7e834248>)
(5 . "10A") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockBegin")
(70 . 4) (71 . 1) (10 0.0 0.0 0.0) (-2 . <Entity name: 7e834258>) (2 . "test")
(1 . "C:\\Base Maps\\Jeffs Test Files\\test.dwg"))
Using MP's code as a base, this has worked in my test drawings:
Code: [Select]
(defun c:YouNameIt (/ name data modList method)
  (vlax-for block
  (setq blocks (vlax-get-property
(vlax-get-property
   (vlax-get-acad-object)
   'ActiveDocument
)
'Blocks
       )
  )
    (if
      (and
(eq :vlax-true
    (vlax-get-property
      block
      'IsXref
    )
)
(assoc 71
       (setq data
      (entget
(tblobjname
  "block"
  (setq name
(vlax-get-property
   block
   'Name
)
  )
)
      )
       )
)
      )
       (vla-detach block)
    )
  )
  (princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Detach unloaded xrefs
« Reply #20 on: December 15, 2005, 04:30:22 PM »
Tim, did you know that (tblsearch) does NOT return a complete elist?

Nope.  I didn't know that one Jeff.  Thanks.  I was thinking that I could us what Stig mentioned to see if it is unloaded, but didn't see it there.  I wondered why MP did (tblobjname... instead of tblsearch.

Code: [Select]
(defun XrefDetach (/ tmpObj)
(vlax-for Layout (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
 (vlax-for i (vla-get-Block Layout)
  (if
   (and
    (= (vla-get-ObjectName i) "AcDbBlockReference")
    (vlax-property-available-p i 'Path)
    (setq tmpObj (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) (vla-get-Name i)))
    (assoc 71 (entget (tblobjname "block" (vla-get-Name i))))
   )
   (vla-Detach tmpObj)
  )
 )
)
(princ)
)

This code works as it should now thanks to Stig's post, and Jeff telling me what I was doing wrong.
Tim

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

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Detach unloaded xrefs
« Reply #21 on: December 15, 2005, 04:56:19 PM »
thank you sir, that seems to work quite well.  i have it defined and run when a drawing is closed.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Detach unloaded xrefs
« Reply #22 on: December 15, 2005, 04:59:28 PM »
Took a while to get there, and learned somethings new.  Glad we got somthing that works the way you want it to.
Tim

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

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Detach unloaded xrefs
« Reply #23 on: December 15, 2005, 05:52:30 PM »
Took a while to get there, and learned somethings new.  Glad we got somthing that works the way you want it to.

again, thanks for your time.