Jump to content
Sign in to follow this  
calsan

Script replace pattern with fill

Recommended Posts

Help needed please! :confused:

I would like a script to replace all object fill patterns in a 2d drawing with a fill colour using vectorscript. Can anyone help with this?

For example, replace all instances of fill pattern #4 with fill colour #1826.

Thanks for any help.

Share this post


Link to post

Just create an empty drawing with 2 objects; One with attributes by class and one forced attributes based on a fill. Export to vectorscript and tada!

This will give you all you need to "change" the fill.

Next, all you need is a foreach loop with criteria, there are a lot of existing topics on how to use those.

Edited by Hippocode

Share this post


Link to post

Well, still struggling. I have found out this much:

This script pops up the object attributes for any object with fill pattern 3 and allows manual selection of the fill attribute.

EditProperties(INGROUP & INVIEWPORT & (FP=3));

This script sets the fill background colour of any selected object to colour 1236:

Procedure Filler;

FUNCTION fillObj(h:HANDLE) :BOOLEAN;

Begin

SetFPat(h,1);

SetFillBack(h,1236);

End;

BEGIN

ForEachObjectInLayer(FillObj,2,0,4);

END;

RUN(Filler);

No idea how to link the two. Actually, I haven't found much in the way of reference material. Vectorlab.info doesn't exist anymore and the script reference just provides a list of functions....

Share this post


Link to post

This works, but doesn't update items in groups...

Procedure Filler;

FUNCTION fillObj(h:HANDLE) :BOOLEAN;

Begin

SetFPat(h,1);

SetFillBack(h,1236);

End;

BEGIN

DSelectAll; SelectObj(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3));

ForEachObjectInLayer(FillObj,2,2,1);

END;

RUN(Filler);

Share this post


Link to post

I guess you want to set the fill for all the objects in your search criteria? Then you could do the following:

FUNCTION filler():

   FUNCTION fillObj(h: HANDLE): BOOLEAN;

       BEGIN
           SetFPat(h, 1);
           SetFillBack(h, 1236);
       END;

BEGIN
   ForEachObject(fillObj,'(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3))');
END;

RUN(filler);

It's better to not play with the selection, as this can confuse users, as after your script, the selection will be changed....

Edited by Dieter @ DWorks

Share this post


Link to post
You need to reset the objects you changed for them to reappear with the new attributes.

That's not entirely true....

Well behavior is different between object types and even Vectorworks versions. I just always do it to make sure it's properly reset.

Share this post


Link to post

Hi

Thanks for the help - but I can't get this line to compile:

BEGIN

ForEachObject(fillObj,'(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3))');

END;

I tried with and without the '' but it just pops up a script error.

I'm sorry, I also don't know how to reset objects!

Share this post


Link to post
Hi

Thanks for the help - but I can't get this line to compile:

BEGIN

ForEachObject(fillObj,'(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3))');

END;

I tried with and without the '' but it just pops up a script error.

I'm sorry, I also don't know how to reset objects!

Can you paste the script error you get? I typed this out of my head, probably some syntax error.... I don't use this that often.

Share this post


Link to post

This is the error output with '' in place:

Line #1: FUNCTION filler():

|

{ Error: Expected beginning of a statement. }

|

{ Error: Identifier not declared. }

Line #3: FUNCTION fillObj(h: HANDLE): BOOLEAN;

|

{ Error: Identifier not declared. }

|

{ Error: Identifier not declared. }

Line #6: SetFPat(h, 1);

|

{ Error: Identifier not declared. }

|

{ Error: Expected a string. }

|

{ Error: Expected a handle. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Error: Expected ) }

|

{ Error: Did not expect this after end of statement - missing ;? }

Line #7: SetFillBack(h, 1236);

|

{ Error: Expected END }

|

{ Error: Identifier not declared. }

|

{ Error: Expected a string. }

|

{ Error: Expected a handle. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected ) }

|

{ Error: Did not expect this after end of statement - missing ;? }

Share this post


Link to post

This is with the '' removed

Line #1: FUNCTION filler():

|

{ Error: Expected beginning of a statement. }

|

{ Error: Identifier not declared. }

Line #3: FUNCTION fillObj(h: HANDLE): BOOLEAN;

|

{ Error: Identifier not declared. }

|

{ Error: Identifier not declared. }

Line #6: SetFPat(h, 1);

|

{ Error: Identifier not declared. }

|

{ Error: Expected a string. }

|

{ Error: Expected a handle. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Error: Expected ) }

|

{ Error: Did not expect this after end of statement - missing ;? }

Line #7: SetFillBack(h, 1236);

|

{ Error: Expected END }

|

{ Error: Identifier not declared. }

|

{ Error: Expected a string. }

|

{ Error: Expected a handle. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected , }

|

{ Error: Expected a string. }

|

{ Warning: Expected a longint or integer expression. }

|

{ Error: Expected ) }

|

{ Error: Did not expect this after end of statement - missing ;? }

Share this post


Link to post

On a tangent...

This forum needs a 'like post' option... Would be nice to give a like to someone who's trying to help you out of a hole.

Share this post


Link to post

FUNCTION filler(): should be PROCEDURE filler; , as it doesn't return anything.

