Author Topic: Finding XRef paths  (Read 3702 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
Finding XRef paths
« on: November 10, 2004, 07:35:21 AM »
Walking through a drawings Blocks collection and grabbing xref's only (by checking the IsXRef prop), how would I get the path of each xref?

As I understand it, the Path is a property of the inserted, graphical xref .. of the AcadExternalReference object. Does this mean that I have to get hold of the block Name and then go iterate the entire drawing database for inserted instances of that xref? Of course, alternatively I can make a filtered selection set but it still requires looking at the graphical objects, does it not?

Through lisp, the path can be retrieved from the BLOCK entity, which is basically an AcDbBlockBegin object. Through VBA, it doesn't seem possible to access this object, or at least it doesn't seem to hold any path information.

hendie

  • Guest
Finding XRef paths
« Reply #1 on: November 10, 2004, 09:16:46 AM »
Stig, I found this by Chuck Hardin on a search ~ GetXrefPaths

SMadsen

  • Guest
Finding XRef paths
« Reply #2 on: November 10, 2004, 09:35:52 AM »
Excellent. Thanks Hendie.

Chuck's code uses selection sets so my hunch seems to be correct :)

I'm doing this with ObjectDBX thru lisp and found no problem in switching to entity names in the process .. thus avoiding to iterate through any graphical objects! Just thought that if it was just as easy with ActiveX I wouldn't have to switch to enames.

daron

  • Guest
Finding XRef paths
« Reply #3 on: November 10, 2004, 02:04:13 PM »
HOw are you using ODBX through lisp? Please, do tell.

SMadsen

  • Guest
Finding XRef paths
« Reply #4 on: November 10, 2004, 02:54:26 PM »
I have some 600 drawings I need to test for references - to see if some drawings aren't being used as xrefs. So I'm running through all drawings and grabbing xrefs so that I have a searchable list. Searching through the list I can count how many times each drawing is referenced.

Below is what I have so far (well, not really but I'll just post the DBX stuff). It simply makes a list of all dwgs and their xrefs/paths:

(setq files (getFiles) folder (car files) files  (cadr files))
(setq xreflst (XRefDbx files folder))
->
((drawing1.dwg ((xref1 . path1)(xref2 . path2)(xref3 . path3)))
(drawing2.dwg ((xref1 . path1)) ...)
)

Code: [Select]
(defun getFiles (/ path folder)
  (cond ((setq path (getfiled "Select a File" "" "dwg" (+ 4 128)))
         (list (setq folder (vl-filename-directory path))
               (vl-directory-files folder "*.dwg" 1)
         )
        )
  )
)

(defun XRefDbx (files folder / dbxDoc of filelst filesublst blklst)
  (cond
    ((and files
          (not (vl-catch-all-error-p
                 (setq dbxDoc (vl-catch-all-apply
                                'vla-getInterfaceObject
                                (list (vlax-get-acad-object)
                                      "ObjectDBX.AxDbDocument.16")))
               )
          )
     )
     (foreach file files
       (setq of (vl-catch-all-apply
                  'vlax-invoke-method
                  (list dbxDoc 'Open (strcat folder "\\" file))
                )
       )
       (cond ((vl-catch-all-error-p of)
              (princ (strcat file "Error: "
                        (vl-catch-all-error-message of)))
             )
             ((setq dbxBlks (vlax-get-property dbxdoc "Blocks"))
              (vlax-for blk dbxBlks
                (cond ((= (vlax-get-property blk 'IsXRef) ':vlax-true)
                       (setq bname (vlax-get-property blk 'Name))
                       (setq en360
                              (cdr
                                (assoc 360 (entget (vlax-vla-object->ename blk)))
                              )
                       )
                       (setq path (cdr (assoc 1 (entget en360))))
                       (setq blklst (cons (cons bname path) blklst))
                      )
                )
              ) ;_ vlax-for
              (setq filesublst
                     (list file blklst)
                    blklst nil
              )
              (vlax-release-object dbxBlks)
             )
       )
       (and filesublst (setq filelst (cons filesublst filelst)))
       (setq filesublst nil)
     ) ;_ foreach
     (vlax-release-object dbxdoc)
     (gc)
    )
    ((vl-catch-all-error-p dbxDoc)
     (princ (vl-string-subst
              "DBX interface"
              "application"
              (vl-catch-all-error-message dbxdoc)
            )
     )
    )
    ((not files) (princ "\nNo files found"))
  )
  filelst
)

daron

  • Guest
Finding XRef paths
« Reply #5 on: November 11, 2004, 08:17:29 AM »
Now that looks sweet. I've been pondering ODBX in lisp for some time, but couldn't figure out where to start. I think this ought to give me a good starting point. Thanks, Stig.

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Finding XRef paths
« Reply #6 on: November 11, 2004, 03:17:04 PM »
Stig, that's a nice little workaround for the Path. I was under the impression, based on the minimal amount of information I've found on ObjectDBX, that ONLY VLA- methods and properties could be used on a DBX file so I never even thought to try (entget).....

SMadsen

  • Guest
Finding XRef paths
« Reply #7 on: November 11, 2004, 03:42:39 PM »
Jeff, I was under that impression, too. Having run into all sorts of problems in the past with A2K by mixing ActiveX and native lisp in peculiar ways, I had doubts if it would work. But it runs pretty smoothly (in A2K4 and -5 at least).

I expanded it today to go back and forth between blockdefs, blockrecords and referenced inserts - all based on enames. No problems it seems (key word here is seems!)

Of course, doing anything with unreferenced enames after DBX is done will deliver an access violation on the spot.

Daron, I look forward to see some ObjectDBX from your hands :)

MP

  • Seagull
  • Posts: 17498
Finding XRef paths
« Reply #8 on: November 11, 2004, 03:43:11 PM »
I've been using entget on ObjectDBX models for awhile, my attempt was so I could pull out the overlay /attach status for xrefs (part of my 'Carnivore' app that scans dwgs in the tens of thousands if you recall from previous discussions).

Anyway, what I want to add to this thread is that entget seems to work fine, but do not attempt to entmod the data back, as this tends to corrupt the drawing (it gets confused it seems about colors and linetypes), and, here's the important bit "without warning". The next time you attempt to open the drawing? Kaboom! AutoCAD dies and doesn't know why. It's a shame, because I thought I'd use it to remedy the justification woes incurred when you modify text / attribute values. Drat, foiled again.

Carry on ... :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

SMadsen

  • Guest
Finding XRef paths
« Reply #9 on: November 11, 2004, 03:45:26 PM »
That's valuable information, MP. Thanks.

If I read you correctly, you are saying that doing queries by using enames is ok but doing modifications is a no-no?

MP

  • Seagull
  • Posts: 17498
Finding XRef paths
« Reply #10 on: November 11, 2004, 03:54:34 PM »
As was your intitial post on the entget topic.

When I first discovered that entget worked I was bouncing off the walls because I had tried it on a lark and holy **** it worked! Then the implications of what I could do struck me, yep, more babbling fool. The guys at work here thought I was completely daffy (yes, more than they normally do).

Anyway, as cool as I thought it was I really didn't think I should publicize it, it is certainly undocumented and uncharted territory and the last thing I wanted was people blithly using it without testing it, potentially causing corruption the likes we've never seen. I've seen more than my share of corrupt drawings, through work as well as my activities with Alex (RIP).

So I'm really pleased to hear a scientist like yourself is using it successfully and that you're finding it stable. Yee haa!

Well, as stable as anything else. :twisted:
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17498
Finding XRef paths
« Reply #11 on: November 11, 2004, 03:58:30 PM »
Quote from: SMadsen
That's valuable information, MP. Thanks.

If I read you correctly, you are saying that doing queries by using enames is ok but doing modifications is a no-no?

Based on limited testing yes. I have not done testing across the board, only text and attributes, and found that I could recover the corrupted drawings, and entity for entity (I recorded the handles of entities I modified) they were all corrupt: invalid colors and linetypes. Now it's a leap of logic, but I assumed this would probably apply across the board. The only mods I was making to the entities was the justification flags and insertion / alignment points.

Dang, I've go a meeting to go to in 4 minutes. More on this later friends.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

daron

  • Guest
Finding XRef paths
« Reply #12 on: November 12, 2004, 08:14:57 AM »
Quote from: SMadsen
Daron, I look forward to see some ObjectDBX from your hands :)


I'm certainly honored to hear that. Thank you. New world of lisp, here I come.