nested XREF Layer

Discussion in 'AutoCAD' started by Jorge Jimenez, Aug 4, 2004.

  1. Hi all.

    How do I get the layer where a "nested" XREF is inserted ??
    Is there a quick way to do this ???
     
    Jorge Jimenez, Aug 4, 2004
    #1
  2. Jorge Jimenez

    TomD Guest

    No quick way, without lisp.

    I don't have anything written (on my
    things-to-do-when-i've-done-all-the-important-stuff list), but looking into
    the ENTGET function would get you the info you're looking for. There would
    be a few checks required, etc., that off hand, I couldn't explain.

    You need to use NENTSEL to select a nested object, then use ENTGET and work
    through the list of parent objects............or something like that. It's
    been a while since I've looked into that, so I apologize for the lack of
    specifics.

    I don't know the VBA method of selecting a nested object, BTW.

    I hope my rambling is of some use to you.
     
    TomD, Aug 4, 2004
    #2
  3. Thanks Tom.
    I need to make a list of all XREFs in a dwg and their insertion layer.
    No selection by the user should be necessary.
    I'm using VB, so LISP may not be a good idea, but if it's the only way...

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


     
    Jorge Jimenez, Aug 4, 2004
    #3
  4. It is not the only way.

    Sub Test()
    Dim aEntity As AcadEntity
    Dim aBlock As AcadBlock
    For Each aBlock In ThisDrawing.Blocks
    For Each aEntity In aBlock
    If TypeOf aEntity Is AcadExternalReference Then
    Debug.Print aEntity.Name & "->" & aEntity.Layer
    End If
    Next aEntity
    Next aBlock
    End Sub


    --
    R. Robert Bell


    Thanks Tom.
    I need to make a list of all XREFs in a dwg and their insertion layer.
    No selection by the user should be necessary.
    I'm using VB, so LISP may not be a good idea, but if it's the only way...
     
    R. Robert Bell, Aug 4, 2004
    #4
  5. Jorge Jimenez

    aks01 Guest

    I think you can do this in VBA. I have a homebrew that reports the resolved xref attachments and the nested attachments. It writes out to a comma delinated text file but it goes only one nesting deep. Perhaps you would have to use recursion to discover the nesting at any depth. It uses a selection set filter for blocks and then checks .isXref to find the first level xrefs. It then uses TypeOf AcadExternalReference to find the first level of nesting. Apparently the .Layer of the object meeting the first level of nesting seems to return the "full" layername (<nested>|<layername>) of the layer the nexted xref is inserted into the first level xref. I just made a quick and dirty check. So I think there is way to acheive what you want at least down to the first nested xref.
     
    aks01, Aug 4, 2004
    #5
  6. Jorge Jimenez

    TomD Guest

    I made an erroneous assumption about your original post, thinking you needed
    to find it by selection.

    Never accept anything as the only way. ;)
     
    TomD, Aug 4, 2004
    #6
  7. Jorge Jimenez

    manoj_vest Guest

    Hi Jorge,

    You can do as follows. In the current drawing search for the external references and you can find the layer name directly. For nested external references you need to iterate the Blocks cloolection. If the block's IsXRef property is true then use XRefDatabase property of the block to get the database of the inserted external reference. The XRefDatabase is intern is AcadDatabase which has a property Modelspace, you can iterate the modelspace of that object to find the external-references and there layer property. Also the database also has block collection which you need the iterate for further deep lave external references. You can use the recuision for the same.

    I hope this help

    Manoj
     
    manoj_vest, Aug 5, 2004
    #7
  8. Seems like too much work. See my sample code posted yesterday.

    --
    R. Robert Bell


    Hi Jorge,

    You can do as follows. In the current drawing search for the external
    references and you can find the layer name directly. For nested external
    references you need to iterate the Blocks cloolection. If the block's IsXRef
    property is true then use XRefDatabase property of the block to get the
    database of the inserted external reference. The XRefDatabase is intern is
    AcadDatabase which has a property Modelspace, you can iterate the modelspace
    of that object to find the external-references and there layer property.
    Also the database also has block collection which you need the iterate for
    further deep lave external references. You can use the recuision for the
    same.

    I hope this help

    Manoj
     
    R. Robert Bell, Aug 5, 2004
    #8
  9. Thanks Robert.
    I actually thought iterating for each entity in each block would take a very
    long time in a big drawing, so I didn't even try it.
    I was looking for another way to do it.
    I was getting all the xrefs names from the layer collection. That worked
    fast
    And then I got the block entities from the block collection using their
    block name. That also was fast.
    But after that, I was looking for more direct way to get to the insertion
    layer, like using the owner objectid or something like that, but it got
    complicated and time consuming.

    Anyway, after giving your sub a try, in a drawing with some 3,000 blocks and
    18 xrefs heavily nested (some five level deep and circular references), I
    was amazed as to how fast it got thru all the entities.
    I underestimated the for each loop
     
    Jorge Jimenez, Aug 6, 2004
    #9
  10. Thanks.
    I had gotten that far already, but as the nested the levels got deeper the
    more time it took for the program to get the info. It got to a crawling
    state in a dwg with some 18 xref some five level deep .
    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


    resolved xref attachments and the nested attachments. It writes out to a
    comma delinated text file but it goes only one nesting deep. Perhaps you
    would have to use recursion to discover the nesting at any depth. It uses
    a selection set filter for blocks and then checks .isXref to find the first
    level xrefs. It then uses TypeOf AcadExternalReference to find the first
    level of nesting. Apparently the .Layer of the object meeting the first
    level of nesting seems to return the "full" layername (<nested>|<layername>)
    of the layer the nexted xref is inserted into the first level xref. I just
    made a quick and dirty check. So I think there is way to acheive what you
    want at least down to the first nested xref.
     
    Jorge Jimenez, Aug 6, 2004
    #10
  11. Thanks againg
    I usually don't.
     
    Jorge Jimenez, Aug 6, 2004
    #11
  12. Thank Manoj.
    I already was doing it that way, but it took way to much time when the
    nested levels were more than 3 or 4

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


    references and you can find the layer name directly. For nested external
    references you need to iterate the Blocks cloolection. If the block's IsXRef
    property is true then use XRefDatabase property of the block to get the
    database of the inserted external reference. The XRefDatabase is intern is
    AcadDatabase which has a property Modelspace, you can iterate the modelspace
    of that object to find the external-references and there layer property.
    Also the database also has block collection which you need the iterate for
    further deep lave external references. You can use the recuision for the
    same.
     
    Jorge Jimenez, Aug 6, 2004
    #12
  13. The ActiveX interface can be amazingly fast, huh?!

    Glad I could help.

    --
    R. Robert Bell


    Thanks Robert.
    I actually thought iterating for each entity in each block would take a very
    long time in a big drawing, so I didn't even try it.
    I was looking for another way to do it.
    I was getting all the xrefs names from the layer collection. That worked
    fast
    And then I got the block entities from the block collection using their
    block name. That also was fast.
    But after that, I was looking for more direct way to get to the insertion
    layer, like using the owner objectid or something like that, but it got
    complicated and time consuming.

    Anyway, after giving your sub a try, in a drawing with some 3,000 blocks and
    18 xrefs heavily nested (some five level deep and circular references), I
    was amazed as to how fast it got thru all the entities.
    I underestimated the for each loop
     
    R. Robert Bell, Aug 6, 2004
    #13
  14. Robert, why would this exact same routine run in 3 seconds in VBA but take
    for ever in a VB DLL ??
    I thought that a VB dll, loaded in the same application space as acad, would
    run just as fast as any VBA macro.
    I'm I wrong ??
     
    Jorge Jimenez, Aug 6, 2004
    #14
  15. <hmm> Me too (or nearly as fast). Can you email me a sample drawing
    etransmitted/zipped up for some testing? (Remove the obvious from my
    address.)

    --
    R. Robert Bell


    Robert, why would this exact same routine run in 3 seconds in VBA but take
    for ever in a VB DLL ??
    I thought that a VB dll, loaded in the same application space as acad, would
    run just as fast as any VBA macro.
    I'm I wrong ??
     
    R. Robert Bell, Aug 7, 2004
    #15
  16. Robert, why would this exact same routine run in 3 seconds in VBA but take
    IME it depends heavily upon how you acquire your reference, or pointer, to
    AutoCAD. If you've sent it to Robert, I'm sure he'll get you fixed up!

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 7, 2004
    #16
  17. Robert, the dwg and xrefs are quite big, and IMHO they donĀ“t seem to be the
    problem here
    Why would the VBA macro run so fast and the VB dll crawl, on the same dwg,
    using the same code (just replacing thisdrawing with acaddoc) . ??
    The VB dll is loaded using lisp, which passes the acadapp to the function.

    (setq acd (vlax-get-acad-object))
    (setq dibserv (vlax-invoke acd "getinterfaceobject" "SCAD.dwgs"))
    (vlax-invoke dibserv "Fstart" acd)

    I've done some testing with several dwgs and got the same result: the VBA
    macro blazes and the VB dll crawls.
     
    Jorge Jimenez, Aug 7, 2004
    #17
  18. Hi Mike
    The VB dll is loaded using lisp:

    (setq acd (vlax-get-acad-object))
    (setq dibserv (vlax-invoke acd "getinterfaceobject" "SCAD.Dwgs"))

    then a Sub is called the same way:

    (vlax-invoke dibserv "Fstart" acd)
    -----------------------------------------
    Inside the VB dll class

    Public withevents AcadApp as AutoCAD.AcadApplication

    Public Sub Fstart (Mapp as AutoCAD.AcadApplication)
    set AcadApp = Mapp
    ..
    ..
    ..
    End Sub
     
    Jorge Jimenez, Aug 7, 2004
    #18
  19. Never mind me !!! My brain was fried !!
    I was running the dll in debug mode.

    Thanks for the help !!
     
    Jorge Jimenez, Aug 8, 2004
    #19
  20. Ahh. Glad you figured it out.

    --
    R. Robert Bell


    Never mind me !!! My brain was fried !!
    I was running the dll in debug mode.
     
    R. Robert Bell, Aug 8, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.