When an error occurs, you always get a long list of errors, but you have to solve them in the order they are given, because lower errors are mostly because of errors happening before it. So fixing the first could be solving all the others.

Edited by Dieter @ DWorks

Share this post


Link to post

This is the script now.

Procedure filler;

Function fillObj(h:HANDLE):BOOLEAN;

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1236);

END;

BEGIN

ForEachObject(fillObj,(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3)));

END;

RUN(filler);

Share this post


Link to post

And this is the error:

Line #8: ForEachObject(fillObj,(INSYMBOL & INOBJECT & INVIEWPORT & (FP=3)));

|

{ Error: Expected a procedure that accepts one handle argument. }

Line #10: RUN(filler);

|

{ Error: Expected a RUN statement at the end of the script }

Share this post


Link to post

I believe the fillobj Function has to be a procedure that accepts a single handle argument.

PROCEDURE fillObj(h:HANDLE);
	BEGIN
		SetFPat(h, 1);
		SetFillBack(h, 1236);
	END;

Share this post


Link to post

Procedure filler;

PROCEDURE fillObj(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1236);

END;

BEGIN

ForEachObject(fillObj,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=3)));

END;

RUN(filler);

This works!!!!!!!!

Happy Happy Joy Joy

Many thanks to Dieter @ DWorks and twk.

I hope the above code will be of use to someone reading this in the future.

Share this post


Link to post

Have modified the script to replace on multiple patterns to fills. Posting as may be of use to someone.

Share this post


Link to post

Procedure PatternsSwapToFill;

PROCEDURE fillObj1(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1236); {Fill 1 - Type the desired fill colour # here}

END;

PROCEDURE fillObj2(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1237); {Fill 2 - Type the desired fill colour # here}

END;

PROCEDURE fillObj3(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1238); {Fill 3 - Type the desired fill colour # here}

END;

PROCEDURE fillObj4(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1239); {Fill 4 - Type the desired fill colour # here}

END;

PROCEDURE fillObj5(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1240); {Fill 5 - Type the desired fill colour # here}

END;

PROCEDURE fillObj6(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 1241); {Fill 6 - Type the desired fill colour # here}

END;

BEGIN

ForEachObject(fillObj1,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=3))); {Type the original pattern 1 # here}

ForEachObject(fillObj2,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=4))); {Type the original pattern 2 # here}

ForEachObject(fillObj3,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=5))); {Type the original pattern 3 # here}

ForEachObject(fillObj4,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=6))); {Type the original pattern 4 # here}

ForEachObject(fillObj5,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=7))); {Type the original pattern 5 # here}

ForEachObject(fillObj6,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=8))); {Type the original pattern 6 # here}

END;

RUN(PatternsSwapToFill);

Share this post


Link to post

I found out the fill numbers are unreliable, as they have changed between vectorworks versions. More reliable than fill numbers is to use 24bit RGB values.

Get the RGB Value by hovering over the fill in the attirbutes palette.

Multiply each RGB value by 256

i.e.

Grey of RGB value (221, 221, 221) becomes (56576, 56576, 56576)

Below is amended 24bit RGB script.

Share this post


Link to post

Procedure PatternsSwapToFill;

PROCEDURE fillObj1(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h,21760,21760,21760); {Fill 1 - Type the desired fill colour # here}

END;

PROCEDURE fillObj2(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 34816,34816,34816); {Fill 2 - Type the desired fill colour # here}

END;

PROCEDURE fillObj3(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 43520,43520,43520); {Fill 3 - Type the desired fill colour # here}

END;

PROCEDURE fillObj4(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 49152,49152,49152); {Fill 4 - Type the desired fill colour # here}

END;

PROCEDURE fillObj5(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 56576,56576,56576); {Fill 5 - Type the desired fill colour # here}

END;

PROCEDURE fillObj6(h:HANDLE);

BEGIN

SetFPat(h, 1);

SetFillBack(h, 60928,60928,60928); {Fill 6 - Type the desired fill colour # here}

END;

BEGIN

ForEachObject(fillObj1,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=3))); {Type the original pattern 1 # here}

ForEachObject(fillObj2,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=4))); {Type the original pattern 2 # here}

ForEachObject(fillObj3,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=5))); {Type the original pattern 3 # here}

ForEachObject(fillObj4,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=6))); {Type the original pattern 4 # here}

ForEachObject(fillObj5,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=7))); {Type the original pattern 5 # here}

ForEachObject(fillObj6,(INSYMBOL & INGROUP & INOBJECT & INVIEWPORT & (FP=8))); {Type the original pattern 6 # here}

END;

RUN(PatternsSwapToFill);

Share this post


Link to post

Instructions to install the above script into a menu in your workspace:

Create the plugin:

Select menu item: Tools / Plug-ins / Plug-in Manager...

Custom Plug-ins Tab - click "New..."

Name the script "Grey Patterns to Grey Fills"

Select the option "Command"

Click "OK"

Click "Edit Script..."

Paste the script text copied from the above field

Click "OK"

Click "Close"

Edit your workspace:

Find the command "Grey Patterns to Grey Fills" under miscellaneous

Drag it under the menu "New"

(or your preferred menu location.

This will now be available at all times under the New menu

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