Nested Highlighting (copy and highlight from xref)

Discussion in 'AutoCAD' started by James Allen, Jan 14, 2005.

  1. James Allen

    James Allen Guest

    Does anyone know how to make copyobjects work with nested leaders from an
    xref database? I get the same error with nested blocks as nested leaders
    (and I presume other dimensions). So I'm hoping the solution to the leader
    issue will also point me in the right direction with nested blocks. The
    nested blocks is really where I'm headed with it and already have the rest
    of the puzzle worked out (I think), but don't see what's wrong here.
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO

    Code:
    ;;; Leader in xref -> Error: AutoCAD.Application: Invalid owner object
    (defun c:NPTest (/ ActiveDocument blk doc enm lyt obj pck tmp)
    (setq ActiveDocument (vlax-get (vlax-get-acad-object) 'ActiveDocument))
    (setq pck (nentselp "Select nested object: ")
    obj (vlax-ename->vla-object (car pck))
    tmp (mapcar 'vlax-ename->vla-object (cadddr pck))
    )
    ;; Copy Nested first if necessary
    (if tmp
    (progn
    (setq blk (vla-get-Name (last tmp))
    blk (vla-Item (vla-get-Blocks ActiveDocument) blk)
    doc (if (eq (vla-get-IsXref blk) :vlax-True)
    (vla-get-XRefDatabase blk)
    ActiveDocument
    )
    lyt (vla-get-ModelSpace ActiveDocument)
    obj (car (vlax-invoke doc 'CopyObjects (list obj) lyt))
    )
    (vla-TransformBy obj (vlax-tmatrix (caddr pck)))
    )
    )
    (vla-Highlight obj :vlax-True)
    (setq enm (vlax-vla-object->ename obj))
    (sssetfirst (ssadd enm) (ssadd enm))
    (princ)
    )
    
     
    James Allen, Jan 14, 2005
    #1
  2. James Allen

    LUCAS Guest

    LUCAS, Jan 14, 2005
    #2
  3. James Allen

    Joe Burke Guest

    Hi James,

    I don't get the error when I select an object in a block within an xref. Also no
    error with any part of a dimension, except for the dimension mtext. I get the error
    with any text object, mtext or text. And I get it with a leader, either selecting the
    arrow or the lines. There's no mtext associated with the leader.

    Have you considered not using the database object? Rather copyobjects from the xref
    file itself, either using ObjectDBX or the active documents collection if the file is
    open. I mention it because what I use to do this doesn't use the database object and
    it works fine.

    BTW, wanting to copy from an xref is what got me started on those matrix functions.

    Joe Burke
     
    Joe Burke, Jan 14, 2005
    #3
  4. James Allen

    James Allen Guest

    Interesting, I found some mtext that does not give the error, but others
    that do. The part about the nested blocks is regarding the nested blocks
    themselves, not the items in the blocks. Like: (cadddr (nentselp)) as
    opposed to (car (nentselp)). The code I posted, as-is, does not support
    that but what I'm working on does. I've suspected lately that I might be
    learning how to use ObjectDBX in the near future. I guess I'll start
    investigating. Just seems like this should work as well, and I'm afraid of
    getting the same problem after investing in a different approach.

    James
     
    James Allen, Jan 14, 2005
    #4
  5. James Allen

    James Allen Guest

    Oh, and were you saying that all of the text objects, leaders, and nested
    inserts themselves copy fine through ObjectDBX? The nested inserts are my
    main concern, but not exclusively.

    James


     
    James Allen, Jan 14, 2005
    #5
  6. James Allen

    James Allen Guest

    Thank you Lucas. It looked like basically the same thing using ObjectDBX
    rather than the XRefDatabase property. Would you mind sharing what problems
    were still not resolved using ObjectDBX? Did you get the same problems or
    different ones? And have you used it to copy a block reference from the
    xref, or just the the most deeply nested items from block references?

    James
     
    James Allen, Jan 14, 2005
    #6
  7. James Allen

    Joe Burke Guest

    James,

    Yes, all object types copy as expected. I've never seen this, "Invalid owner object"
    error using either ObjectDBX or a doc in the active documents collection. I say this
    with confidence since I use my copy from xref program a lot. And I tested the same
    objects which didn't work with the database object used in your post here.

    The thing I use copies nested blocks. It only goes one level deep into the xref by
    design. So if nentselp returns four enames in the last list, I grab the second to
    last one. If there's only one ename in last list, the xref, I copy the selected
    object.

    I'm curious about these problems using the database object. It's an obvious choice,
    but not something I tried before in terms of copyobjects. I went the other route from
    the start. Mostly because John Uhden told me that was the way to go.

    If you want to try it the other way, get the handle of the object to copy in the
    active file. Then something like this.

    (setq copyobj (vla-handletoobject <source doc> <handle>))
    (setq copyobj (car (vlax-invoke <source doc> 'copyobjects (list copyobj) <model
    space>)))

    Joe Burke

     
    Joe Burke, Jan 14, 2005
    #7
  8. James Allen

    James Allen Guest

    Well I thought ObjectDBX would be a lot harder than that. And it works fine
    with the nested blocks as well. Cool! Revised code follows. It does lead
    me to several other questions though.

    ObjectDBX:
    I have not seen code posted that closes the odbx-opened database. Does a
    drawing open with odbx not need to be closed?
    I've seen code you posted that returns the open document if it is open. Is
    there a significant performance hit just using odbx even if the source
    drawing is an open document, or does it cause other problems?

    Nested Highlighting:
    Joe, if you have this working, what led you to pursue the bounding box stuff
    we were discussing? Just the fact that this method is manipulating the
    database? Do you know of specific problems I should be aware of?

    James

    Code:
    (defun c:NPTest (/ Acad-Object ActiveDocument blk doc enm lyt obj pck tmp)
    (setq Acad-Object (vlax-get-acad-object))
    (setq ActiveDocument (vlax-get Acad-Object 'ActiveDocument))
    (setq pck (nentselp "Select nested object: ")
    obj (vlax-ename->vla-object (car pck))
    tmp (mapcar 'vlax-ename->vla-object (cadddr pck))
    )
    ;; Copy Nested first if necessary
    (if tmp
    (progn
    (setq blk (vla-get-Name (last tmp))
    blk (vla-Item (vla-get-Blocks ActiveDocument) blk)
    lyt (vla-get-ModelSpace ActiveDocument)
    )
    ;; Access ObjectDBX
    (if (eq (vla-get-IsXref blk) :vlax-True)
    (progn
    (setq doc (vla-GetInterfaceObject
    Acad-Object
    "ObjectDBX.AxDbDocument.16"
    )
    )
    (vla-Open doc (vla-get-Path blk))
    (setq obj (vla-HandleToObject doc (vla-get-Handle obj)))
    )
    )
    ;; Copy and Transform
    (setq obj (car (vlax-invoke
    (cond (doc)
    (ActiveDocument)
    )
    'CopyObjects
    (list obj)
    lyt
    )
    )
    )
    (vla-TransformBy obj (vlax-tmatrix (caddr pck)))
    ;; Clean Up ObjectDBX
    (if doc
    (vlax-release-object doc)
    )
    )
    )
    ;; Highlight and Select
    (vla-Highlight obj :vlax-True)
    (setq enm (vlax-vla-object->ename obj))
    (sssetfirst (ssadd enm) (ssadd enm))
    (princ)
    )
    
     
    James Allen, Jan 14, 2005
    #8
  9. James Allen

    Joe Burke Guest

    James,

    As I mentioned privately, it's important to specifically release an ObjectDBX doc.
    Otherwise it remains open, read only. Releasing is analogous to closing. Related, if
    you modify an ODBX doc and want to save changes, use the SaveAs method rather than
    Save, which simply doesn't work. In most cases simply SaveAs the original file name,
    unless you have reason to do otherwise.

    The reason for checking the documents collection first is you can't use ODBX to open
    an open file. Trying to do so will toss an error.

    In terms of performance, you'll find working with ODBX files is faster than you might
    imagine. It's very fast since the graphics editor in not involved.

    Regarding our discussion about nested highlighting from the previous thread. The
    bounding box idea is just an alternative to copying the object, simply to highlight
    it. On the plus side it avoids the baggage which might come along with any copied
    object. Layers, linetypes, text styles, block names, etc. All of which need be
    trashed if the object was only copied in order to highlight. The down side is it
    doesn't look like the standard interface.

    Maybe I have a slightly different perspective on the issue because my first attempt
    at copying from an xref was designed to do that. Later I questioned why all the
    overhead, if all I want to do is provide some visual indication an object in an xref
    was selected. IOW, I don't need to copy the object. I'm just extracting data from it.
    For instance, a text string.

    BTW, I wonder if the Highlight and Select part is a bit redundant? Maybe just:

    (sssetfirst nil (ssadd (vlax-vla-object->ename obj)))

    Regards
    Joe Burke
     
    Joe Burke, Jan 14, 2005
    #9
  10. James Allen

    James Allen Guest

    That all helps. Thanks again Joe.

    James
     
    James Allen, Jan 15, 2005
    #10
  11. James Allen

    LUCAS Guest

    1.If the object(other blk) nested in xref not scales 1:1
    It needed to transform the object position.(still not resolved)

    2.Make sure you have the text style in activedoc. (Copy attrib)
    3.Finding the correct path of xref!

     
    LUCAS, Jan 17, 2005
    #11
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.