Jump to content

Switch/Activate to an Open Drawing - Part of a Larger Routine


Recommended Posts

Posted (edited)

My end goal is this:

From the current drawing

       Go to model space

        Copy everything using 0,0 as the base point.


Switch to a specific drawing (ie:TARGET.dwg)
       Activate model space

       Paste the clipboard to 0,0

this code does the first part
 

(defun c:C2C (  )  
  (vl-load-com)
  (command "model") ;; Switch to model space
  (command "_.ZOOM" "EXTENTS")
  (command "_.COPYBASE" "0,0" "ALL" "")
  (princ)
)

 

I found the snippet below here
 

(vla-activate(vla-open (vla-get-documents (vlax-get-acad-object))(findfile "TARGET.DWG") ))


which will open a drawing you specify (if it is already open it opens a locked version)

I do not know how to simply switch to an already open drawing (ie:TARGET.dwg)


Once the Target drawing is open I have this

 

(command "model") ;;;switch to model space
(command "pasteclip" "0,0") ;;;pastes clipboard to 0,0


Tharwat posted this
 

(defun c:Test nil
 (vlax-for doc (vla-get-Documents (vlax-get-acad-object))
   (if (eq (vla-get-fullname doc) [color=red]<complete_path_of_opened_drawing>[/color] )
     (vla-put-windowstate doc acmax)
     (vla-put-windowstate doc acmin)
   )
 )
 (princ)
)
(vl-load-com)

 

but I could not make it work.

This is as close as I have been able to get.

 

(defun c:C2C2 (  ) 
  (vl-load-com)
  (command "model") ;; Switch to model space
  (command "_.ZOOM" "EXTENTS")
  (command "_.COPYBASE" "0,0" "ALL" "")
(vla-activate(vla-open (vla-get-documents (vlax-get-acad-object))(findfile "TARGET.DWG") ))
  (princ)
)


Once the other drawing is open it will not process any other commands provided.

Typically I will have both the "source" and "target" drawings open at the same time


Can someone help me put these pieces together?
 

 

Edited by ILoveMadoka
  • ILoveMadoka changed the title to Switch/Activate to an Open Drawing - Part of a Larger Routine
Posted (edited)

Not possible really with LISP.

 

LISP is run via the parent drawing, so when you switch drawings, the 'parent' also changes - and this second isn't running the LISP, the LISP will just stop running.

 

You can try making a script to run a routine on one drawing and then the next, but I have only really had success where you open the drawing and not switch to an all ready opened drawing - I think it was something to do with getting the script to recognise which drawing to work on - opening the drawing then that drawing becomes the current one by default.

 

Anyway, generally not possible or easy (there are a few rare exceptions).

 

 

You might want to create 2 LISP files, one to do all the processing you need in drawing 1 and the other to do everything in drawing 2 - in your example:

LISP 1 Copy

LISP 2 Paste

but you have to manually switch from one to the other. You can make use of registry settings or temporary files to store information while you switch from one to the other.

 

 

 

(be great if it could.... been looking for something suitable to for example plot every open drawing for years and never found anything suitable, referencing Lee Mac, I think all his batch processes need all but the reference drawing to be closed)

Edited by Steven P
Posted

Hi
I don't know what CAD environment you're working in.
If you have a version of AutoCAD Map or C3D, you could use the "ade_" functions to achieve this.

Posted

Autocad 2025 Vanilla

Posted

if this opens a drawing called

 

(vla-activate(vla-open (vla-get-documents (vlax-get-acad-object))(findfile "TARGET.DWG") ))

 

how can I switch to an already open drawing called TARGET.DWG?

Posted

Generally with LISP it is not possible.

Posted (edited)
58 minutes ago, ILoveMadoka said:

Autocad 2025 Vanilla

 

Okay.
You can still try.

I don't know what's new in the latest versions of AutoCAD.

Try typing, for example, 'ade_savetodwg' in the Visual Lisp editor to see if it recognizes it as a function.

Aladdin might emerge from inside the lamp.

 

And...You can also:

1) Type arx in the command line and press Enter to check if ade.arx appears in the list.
2) Search the AutoCAD directory to see if ade.arx exists.

Edited by GLAVCVS
Posted (edited)

If I cannot make this part work, it's not going to work anyway..


I run this autoloading command to copy everything from the first drawing

 

(defun c:C2C1 (  ) 
  (vl-load-com)
  (command "model") ;; Switch to model space
  (command "_.ZOOM" "EXTENTS")
  (command "_.COPYBASE" "0,0" "ALL" "")
(vla-activate(vla-open (vla-get-documents (vlax-get-acad-object))(findfile "TARGET.DWG") ))
  (princ)
)

 

The SOURCE drawing is opened as well.
 

I have the following autoloading as well.
 

(defun c:C2C2 (  ) 
(command "model") 
(command "pasteclip" 0,0) 
(princ) )

 

If I run that command, nothing happens.
If I <CTRL> V it pastes the clipboard with my desired geometry into the drawing.
The <CTRL> V may be my workable solution but still...

 

if I type this at the command prompt

 

(command "pasteclip" 0,0) 

 

It works as well.


I do not understand what is wrong here


I'll look at the ade stuff tomorrow..
 

Edited by ILoveMadoka
Posted

Wonder if there is a tchnical difference between:

 

(command "_.COPYBASE" "0,0" "ALL" "")

and

(command "pasteclip" 0,0)

.. looking at "'s

 

0,0 could be "0,0" or a list, '(0 0) or (list 0 0) in pasteclip (and better to be a list, and the same in copybase)

Posted

Found something I had, Can be a bit flaky only have 1 new dwg open.

 

; by alanh copy a window from another dwg
; Nov 2019

(defun openblk (blkname / adocs)
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(vla-open acDocs blkname)
(command "copyclip" "w" (getvar 'extmin) (getvar 'extmax) "")
(vla-close (vla-item acdocs 1) :vlax-false)
(command "pasteclip" "0,0")
)
(openblk "d:\\acadtemp\\y.dwg")

 

It may be possible to play with the items in acdoc if you do a dump you will see current count of the number of dwgs open.

 

 

Posted

you might try python, concept

from pyrx import Rx, Ge, Gi, Gs, Db, Ap, Ed, Ax
import traceback

def dowblock(fromdb: Db.Database, path : str):
    lock = Ap.AutoDocLock()
    todb = fromdb.wblock(fromdb.modelSpaceId())
    todb.saveAs(path)
    
@Ap.Command("doit", Ap.CmdFlags.SESSION)
def woohoo():
    try:
        path = "e:\\temp\\outdwg.dwg"
        dowblock(Db.curDb(), path)
        Ap.DocManager().appContextOpenDocument(path)
        Ed.Core.alert(Ap.curDoc().fileName())
    except Exception as err:
        traceback.print_exception(err)

outdwg.png.81e3be9e487a12137fc38f071feec201.png

 

Posted

It's the simple things...

image.png.dcf0f2f42df3d50f8ec690a1f4c2a980.png

Solution:
 

(Command "Pasteclip" "0,0")

 

 

Sheesh!!




I will mess with the other code to see what they do..

 

Thank you all so very much!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...