Jump to content
Sign in to follow this  
David L

Script to change attributes of selected objects

Recommended Posts

The following is a VectorScript for setting an attribute for one or more selected objects. It uses the "ForEachObjectInLayer" procedure which is very powerful and customizable. It can do, in one line of code, what it would take many other lines of code to do. This script can be applied to setting almost any attribute for selected objects.

The best use for it is to create a menu command from the script and assign it a key command (See Robert Anderson's "What do I do with a VectorScript, anyway?" in this topic). That way you can select some objects and type a key command to change their attributes (line weight, dash, fill, pattern, etc.).

To set other attributes enter the procedure(s) you want in the "FUNCTION FillObject" subroutine. You can customize what objects are worked on by adjusting the parameters in the "ForEachObjectInLayer" procedure. Using the Constant for entering the attribute parameter makes is easier to create multiple copies for each line weight or other attribute.

This script also sets the default attribute for the drawing if no objects are selected. If you don't want it to do that, delete all of the lines with countObj in them.

Please copy everything including the comments if you distribute this script.

{===================================================================

??This script sets the line weight of the user-selected object(s)

??to value indicated for the CONSTANT - w.

??If no objects are selected the default fill pattern is set to the

??CONSTANT value.

??This Vectorscript may be freely distributed. No warranty

??provided. Use at your own risk. David LaBarbera, 2008

====================================================================}

PROCEDURE SelectedObjLineWeight;

CONST

???w = 2; { <----------- Line weight in mils.}

VAR

???countObj : INTEGER;

FUNCTION FillObject(h:HANDLE) :BOOLEAN;

BEGIN

???SetLW(h, w);

???countObj := countObj + 1;

END;

{---IF selected objects exist, they will be

????counted each time Function above is called}

BEGIN

???countObj := 0;

???ForEachObjectInLayer(FillObject, 2, 1, 4);

{---IF no objects are selected, then default fill pattern is set}

???IF countObj = 0 THEN PenSize(w);

END;

Run(SelectedObjLineWeight);

{==========================================================================

ForEachObjectInLayer(Function Call; objOptions; travOptions; layerOptions)

Object Options

0 = All objects

1 = Visible Objects only

2 = Selected Objects only

4 = Unlocked objects only

Traversal Options

0 = Traverse Shallow

1 = Traverse Groups

2 = Traverse Deep

Layer Options

0 = Current layer

1 = All layers

2 = Visible layers

4 = Editable layers

8 = Snappable layers

===========================================================================}

Share this post


Link to post

After reading Pat Stanford's script "Rotate objects by individual centers" I discovered the Count procedure, so I revised the script. Now it is basically only 3 lines of functioning code.

{===================================================================

??This script sets the line weight of the user-selected object(s)

??to value indicated for the CONSTANT - w.

??If no objects are selected the default fill pattern is set to the

??CONSTANT value.

??This Vectorscript may be freely distributed. No warranty

??provided. Use at your own risk. David LaBarbera, 2008

====================================================================}

PROCEDURE SelectedObjLineWeight;

CONST

???w = 2; { <----------- Line weight in mils.}

FUNCTION FillObject(h:HANDLE) :BOOLEAN;

BEGIN

???SetLW(h, w);

END;

BEGIN

???ForEachObjectInLayer(FillObject, 2, 1, 4);

{---IF no objects are selected, then default attribute is set}

???IF Count(SEL=TRUE) = 0 THEN PenSize(w);

END;

Run(SelectedObjLineWeight);

{==========================================================================

ForEachObjectInLayer(Function Call; objOptions; travOptions; layerOptions)

Object Options

0 = All objects

1 = Visible Objects only

2 = Selected Objects only

4 = Unlocked objects only

Traversal Options

0 = Traverse Shallow

1 = Traverse Groups

2 = Traverse Deep

Layer Options

0 = Current layer

1 = All layers

2 = Visible layers

4 = Editable layers

8 = Snappable layers

===========================================================================}

Share this post


Link to post

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

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...