Get List of Xrefs using AcadDocument_EndCommand

Discussion in 'AutoCAD' started by Matt W, May 26, 2004.

  1. Matt W

    Matt W Guest

    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.
     
    Matt W, May 26, 2004
    #1
  2. Matt W

    Joe Sutphin Guest

    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Joe Sutphin, May 26, 2004
    #2
  3. You need to store a count of the existing entities at the beginCommand event
    of XATTACH or XREF commands, using something like:

    dim Tpent as long <-- declared at module level
    Tpent= ThisDrawing.ActiveLayout.Block.Count

    Then, in the EndCommand event, check the total entities and compare that
    to the previous total.

    Dim Taent as long
    Taent= ThisDrawing.ActiveLayout.Block.Count

    if Taent > Tpent then
    for i = Tpent to Taent-1
    set myEnt = ThisDrawing.ActiveLayout.Block(i)
    debug.print MyEnt.ObjectName
    next i
    end if

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Jorge Jimenez, May 26, 2004
    #3
  4. Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Jorge Jimenez, May 26, 2004
    #4
  5. Jorge,
    I'll have to disagree with nixing the ObjectAdded event across the board. I use it almost exactly as Joe has shown in my own auto-layering code with no performance degradation. I do agree that you want to be careful of the code that you put in it, but simply storing object references to count is a perfectly valid use.

    that's my 0.02

    p.s. - Notice that I only used one oxymoron. I think the fit is passing. It was a pretty awful one.
    --
    Bobby C. Jones
    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Bobby C. Jones, May 26, 2004
    #5
  6. Yes Bobby, it will also depend on the code you put in your ObjectAdded event, and what type of work you do with your cad.

    But take for example any dim command, it fires up the BeginCommand and EndCommand just once, while it fires up the objectadded event many times.
    And think about the dimcontinue command !! you can go ahead and dimcontinue as many features as you want firing up the objectadded event like crazy, while the begin and end command will fire up only once.

    The same thing happens with the copy command and some others.

    So why put code in an event that will fire up many times, when you can do it in an event that will fire only once for a command ??


    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    "Bobby C. Jones" <bjones (at) beazer (dot) com> wrote in message Jorge,
    I'll have to disagree with nixing the ObjectAdded event across the board. I use it almost exactly as Joe has shown in my own auto-layering code with no performance degradation. I do agree that you want to be careful of the code that you put in it, but simply storing object references to count is a perfectly valid use.

    that's my 0.02

    p.s. - Notice that I only used one oxymoron. I think the fit is passing. It was a pretty awful one.
    --
    Bobby C. Jones
    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Jorge Jimenez, May 26, 2004
    #6
  7. Matt, I can't tell how much impact your code would have on AutoCADs performance, 'cause that depends on many factors, including your computing power.

    But what I can tell you is, if you can do it using an event that will fire only once for the command, why put code in an event that may fire many times for the same command ??

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Jorge:
    The only thing I would put in there is a small amount of code to 1) check if the object added is an xref and if it is 2) put it on our company's xref layer (which is locked to prevent people from "accidentally" moving, rotating, deleting xrefs.

    Do you really think that would decrease ACAD's performance??

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.

    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Jorge Jimenez, May 26, 2004
    #7
  8. Matt W

    Matt W Guest

    Good point, Jorge.
    Looks like it's back to the drawing board once again!

    Thanks for all your input guys!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't
     
    Matt W, May 26, 2004
    #8
  9. If you think it fires the ObjectAdded event a lot, you should monitor how many times it fires the ObjectModified event. I just added a single linear dimension to a drawing and it fired the documents OjbectModified event 34 times and the ObjectAdded event 22 times. I monitor *both* of these events in my code and adding a dimension doesn't even come close to firing them as often as other commands. The amount of code in these events is minimal, but I am doing such evil slow things as wild card string comparisons with the Like operator. We've been doing this for a long time. The oldest hardware that this system ran on was a PIII 600Mhz with 128M of ram. That "old" hardware ran the system without a problem.

    Certainly, if you don't need these events then stay away from them. But don't make a blanket statement that they should never be used.
    --
    Bobby C. Jones
    Yes Bobby, it will also depend on the code you put in your ObjectAdded event, and what type of work you do with your cad.

    But take for example any dim command, it fires up the BeginCommand and EndCommand just once, while it fires up the objectadded event many times.
    And think about the dimcontinue command !! you can go ahead and dimcontinue as many features as you want firing up the objectadded event like crazy, while the begin and end command will fire up only once.

    The same thing happens with the copy command and some others.

    So why put code in an event that will fire up many times, when you can do it in an event that will fire only once for a command ??


    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    "Bobby C. Jones" <bjones (at) beazer (dot) com> wrote in message Jorge,
    I'll have to disagree with nixing the ObjectAdded event across the board. I use it almost exactly as Joe has shown in my own auto-layering code with no performance degradation. I do agree that you want to be careful of the code that you put in it, but simply storing object references to count is a perfectly valid use.

    that's my 0.02

    p.s. - Notice that I only used one oxymoron. I think the fit is passing. It was a pretty awful one.
    --
    Bobby C. Jones
    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Bobby C. Jones, May 26, 2004
    #9
  10. When did I say never ?

    My recommendation to Matt was, if it's possible to do what he wants inside an event that fires a few times, and handle his actions in a batch mode, why use an event that fires many times as much.
    Logic (and personal experience) tells me that this is a more efficient use of resources.

    You may code as you wish, and if you haven't experienced any performance hit in your apps, well, I'm happy for you.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    "Bobby C. Jones" <bjones (at) beazer (dot) com> wrote in message If you think it fires the ObjectAdded event a lot, you should monitor how many times it fires the ObjectModified event. I just added a single linear dimension to a drawing and it fired the documents OjbectModified event 34 times and the ObjectAdded event 22 times. I monitor *both* of these events in my code and adding a dimension doesn't even come close to firing them as often as other commands. The amount of code in these events is minimal, but I am doing such evil slow things as wild card string comparisons with the Like operator. We've been doing this for a long time. The oldest hardware that this system ran on was a PIII 600Mhz with 128M of ram. That "old" hardware ran the system without a problem.

    Certainly, if you don't need these events then stay away from them. But don't make a blanket statement that they should never be used.
    --
    Bobby C. Jones
    Yes Bobby, it will also depend on the code you put in your ObjectAdded event, and what type of work you do with your cad.

    But take for example any dim command, it fires up the BeginCommand and EndCommand just once, while it fires up the objectadded event many times.
    And think about the dimcontinue command !! you can go ahead and dimcontinue as many features as you want firing up the objectadded event like crazy, while the begin and end command will fire up only once.

    The same thing happens with the copy command and some others.

    So why put code in an event that will fire up many times, when you can do it in an event that will fire only once for a command ??


    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    "Bobby C. Jones" <bjones (at) beazer (dot) com> wrote in message Jorge,
    I'll have to disagree with nixing the ObjectAdded event across the board. I use it almost exactly as Joe has shown in my own auto-layering code with no performance degradation. I do agree that you want to be careful of the code that you put in it, but simply storing object references to count is a perfectly valid use.

    that's my 0.02

    p.s. - Notice that I only used one oxymoron. I think the fit is passing. It was a pretty awful one.
    --
    Bobby C. Jones
    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Jorge Jimenez, May 26, 2004
    #10
  11. Jorge - For the record, I completely agree with your
    comments.

    Bobby is misinformed about the facts surround this, and his
    opinion seems to be rooted in a misunderstanding of how
    ActiveX events work.

    Any time you use the AcadDocument object, that is declared
    using 'WithEvents', your code is sinking *all* of its events,
    regardless of whether you write an explicit handler for them,
    or not.

    Hence, handling any AcadDocument event will impose the basic
    overhead of the three ObjectXxxxx() events, even if you do not
    handle any of them. If you do handle them, then there is the
    additional overhead of what you do in the event handlers, but
    the basic overhead of the events themselves cannot be avoided
    without avoiding the use of any event of AcadDocument.

    Therefore, you wants to realize the true impact of the three
    high frequency AcadDocument.ObjectXxxxx() events, you can't do
    that by simply eliminating the explicit handlers for them.
    Rather, you must completely eliminate the handling of all
    AcadDocument events, by eliminating the 'WithEvents' from
    its declaration.

    That's why I went to the trouble of writing alternatives for
    some AcadDocument events in AcadX. I can use them without
    having to endure the collateral overhead of the ObjectXxxx()
    AcadDocument events, even when I'm not interested in them.

    Also, regarding 'blanket statements', here's one:

    Do not use AcadDocument events at all, from an out-of-process
    client, under any circumstances.




    When did I say never ?

    My recommendation to Matt was, if it's possible to do what he wants inside an event that fires a few times, and handle
    his actions in a batch mode, why use an event that fires many times as much.
    Logic (and personal experience) tells me that this is a more efficient use of resources.

    You may code as you wish, and if you haven't experienced any performance hit in your apps, well, I'm happy for you.
     
    Tony Tanzillo, May 26, 2004
    #11
  12. Any time you use the AcadDocument object, that is declared
    One effect of this fact, on a VB DLL running in process
    shows up as the wacky behavior of the dimcontinue
    command, as I pointed out a couple of weeks ago.
     
    Jorge Jimenez, May 26, 2004
    #12
  13. This should work and is simpler.
     
    Nathan Taylor, May 27, 2004
    #13
  14. Matt W

    Joe Sutphin Guest

    Who said we were talking about out of process. The example I gave is in
    process. The events in the AcadDocument object within VBA will fire
    regardless of whether there is code there to handle the event.

    Joe
    --

    an event that fires a few times, and handle
    hit in your apps, well, I'm happy for you.
     
    Joe Sutphin, May 27, 2004
    #14
  15. Matt W

    Joe Sutphin Guest

    You would have to have a HUGE amount of code going on and be running on a 386SX for this to make any significant difference.

    Joe
    --
    Jorge:
    The only thing I would put in there is a small amount of code to 1) check if the object added is an xref and if it is 2) put it on our company's xref layer (which is locked to prevent people from "accidentally" moving, rotating, deleting xrefs.

    Do you really think that would decrease ACAD's performance??

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.

    Matt, I wouldn't recommend the use of the ObjectAdded event.

    Depending on how you work and the amount of entities you add
    to a drawing, code in the objectadded event can really deteriorate
    AutoCAD's performance.

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    Duh... That would make more sense, wouldn't it??
    I was so hung up on the fact that it was a command that I was executing and forgot about that.

    Sometimes it just takes a fresh set of eyes to find something that has been staring you right in the face!

    Thanks, Joe!

    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.


    Matt,

    I would use the ObjectAdded event instead.

    Joe
    --

    Private Sub AcadDocument_ObjectAdded(ByVal Object As Object)
    Dim oBlock As AcadBlock

    If TypeOf Object Is AcadBlock Then
    Set oBlock = Object

    If oBlock.IsXRef Then MsgBox "XRef was just added!"
    End If
    End Sub


    Is there a way, using the AcadDocument_EndCommand sub, to get a list of the xrefs that were just added to the drawing??

    Thanks in advance!
     
    Joe Sutphin, May 27, 2004
    #15
  16. My apologies Jorge. Your original post read like a "never" to me. If that's not the case, then we are in agreement and can stop dancing in circles around each other <g>
    --
    Bobby C. Jones
    When did I say never ?

    My recommendation to Matt was, if it's possible to do what he wants inside an event that fires a few times, and handle his actions in a batch mode, why use an event that fires many times as much.
    Logic (and personal experience) tells me that this is a more efficient use of resources.

    You may code as you wish, and if you haven't experienced any performance hit in your apps, well, I'm happy for you.
     
    Bobby C. Jones, May 27, 2004
    #16
  17. Bobby is misinformed about the facts surround this, and his
    [BCJ] I completely understand how ActiveX events work. If you want to pat
    yourself on the back you can as it was some of your comments in my early
    adventures that prompted me to look inside the details.
    [BCJ] So what you're saying is that utilizing them with small amounts of
    code won't make any difference over not using them at all. Now where have I
    heard that before?
    [BCJ] It almost sounds like you are suggesting that the OP should either
    take the time and effort to learn C++ & ARX or download and use a third
    party application for the simple task of counting xrefs...And I thought that
    my oxymoron tirade was out there!
    [BCJ] Blanket statements...I just find them so mind numbingly droll.
     
    Bobby C. Jones, May 27, 2004
    #17
  18. Matt W

    Matt W Guest

    Man!! Who would've thought such a simple request (or so it seemed) would spark this much discussion!

    Thanks for the information (and entertainment). I've actually learned quite a bit from all the back-and-forth that went on!


    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.
     
    Matt W, May 27, 2004
    #18
  19. Apology accepted.
    Thank you very much !

    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)
    "Bobby C. Jones" <bjones (at) beazer (dot) com> wrote in message My apologies Jorge. Your original post read like a "never" to me. If that's not the case, then we are in agreement and can stop dancing in circles around each other <g>
    --
    Bobby C. Jones
    When did I say never ?

    My recommendation to Matt was, if it's possible to do what he wants inside an event that fires a few times, and handle his actions in a batch mode, why use an event that fires many times as much.
    Logic (and personal experience) tells me that this is a more efficient use of resources.

    You may code as you wish, and if you haven't experienced any performance hit in your apps, well, I'm happy for you.
     
    Jorge Jimenez, May 27, 2004
    #19
  20. Excuse me Mr. "Yea, but I already know that", but I don't
    think so. The forgone conclusions in your previous comments
    make that perfectly clear.
    No, what I'm saying is that if you're using any AcadDocument
    events, then you're suffering the overhead of these events,
    regardless of whether you use them, or not. Small amounts of
    code are no longer a trivial matter when they're executed with
    the frequency at which these events can fire.
    Naaa... That's just your typical, envy-driven spin job that is
    designed to trivialize or marginalize anything that is beyond
    your own capabilitiy.

    In fact, he would find many other uses for either his C++
    skills or the third party application you're referring to,
    but of course that wouldn't play well any vanity striken,
    guru wannabe.
     
    Tony Tanzillo, May 27, 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.