Jump to content

Recommended Posts

Posted

Hello everyone, 

i have one simple task to do:

-open a dwg file, paste one text in a specific point

-close the file

and to do it again for a lot of files.

 

I tried a lot of different things with simple autolisp code but any of them worked.

 

Thanks for your help!

Posted

The tricky part with a plain LISP is that it runs in the current drawing, when that drawing is no longer the current drawing then (you open another for example) then the LISP stops... so you will probably have got as far as opening another drawing? No text pasted.

 

If you can make up a LIPS to paste the text at the point you wan, fairly simple

(defun....

.. create text or paste

).. end defun, a few lines

 

I suspect that that will take a matter of moments for you

 

Get that to work as you want and avoid VL:A commands then you an look at the core console (which doesn't do VLA, basic LISP only) or scripts.

 

Lee Mac has a good script editor on his website, and scriptpro (I think) - and there are others out there that will do the same (I have similar that is in a perpetual state of not being finished yet, other things get in the way), run the script program, point it to the LISP and files and off you go

 

Similarly with core console, make up the lisp and go that route, it is a bit quicker than scripts

 

Or... post the text LISP you make up below and no doubt you will get advice how to put that together to work on lots and lots of drawngs

Posted

Like this not tested saved as script.

 

open dwg1

(load "mylisp")

close y

open dwg2

(load "mylisp")

close y

open dwg3

(load "mylisp")

close y

Posted (edited)

It is doable.  I've done stuff like that.

 

But there's a few things you must arrange.

- You need to have a lisp file that  automatically loads when the drawing opens, then automatically executes the function.

  So somehow you must distinguish which files should auto execute that function and which don't.  For example you could give a list of folders.  If the drawing is in that folder, then execute the function.

Auto loading lisp files: 

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Automatically-load-AutoLISP-routines.html

 

That's something like:

;; file "paste_text.lsp"

(setq folders_to_autolaud (list
  "c:\\myAutocadfiles\\demo\\"
  "c:\\myAutocadfiles\\demo2\\"
))

(defun paste_text (/)
  ;; do the pasting here

  ;; finish by closing the file
  (command-s "._close" "_y")
)

(if (member (getvar "dwgprefix") folders_to_autolaud) 
  (paste_text)
)

 

Then with your main file you load this file and execute the command OFPT

;; file "open_files_and_paste_text.lsp"

(setq files_path "c:\\myAutocadfiles\\demo\\")
(setq list_of_files (list
  "file1.dwg"
  "file2.dwg"
  "file3.dwg"
))

(defun open_file (FileName ReadOnly / )
    (vla-Open
     (vla-get-Documents
      (vlax-get-Acad-Object)
     )
     FileName
     (if ReadOnly
      :vlax-true
      :vlax-false
     )
    )
)

(defun c:OFPT ( / i)
  (setq i 0)
  (repeat (length list_of_files)
    ;; iterate over all files
	  (open_file (nth i list_of_files) nil)
	  (setq i (+ i 1))
  )
  (princ)
 )

 

This is just the general idea .  It's not a finished, working example.

 

You probably need some mechanism to slow down the opening of files, or do it in batches.  You don't want 100 open tabs all actively doing things at the same time.

 

Anyone, feel free to expand on this.

Maybe if I got time to spare I'll see for a full example

Edited by Emmanuel Delay
Posted

Thanks everyone for the response, I will try again in a couple of days using your suggestions.

Thanks !!

 

 

Posted
On 7/7/2022 at 10:06 AM, nod684 said:

Have you tried @LeeMac Copy2Drawings lisp?

http://www.lee-mac.com/copytodrawing.html

 

just insert the text you want in one file and use the lisp

then select the files the you need

it will copy in the exact location.

 

That's interesting, the only thing is that the text i have to copy has to be different for each drawing.

 

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...