A Pseudo-Batch operation for DraftSight (free version)

Over the last year or so several questions have been posted by users of the free version of DraftSight relating to batch processing. This article attempts to provide a near-equivalent using the somewhat capability-limited scripting tools provided in the free version of the program.

Credit is given here to Doug Yates who first turned the author's thinking in the direction of the method that is used here --- namely calling one script from another and building a suite of single-action, scripts that work together for a purpose. This approach resolved a number of problems that arose when an attempt was made to write a single script for the purpose used as an example here.

This article is written by a Windows 7 user. Consequently, if a different platform is being used, the reader may need to make appropriate changes to some instructions to achieve an equivalent to that which is described here on the system being used. For that the author apologises.

The Problem

Provide a batch process to change the ltscale value in a large number of files arranged in different directories.

This requires that, within a directory or folder a single file is opened, the value is changed, and the file is saved and closed. That process is to be repeated for each file in the directory and for each directory.

For the purpose of this exercise, please

Create a folder “C:\\Testing” with a subfolder “TestFiles”.

Place multiple COPIES of a small .dwg file (four or five will do) in “TestFiles” naming them Test1, Test2, …, ... Test5 (Any other names will also work for the test – they do not have to be sequentially numbered). Ensure that these have a value for ltscale other than 10. It will most likely be 1.

Copy and paste separately the text of each of the sub-scripts and master-script below into a text editor such as notepad, copying all text between and including the marker lines shown “;;===========”. Save each in “C:\\Testing” with the filename shown immediately above the top marker line. (Note that the filename is NOT to be copied with the text of the script. It can be copied separately for naming the file though.) Make sure that each filename includes the “.scr” suffix.

The sub-scripts:

FileOpen.scr

;;============

;;FileOpen

Open

;;============

 

FileClose.scr

;;============

;;FileSave&Close

Save

Close

;;============

Change “Save” to “Save as” and add appropriate responses to save in a different directory. Some experimentation may be needed.

 

Ltscale10.scr

;;============

;;Set LTSCALE = 10.

ltscale

10

;;============

Note that any value may be substituted for “10” if a different value is desired.

The master script:

PsBatch.scr

;;=====================================

;;Open a file, change its LTscale value, and close the file.

;;First ensure dialogs will display -- The command button had to turn them off.

DisplayDialogs

Yes

;;Open a file

loadscript

C:\\Testing\\FileOpen.scr

;;Set ltscale to 10

loadscript

C:\\Testing\\LTscale10.scr

;;Close the file

loadscript

C:\\Testing\\FileClose.scr

;;=====================================

 

The command button:

Create the command button as described below.

Creating:

Open DraftSight.

Right-click on a docked toolbar and select CUSTOMIZE INTERFACE... > COMMANDS

Create a new customization file (if a “personalised” one does not already exist – white “+” on green circle at top of page) or select a “personalised” one from the list.

With the customization file selected (name in “Source” box), Right-click in main pane and select NEW COMMAND. A new command line will be highlighted.

Right-click on it, select RENAME, replace the default name with “PsBatch”, and press ENTER.

With “PsBatch” highlighted double-click the space under “Command string” and copy and paste the following string: ^C^C_DisplayDialogs;No;loadscript;C:\\Testing\\PsBatch.scr;

This instructs DraftSight to cancel any current command (^C^C), turn off dialog boxes (DisplayDialogs;No;), and starts the script “PsBatch” (loadscript;C:\\Testing\\PsBatch.scr). (Note that this last instruction needs suitably modifying when the path to the file is different.)

Double-click under “Description” and copy and paste the following string to the “Description” box: “Starts the pseudo-batch process.” (This displays on the status bar when the cursor rests on the command button.)

Large and small icons may be added later in the icon boxes if desired so that an icon, rather than the command name, will appear on the toolbar.

Select APPLY to lock in the command. (The command may be lost if that is not done !!! )

Adding the command button to a toolbar:

Select INTERFACE (Upper left) and expand TOOLBARS.

Decide on the toolbar to which the button is to be added. (If a new toolbar is being created make sure the appropriate personalised customization filename appears in the “Source” box at the top OR to show all existing toolbar names display “All Customization Files”.)

Left-click on the “Show command explorer” icon on the right and begin entering “PsBatch” in the “Find” box at the top (Not case-senitive). Keep typing until the new command name is seen in the list.

Drag it to the chosen toolbar.

Expand the toolbar and, if desired, re-order the item list.

Select APPLY and OK to return to DraftSight.

If the selected toolbar is not visible in DraftSight, turn it on. (Right-click a docked toolbar, select TOOLBARS..., check the box beside the toolbar name, and select OK.) The new button should now be available.

Procedure for use:

Open DraftSight with new drawing using the usual default template.

Select the “PsBatch” command button.

If necessary, navigate to the directory that contains the files of interest (In this case C:\\Testing\\TestFiles).

Select the first / next file.

Repeat, from the second line of this sequence, until done.

Since file selection is not automated, the user needs to select each file in turn and there is a possibility that a file may be missed or even processed twice. The latter is not a problem as the correct data will still result. The former, however is a problem. A method of flagging that a file has been processed is therefore desirable. This is achieved if DraftSight is set to create a backup within the directory each time a file is saved (a good general practice anyway). If files within the directory are grouped according to type then a directory that, at the start, shows only the list of originally-contained files will, after processing, show two lists differing only in the file extensions (.dwg and .bak). It follows then that when the lists are otherwise identical all files will have been correctly processed.

Check the TestFiles directory to see the results. If the number of files in each group is the same, all is well. A random file could also be checked by opening it in DraftSight and confirming the value of ltscale. For this case it should be 10. If the tests are good everything is working as expected.

If not then trouble-shooting needs to be commenced.

Where to from here?

When trying this is finished, the “Testing” directory can be deleted from the C:\\-drive and the toolbar and button changes reversed.

Alternatively, where it is wished that this become permanent on the system

  • Move the necessary files to a more appropriate location on the system.

  • Locate permanent working scripts with the other DraftSight scripts.

  • Modify paths and filenames used in the routines and the button command to appropriately reflect any changes.

The underlying principles demonstrated here may have application in any situation where bulk processing of .dwg files becomes necessary.

Disclaimer:

Use of the scripts and methods provided in the above article are entirely at the risk of the user. Please ensure that sufficient testing is done to prove their suitability for any intended purpose and that a backup copy of original files is kept at least until the processed files have been confirmed as correctly processed.

[User of DS (Free) V1R3.1 x64 on Windows 7/64 Home Premium.] 29 Jun 2013, 11:18 (NZ standard time)