Processing between 2 drawings?

Discussion in 'AutoCAD' started by RaghuMN, Mar 23, 2005.

  1. RaghuMN

    RaghuMN Guest

    Hi all,

    I have a (only one) drawing open.

    My intention is to:
    1. 'copyclip' some features from this drawing.
    2. Open another drawing
    3. Paste the copied features into the newly opened drawing.
    4. Save and close this new drawing.
    5. Get back to the old drawing and continue to repeat the cycle.

    Tried as follows till step 3:
    (defun c:cp()
    (setq sset (ssget)) ;from current drawing
    (command "copyclip" sset "")
    (command "._VBAStmt" (strcat "AcadApplication.Documents.Open \"" "c:/junk.dwg" "\"")
    (command "pasteorig") ;does not work in new drawing.
    )

    As soon as the new drawing is opened, it becomes the current. But, the line (command "pasteorig") does not get executed here since the program belongs to old drawing.

    Any tips on what to do so that I can continue to perform the steps 3, 4, 5?

    Thanks for any help.

    MNRaghu
     
    RaghuMN, Mar 23, 2005
    #1
  2. RaghuMN

    Adesu Guest

    HI RaghuMN,I have a script as like your own,but this script still few
    problem,maybe you wish try it,here this script,I've tested and got problem
    in "SDI"

    (vl-load-com)
    (setq osdi (getvar "SDI"))
    (setvar "SDI" 1)
    (setq oli (getvar "LISPINIT"))
    (setvar "LISPINIT" 0)
    (setq file1 "C:/Auto CAD 2000/Drawing1.DWG")
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) file1))
    (setq loc (list 0 0))
    (setq hei 1)
    (setq str "Adesu")
    (command "_text" loc hei "" str "")
    (prompt "\nSELECT A TEXT")
    (setq ss (ssget "x" '((0 . "TEXT"))))
    (command "_copyclip" ss "")
    (setq file2 "C:/Auto CAD 2000/Drawing2.DWG")
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) file2))
    (setq p1 (list 10 10))
    (command "_pasteclip" p1 "")
    (setvar "SDI" osdi)
    (setvar "LISPINIT" oli)


    line (command "pasteorig") does not get executed here since the program
    belongs to old drawing.
     
    Adesu, Mar 24, 2005
    #2
  3. RaghuMN

    Joe Burke Guest

    Hi RaghuMN,

    Have you considered using Active X and the Documents collection or ObjectDBX?

    Code outline using Documents collection. Let's assume you have three files open and
    you want to copy a selection set in model space from the active drawing to the other
    two. As you said, you want the selection set at the same coordinates, like pasteorig,
    in the other two.

    1 - Get the active document: (setq *doc* (vla-get-ActiveDocument
    (vlax-get-acad-object))).
    2 - Get the Documents collection. Assign to symbol *documents*.
    3 - Make a list of vla-objects from the selection set. Assign to symbol CopyLst.
    4 - Step through the Documents collection (vlax-for item *documents*... but skip the
    active document.
    5 - Get the model space collection for each document during step 4. Assign to symbol
    *mspace*.
    6 - Copy the list of vla-objects during step 4 like this.
    (vlax-invoke *doc* 'CopyObjects CopyLst *mspace*)
    7 - Save or not during step 4.

    I think you have to regen the other files before you'll see the copied objects. Not
    sure about that.

    The same operation can be done using ObjectDBX. What would differ is how you
    access/specify the copy to files. For instance, you could copy the selection set to
    all files in a folder. Or simply select one file at a time using getfiled.

    I appreciate this is beyond the scope of your question. But it should solve the
    problem. And it might give you some ideas on how to approach similar tasks.

    Joe Burke
     
    Joe Burke, Mar 24, 2005
    #3
  4. RaghuMN

    Nirmal Guest

    By my experience, you can do it using VBA only.

    Nirmal
     
    Nirmal, Mar 24, 2005
    #4
  5. RaghuMN

    Joe Burke Guest

    Nirmal,

    IMO, not T. Though I'm not familiar with VBA.

    Joe Burke
     
    Joe Burke, Mar 24, 2005
    #5
  6. RaghuMN

    RaghuMN Guest

    Joe Burke,

    Thanks for the detailed information.

    I'll give a try on the ActiveX method that you have suggested. This method seems to work ideally, though I am not able to put my hands on it now.
    ( I am too far from Object DBX, hence, I can't try that now.)

    I am leaving now for a vacation and be back by mid next week.


    Adesu,

    Thanks for the code. I'll surely give this a try and get back.

    Thanks,

    MNRaghu
     
    RaghuMN, Mar 24, 2005
    #6
  7. RaghuMN

    Joe Burke Guest

    MNRaghu,

    You're welcome.

    Post any questions you might have here, when you return from vacation.

    BTW, the ObjectDBX thing may look like black magic. But in fact, it isn't.

    Joe Burke
     
    Joe Burke, Mar 24, 2005
    #7
  8. No, as long as you don't have to do things like modify
    non-default justified text or attributes. For that, you'll
    need a C++ based solution, which can be viewed by
    some as not that much unlike black magic :)
     
    Tony Tanzillo, Mar 24, 2005
    #8
  9. RaghuMN

    Joe Burke Guest

    Tony,

    Thanks for the heads-up as usual. I didn't know that.

    BTW, regardless of my ignorance, it's nice to see a light touch from your end.

    Joe Burke
     
    Joe Burke, Mar 24, 2005
    #9
  10. RaghuMN

    RaghuMN Guest

    Hi Joe Burke,

    I again studied your suggestions.
    You have assumed that I already have 3 drawings open and built the rest of the processing logic is based on it.

    My case is slightly different, wherein I have only one drawing open.
    I search for features based on certain parameters in this drawing.
    If features are found, I need to open another drawing whose name is logically related to these selected features.
    These features should then be pasted into the newly opened drawing, saved and closed to return back to the old drawing.
    The cycle should again repeat (lisp should continue executing) with searching for features based on certain parameters in the old drawing.

    The problem for me is that the lisp stops executing once the new drawing is opened which automatically gets activated.
    I assume that the logic that you have suggested has control over the currently open drawings, but not with the then newly opened drawing.

    Have I misunderstood your logic or is there any other way to get what I need? Please comment.

    ----------

    Hi Adesu,

    I tried your function, but does not get executed since the functions "VLA-ACTIVATE" and "VLA-OPEN" does not exist (I use 2002). Can you extend your help further on this subject?

    Thank you both,

    MNRaghu
     
    RaghuMN, Apr 1, 2005
    #10
  11. RaghuMN

    Joe Burke Guest

    Hi RaghuMN,

    My first post in this thread suggested two possible methods. Use the Documents
    collection (all open files), or ObjectDBX.

    In some cases it's easier to use the Documents collection. That way you control the
    set of files to be modified or examined based on the fact they are open.

    The other way uses ObjectDBX to select files to be examined or modified. That's a
    one-at-a-time process in the sense there can only be one "active" ODBX document.
    That's not meat to imply you can't process a list of files using ODBX. Only that you
    must deal with each one separately. IOW, open, modify, save, one-at-a-time.

    It sounds like you want to use the ObjectDBX method. If so, you will not have a
    problem with, "...lisp stops executing..." because ODBX does not open the file in
    question in the graphics editor. Rather it opens the file in memory. That may be a
    poor explanation of what's actually going on. I defer to others to explain it more
    accurately.

    I'll post some sample code to demonstrate how it might be done using ODBX if that
    would be useful. Let me know.

    Regards
    Joe Burke
     
    Joe Burke, Apr 1, 2005
    #11
  12. RaghuMN

    RaghuMN Guest

    Joe Burke,

    Thanks for the information.

    As you have explained, the ObjectDBX method seems to fulfill my requirement.
    But, since I do not have any exposure to ObjectDBX method as of now, I would not seek any help on this issue, though I am interested at some point of time in future.

    W.r.t the vlisp / activex method, could you please let me know of any other possibilities to perform this task?

    (I do have in my mind of using the script and performing the paste task in another session, but keeping it as the last resort.)

    Thanks for the help offered.

    MNRaghu
     
    RaghuMN, Apr 2, 2005
    #12
  13. RaghuMN

    Joe Burke Guest

    MNRaghu,

    You're welcome.

    Regarding other possibilities, nothing comes to mind.

    Joe Burke
     
    Joe Burke, Apr 2, 2005
    #13
  14. If you do not use acaddoc.lsp files, you could create a temporary
    acaddoc.lsp file that runs when the drawings are created, then delete the
    file when finished.
    If you use acaddoc.lsp files, rename the file, create a new temporary
    acaddoc.lsp file, create drawings, then delete the new file and rename the
    old file.

    line (command "pasteorig") does not get executed here since the program
    belongs to old drawing.
     
    Alan Henderson @ A'cad Solutions, Apr 2, 2005
    #14
  15. Joe - Can you expound on this? I'm not sure what you mean
    by '"active" ODBX document'. ObjectDBX does not support the concept
    of an 'Active document' in an exclusive sense, and an ObjectDBX document
    is never active in the same way that documents in the drawing editor are.

    AFAIK, there is no limitation on the number of ObjectDBX documents
    that can be opened or accessed concurrently, contrary to what you
    write above ('one-at-a-time') seems to suggest.
     
    Tony Tanzillo, Apr 2, 2005
    #15
  16. RaghuMN

    Jeff Mishler Guest

    Tony, I think that what Joe is referring to is that, unlike the
    AcadApplication that has a Documents Collection, ObjectDBX does not, thereby
    making it a 'one at a time' Application. Of course, that does NOT imply that
    you can't have more than one instance of an ObjectDBX Application which
    would allow you to work with more than one at a time.

    Joe, here's a quick sample that shows that you can have more than one open
    at a time:
    Code:
    (defun odbx-test ( / *acad* num dwg1 dwg2 dwg3)
    (setq *acad* (vlax-get-acad-object)
    num 1.0)
    (mapcar '(lambda (x)
    (set (read x) (vla-getinterfaceobject *acad*
    "ObjectDBX.AxDbDocument"))
    (vla-open (eval (read x)) (strcat "c:\\testing" (itoa (fix num))
    ".dwg"))
    (vlax-invoke (vla-get-modelspace (eval (read x))) 'addcircle (list num
    num 0.0) num)
    (setq num (+ num 1.0))
    (vla-saveas (eval (read x)) (vla-get-name (eval (read x))))
    )
    (list "dwg1" "dwg2" "dwg3")
    )
    (foreach x (list dwg1 dwg2 dwg3)
    (princ (strcat "\nObjectDBX Drawing named: " (vla-get-name (eval x)) "
    is now open..."))
    )
    (mapcar '(lambda (x)
    (vlax-release-object (eval (read x))))
    (list "dwg1" "dwg2" "dwg3")
    )
    (princ)
    )
     
    Jeff Mishler, Apr 2, 2005
    #16
  17. RaghuMN

    Joe Burke Guest

    Tony,

    Thanks for the heads-up. I was not aware multiple ObjectDBX documents may be accessed
    concurrently. A wrong assumption on my part.

    I was trying to make a point, as Jeff suggested, that the Documents collection might
    be a convenient mechanism to use given the question at hand. Particularly if the OP
    is not familiar with ODBX. Which turned out to be the case.

    My other thought related to "one-at-a-time" was the idea getfiled only allows single
    document selection. So each document might as well be dealt with separately codewise:
    Open, CopyObjects, SaveAs, Close. Of course what I forgot was DOSLib dos_getfilem.
    Which is what I would use with the approach Jeff posted.

    I should know better than to make assumptions I haven't tested. Worse, post as fact
    here. On the other hand, at least I learned something valuable.

    Thank you,
    Joe Burke
     
    Joe Burke, Apr 3, 2005
    #17
  18. RaghuMN

    Joe Burke Guest

    Hi Jeff,

    Thanks for the code example. I ran it (modified for 2004) and note the incremented
    circle added to each file.

    I wonder if you've found a practical application for the idea of multiple concurrent
    ODBX files? See my reply to Tony regarding dos_getfilem, which returns a list of file
    names, with qualified path first.

    Given that my first thought, in terms of this thread, would be something like
    (foreach x (cdr lst) (setq fullpath (strcat (car lst) x)) Open <do stuff> SaveAs...
    So each file would be processed in turn, rather than having all selected files open
    at the same time.

    I appreciate your example may only be intended to demonstrate multiple concurrent
    ODBX files. I'm just asking the next obvious question. Are there applications for the
    idea which haven't dawned on me yet?

    Regards
    Joe Burke

     
    Joe Burke, Apr 3, 2005
    #18
  19. RaghuMN

    Jeff Mishler Guest

    Well, now ya got me. No, I have never had a need for multiple files....yet.
    And, in fact, I had never even thought about it until I read Tony's response
    to you. So I went exploring..... ;-) What can I say, it was a rainy Saturday
    and I was bored.
    I would approach this using the Windows FileSystemObject in place of DOSLib,
    only because you don't need to make sure you have the correct DOSLib for
    each version....
    I'm sure there are, and now that you know it's possible they may be found
    that much sooner.
    Jeff
     
    Jeff Mishler, Apr 3, 2005
    #19
  20. Sorry, I still don't follow that logic.

    I don't see how the lack of a documents collection makes ObjectDBX
    a 'one-at-a-time' application. It only means that you don't iterate
    over a collection exposed by AutoCAD (of course, you can quite easily
    maintain your own Collection of AxDbDocuments).

    An AxDbDocument represents an AutoCAD drawing on disk.

    I read Joe's comments to infer that you can only manipulate
    or access one of those at a time.
     
    Tony Tanzillo, Apr 3, 2005
    #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.