Jump to content

Recommended Posts

Posted

Hi, I would like to learn how to use scripts, but I have doubts about how much they can do and how much I expect to be able to do.

I ask you if:
- can scripts be run on closed files in a folder?
I expect that, correctly compiled as I need, I can run a script on all the files in a folder without having to manually open the files one by one, but "automatically" which for me "automatically" means specific lines in the script

Note: I know and make basic use of Lee Mac ScriptWriterV1-2 lisp

- Is it possible to execute commands that interact with control windows in manual mode? for example to specify an "OK"

- Is it possible to perform operations between a source file and the files to be modified? for example copying and inserting blocks, xrefs etc.

- Is it possible to perform operations such as replacing blocks within a file?
- Is it possible to perform operations such as compiling attributes of specific blocks within a file?
- Is it possible to perform operations such as renaming elements (layers, blocks) within a file?

 

I believe that the answers to these questions will save me from useless attempts and subsequent useless questions on the forum.

 

Thank you

Posted

Scripts.

 

On a very basic level, if the command can run in CAD then you can automate running that and I think there are 3 basic methods:

Run on file open. Which might be a LISP routine, when the file opens it runs the specified routine and this runs every time any file is opened. For example I have a couple that do this, one sets up the object snaps as I like them, another makes a little record into a text file of the file name as it opens.

 

Another type is to loop through a list of drawings (typically all contained in a single folder), open each, run a series of commands, save and close as required. Like the one above this can use any command that you can run in CAD. Might be something like drawing a line, might be running a LISP. The opening and closing is controlled by the script.

 

A third type is from the core console which does it all in the background, no files opened, but this doesn't have all the commands available, VLA- commands for example, however it is very quick. It won't do anything that needs the graphic interface though.

 

Lee Macs ScriptWriter and ScriptPro tend to do things in the background - I forget how, but have a nice interface for you to create the script.

 

I prefer the middle option, open file, do stuff, close file via a script partially that that creartes a .bak file if I make a mistake and need to go back a step. I also look at a script as a method to do stuff and go and make coffee which means no user interaction.

 

A lot of commands that have a command window / pop up requiring say "OK" also have a command line version only and it is better to use these, adding the "OK" as a part of the command call. Very tricky to hit a button with a script.

 

Switching between files is possible but you need to specify which files to go from and to. Better to have these copied before the script starts and just paste. Might be that you run a few iterations pasting an object from a clipboard each time. However for xrefs you can do that via the command line, no need to open another drawing, same with block files.

 

Yes for changing layer and block names and attributes.

 

 

 

All depends what you want to do but it all looks possible from your question

  • Thanks 1
Posted

A couple more suggestions, I have been making scripts for like 40 years, the main task is to get a file of dwg names, there are a few way I use old fashioned DOS, I put the file in a text editor and use replace to make the script. You can use VL-DIRECTORY-FILES to get a list of files. Also you can run lisp from a script generally best to use load and followed by defun name and values.

 

Some can not be used. "Is it possible to execute commands that interact with control windows in manual mode? for example to specify an OK" When tunning a script you would have any user input.

  • Like 1
  • 1 month later...
Posted

Good morning Bigal, I use various methods to obtain the list of files and folders in text form instead of using MS DOS, if it can be useful to you let me know.

 

To simplify this introduction to scripts, I kindly ask you to help me with this example, on a file I need to set the TEXT layer:
- color = 1 (RED)
- line type = CONTINUE
- line thickness = DEFAULT
How do you spell that? and how is it done?

Posted

In simple terms (use lisp) in your script

(command "-layer" "M" "TEXT" "C" 1 "" "LT" "Continuous" "" "")

 

Posted

The best way to make a script is to look at the options for the command you are using and your answers to each prompt.

 

Use F2 to bring up command line history and make the appropriate entries for the script, new line or a space will work for enter.

 

From Autodesk AutoCAD Help Scripts...

 

Quote

Command:

-INSERT Enter block name or [?] <tblk>: tblk

 Units: Inches Conversion: 1.0000

Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate/Explode/REpeat]: 0,0

Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>: 48

Enter Y scale factor <use X scale factor>: 48

Specify rotation angle <0>: 0

 

The following shows how the previous command sequence might look in a script file:

-INSERT

tblk

0,0

48

48

0

 

Most command sequences can also be placed on the same line in a script file:

-INSERT tblk 0,0 48 48 0

 

Posted

In some instances of a dialog box that the - in front of the command doesn't give a non-dialog box version, you can set FILEDIA and/or CMDDIA = 0 to suppress the dialog box.

  • 3 weeks later...
Posted

Thanks for help!

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