This tutorial was inspired by iQuestions that were asking for some form of layer switching automation in DraftSight. The most recent was asking about an auto-dimension-layer – a facility to automatically switch to the dimension layer when initiating dimensioning.
DraftSight currently has no such facility but a useful work-around can be achieved using scripts and user-created command buttons. As noted at the end, it has possibilities for much wider application than just that one use.
In Brief:
Create a “Dimension” layer, with all required settings for the layer, as part of the [templatename].dwt drawing that is being used to start new drawings. (The following expects that layer to be already present in the current drawing.)
Create, and save with DraftSight scripts, a “Dim.scr” script file that switches to the “Dimension” layer and then starts a particular dimension command.
Create, and save too, a “Zero.scr” script file that ends the current operation and returns to a suitable default working layer such as layer zero.
Create a “Dim” command button to run the first script when the button is selected.
Create a “Zero” command button to run the second script when the button is selected.
Place those buttons on a convenient toolbar that will normally be active in the drawing.
The detail:
Create the “Dimension” layer
Open the [YourName].dwt file in which the dimension layer is to be created.
Activate the “Layers” toolbar (if not already active).
Select the “Layers manager” icon from the left end of the “Layers” toolbar. A blue highlight will mark one of the entries in the manager table.
Select “New” at the top of the “Layers manager” window that opens. A new layer will be created and highlighted, immediately below the one that was highlighted, inheriting its settings from its predecessor.
Double-click on the default name of that layer, so that it is highlighted within a white box, and change it to “Dimension”.
Press ENTER to complete the re-naming.
Under “Line color” double-click and select an appropriate color (the last item in the list will give a wider selection of colors if it's needed).
Similarly set “Line style”, “Line weight”, and (if desired) add a description.
Select OK to finish.
The new layer should now appear in the drop-list when the down-arrow of the box on the “Layers” toolbar is selected.
Save and close the file.
Create the “Dim.scr” script file
In DraftSight, open a new drawing using the modified template (This will become the default template until another template is used to open another new drawing.)
Press “Esc” three times (to serve as a start-marker in the Command listing).
Issue the following series of commands on the command line (without quotes): “-Layer”, “Make”, “Dimension”, press ENTER twice, “smartdimension” (or another option for the default dimensioning process), press ENTER, press ESC three times (an end-marker).
Press “F2” to display the expanded command list.
Highlight and copy all text between the markers (sets of three consecutive “Cancels”) in the command list.
Paste the copied text into a text-editor, such as Note Pad.
Edit out all except the commands and key presses that were entered (including each press of ENTER) so that they remain one on each line of the file as below (Each new line is equivalent to pressing ENTER from the keyboard):
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-layer
make
dimension
(Leave this line blank = pressing enter)
lineardimension
(Leave this line blank = pressing enter)
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
To document the script it is worth adding descriptions (each preceded by a “;” to mark it as a comment) as below:
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Make the dimension layer the active layer.
-layer
make
dimension
(Leave this line blank = pressing enter)
; Start the smart dimensioning command.
smartdimension
(Leave this line blank = pressing enter)
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Alternatively the last example above can be copied and the bracketed text from the two “blank” lines cleared to leave them physically blank.
Save the file to the DraftSight scripts directory as “Dim.scr” .
Create the “Zero.scr” script file
Proceed similarly to create the following script for returning to the default working layer (assumed to be 0 (zero), but may be any other layer).
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Return to the default working layer.
-layer
make
0
(Leave this line blank = pressing enter)
(Leave this line blank = pressing enter)
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Save it as “Zero.scr” .
Test the scripts
In DraftSight, with layer 0 active, Enter LOADSCRIPT on the command line.
If the “Select file” window is not showing the correct script directory, navigate to the relevant directory. (This probably only has to be done once.)
Select “Dim.scr”
“Dimension” (the name of the layer) should now be seen in the box on the “Layers” toolbar and “Specify entity” (or other appropriate prompt according to how initiating the dimensioning is done) should now be appearing on the command line ready for next action. If instead a different dimensioning command from the selected default is needed at this point, then simply select it from the dimension toolbar and carry on from there.
Use “loadscript” again and select Zero.scr. (This can be done without completing the dimensioning as the incomplete command will be cancelled by the new command.)
“0” should now be seen in the box on the “Layers” toolbar and the command line should be waiting for the next command to be entered.
If necessary, adjust the scripts until they work properly before proceeding further.
Now make a record of the full path to the script files for later use as follows:
Use “loadscript” to open the “Select file” window.
Left-click in the header box and copy the highlighted path to the Windows clip-board.
Paste it into a temporary text document on the desktop so that it can be easily retrieved later.
Close the “Select file” window.
Create the “Dim” command button
Select TOOLS > CUSTOMIZE INTERFACE... > COMMANDS.
It is good practice to keep user-created commands and toolbars, etc, separate from the main group so select a personal customization file if one already exists or select the “Create customization file” icon (+ in green circle at the top of the page) and create one with a name to suit. Once created it should appear in the “Source:” drop-list.
With the new customization file active (its name should be in the “Source:” box), right-click in the body of the table and select “New command”.
Double-click the temporary “Command” name on the highlighted line and change it to “Dim”. Then press ENTER.
The new command will be placed in alphabetic sequence with any other commands that appear.
To view other groupings try the other drop-list options. There should now be at least three options.
Select the newly created command name.
Double click in the empty box below “Command String” (near the bottom of the page).
Enter (without quotes) “ ^C^C_loadscript;[path]\\Dim.scr; where [path] is replaced by the path to the script directory that was recorded earlier. Copying and pasting is less error-prone than typing. Make sure too that the two semi-colons are put in the correct places.
The “^C^C” issues two “Cancel” instructions to terminate any active command. The “_” makes the command language-independent; and the semi-colons have the same effect as pressing ENTER on the keyboard.
Small and Large icons can be added once the buttons are working if desired. Until that is done the command name will be displayed instead.
Double-click in the space under “Description” and add a brief description that will appear on the command line when the cursor rests on the command.
Have a look at the structure of other commands if additional help is needed, but be careful not to accidentally change any of them. If such a mistake IS made, use the “Cancel” button at the bottom to terminate the activity without saving anything and have another try.
Type the command name in the “find” box to quickly isolate a command if it is lost.
Select APPLY to lock in the work when done and move on to the following.
Create the “Zero” command button
Similarly create the “Zero” command with “^C^C_loadscript;[path]\\Zero.scr;
Make sure both semi-colons are in the correct places!
Select “APPLY”.
Place those commands on a toolbar as buttons
Now that the commands have been created select INTERFACE and expand TOOLBARS.
A separate toolbar is likely to be desirable for the new commands to group them together so …
Right-click in the table space and select “New toolbar”. The temporary name “Toolbar” will appear in the list.
Right-click on the temporary name and change it to “SingleClick” (or another name of choice) and press ENTER.
Select the SHOW COMMAND EXPLORER button (second down on the right hand side).
Select the “Source:” to limit the list of commands and enter “Dim” in the find box if it is not immediately visible.
Drag the command to “SingleClick”.
Repeat for “Zero”.
Expand “SingleClick” (and maybe scroll down) and the names of the commands should be visible.
Select APPLY and then OK.
Test the buttons
In DraftSight, right-click on a docked toolbar and select TOOLBARS... > Check SINGLECLICK > Select OK.
The new toolbar with the two command buttons will be displayed (possibly somewhere in the upper left quarter of the window. It may be hard to see!) move it into the main workspace.
Make sure that layer zero (0) is active.
Select the “Dim” button.
“Dimension” should now be showing in the box on the layers toolbar and the command line should be showing the appropriate prompt to start the selected default dimensioning process.
Select the “Zero” button.
“0” (zero) should now be showing in the box on the layers toolbar and the command line should be waiting to receive a new command.
If all is well try it with some actual dimensions. They should show the linetype and color selected when setting up the dimension layer.
Cancel out with the Zero button.
Draw a line. It should be of the linetype and color associated with the working layer.
If all works as described then the whole process has been successful. If not – sorry – but it's back to fault-finding (de-bugging).
Icons
Icons are not essential because when no icon exists the command name is shown. However, icons can be more compact on a toolbar than names and the command name appears on a pop-up prompt when the cursor rests on the icon.
DraftSight provides for custom command icons to be stored at the default location shown in TOOLS > OPTIONS... > FILE LOCATIONS > INTERFACE (expanded) > CUSTOM ICON LOCATION (expanded). If a different location is to be used (recommended – as the icons will be more easily found for editing) then that path can be changed to suit by “browsing” to that directory (button on the right) and “selecting” the desired folder. The default will be replaced by the path to the selected folder. Note that this may have to be set again after any update of DraftSight.
Creating Icons
Icons are simply a small graphic (.png, .bmp, .jpg) intended to give a visual clue to the purpose of the icon and its underlying command. A user can create their own in any bitmap image editor such as “Paint”.
If some guidance is needed on how they are created make a single, screen capture of a pair of relatively simple icons from the “Customize – Commands” page, “small” and ''large” columns on the left of the main table. Open that pair in “Paint” (or an editor of choice) so that the form of each can be studied when zoomed in to the maximum that the editor allows. Make sure grid-lines are turned on so that the pixel structure of the image can be more clearly seen.
Typically the small icon is based on a square of around 16 x 16 pixels and the large icon on a square of around 20 x 20 pixels. Of course it is possible to use an existing icon as the starting point for a new one and simply modify it but be careful, in that case, not to over-write the original when saving.
Create each icon graphic as a separate image and save it with a suitable name to the designated custom “icons” directory. File-type .PNG is good as that type supports background transparency when it is needed.
Adding Icons
When the needed icons have been created, return to the “Customize – Commands” page.
If the “Icon explorer” panel is not already open, select the SHOW ICON EXPLORER icon (third down on the right) to open it.
Navigate to a command to which icons are to be added and select its name.
Select BROWSE at the bottom edge of the “Small icons” panel and navigate to the custom icons folder.
Click on the small icon that is needed. A copy should appear in the bottom of the “Small icons” table.
Select the copy and drag it to the “Small icon” cell of the main table, to the left of the command name.
Repeat similarly for the large icon using the BROWSE button from the bottom of “Large icons” panel.
Select APPLY.
Select another command then re-select the one just edited. The paths to each of the icons should now be visible under the “Small icon location” and “Large icon location” headings at the foot of the main table.
Repeat the process for each other command.
Select OK when finished. The icon for each command should now be visible on the toolbar in place of the command name and resting the cursor on the icon should bring up the command name.
Backing up
It is highly recommended that the “DraftSight” folder in “%appdata%/roaming” is backed up after completing the above processes so that any customizations are not lost during future updating of the DraftSight program.
Potential
It should be apparent that if this can be done with the two layers that have been used above, any layer that has been previously set up, (preferably in a template drawing) for a specific purpose with specific other attributes set, so that it can be used in drawings on a regular basis, could be handled in the same way and its button added to the SingleClick toolbar. For example: “Out” for outline; “Hid” for hidden lines; “Cen” for centre lines … (over to the user). Once the initial setting up has been done the switching between working modes and the respective layers would be seamless, with just a single “button-press”, from that time on.
The same technique could be applied so that a user has a range of regularly used blocks each able to be called with just a single “button-press” to initiate the block insertion process and select the layer on which it is to be inserted
… … … Think broadly! This has probably just scratched the surface!
[User of DS (Free) V1R3.1 x64 on Windows 7/64 Home Premium.]
10 May 2013, 14:34 (NZ standard time)
