Jump to content
Developer Wiki and Function Reference Links ×

Script for fill of different color


Recommended Posts

Hi, Pat helped me with this script and it is working great! What about if I wanted to add a fill to the script with a specific color, for example rectangle with same red fill and black outline. 

<

PROCEDURE LineWeightChange;
{ (c) twk based off of original code by Petri Sakkinen 2008 } 

CONST     newWeight = 5; 

PROCEDURE ChangeIt (h : HANDLE);     
VAR         oldLW : INTEGER;     

BEGIN         oldLW := GetLW(h);         
IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN             
    Begin
        SetLW(h, newWeight); 
        SetPenFore(h, 65535,0,0);     
    End;
END; 

BEGIN     
FOREACHOBJECT(ChangeIt, ((SEL=TRUE))); 
END; 

RUN(LineWeightChange);

Link to comment

You will need to add the following 2 procedures after SetPenFore(h, 65535,0,0):

 

SetFPat(h,1);

SetFillBack(h, 65535, 0, 0);  {Red fill color}

 

If you need to find the RGB color value other than red, create a rectangle with the attributes that you want in a blank document. Export the file to Vectorscript and you will find in this text file that the attributes are listed prior to the creation of the rectangle.

Link to comment

Alternatively, select an item in the drawing with the fill colors you want and run this script.

 

Procedure GetRGB;

{May 21, 2018}
{© 2018 Patrick Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}


Var	R1, G1, B1: Real;

Begin
	GetFillBack(FSActLayer, R1,G1,B1);
	PtDialog3D('RGB Fill Values of selected object are:', Num2Str(0,R1),Num2Str(0,G1),Num2Str(0,B1),R1,G1,B1);
End;

Run(GetRGB);

 

Link to comment

I believe transparent is SetFPat(H1,0)  [zero]

 

For SetFPat, I believe (have to test every time, I can never completely remember) that positive values use the Patterns and negative values use the Hatches.  Zero is No Fill and One is Solid fill. You need to be careful with Hatches as the index will change from file to file.

Link to comment

Thanks, so... If I want to get rid of the line weight and just have a transparent fill of black, can I get rid of the top part of the script?

"

{ (c) twk based off of original code by Petri Sakkinen 2008 }
CONST 
    newWeight = 10;
PROCEDURE ChangeIt (h : HANDLE);
    VAR
        oldLW : INTEGER;
    BEGIN 
        oldLW := GetLW(h);
        IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN
            SetLW(h, newWeight);
            SetPenFore(h, 0,0,0);  
            SetFPat(H1,0) [zero];
            SetFillBack(h,0,0,0);
    END;

BEGIN
    FOREACHOBJECT(ChangeIt, ((SEL=TRUE)));
END; 

RUN(LineWeightChange);

Link to comment
1 hour ago, Pat Stanford said:

 Zero is No Fill and One is Solid fill.

 

You must also be careful here, too. 

SetFPat     { FILL Pattern  }

0 = No Fill

1 = Solid Fill using the BACKGROUND color    { VW uses this as the default for SOLID FILL }

2 = Solid Fill using the FOREGROUND color

 

In contrast:

SetLS     { LINE STYLE, the equivalent of the Pen's Pattern  }

0 = No Pen

1 = Solid PEN STYLE (pattern) using the BACKGROUND color

2 = Solid PEN STYLE (pattern) using the FOREGROUND color       { VW uses this as the default for SOLID PEN }

 

And then there is that negative value thing to contend with, too.

 

Good luck with all of this,

Raymond  (Make it confusing once, and it stays confusing forever. I wish I knew who to thank for this 😉 )

  • Like 1
Link to comment

You have to match the variable name for the handle to what you are using so the line would actually be:

 

SetFPat(h,0);

 

the [zero] was just a make sure you realized it was a number and not a letter.

 

BUT I don't think this will do what you want. You are now saying you want a "Transparent Fill of Black". What I have given you is a line to generate an object with No Fill which is what I think of as a "transparent" fill. It now sounds more like you want to set the opacity. This will let you be able to see through a filled object.

 

SetFPat(h,2);

SetFBack(h,65535,65535,65535);

SetOpacity(h,50);

 

This should give you an object with a a black fill 50% opacity.

 

 

Link to comment

it should actually be SetFillBack(h,0,0,0) for black color.

 

You also need to be careful with the scope of the IF statement. The IF statement should be formatted as:

 

        IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN

            BEGIN
            SetFPat(h,1);
            SetFillBack(h,0,0,0);

            SetOpacity(h,50);

            END;

 

The BEGIN and END calls are required to mark the start and end of the IF statement. Otherwise if you omit it as shown in your previous script:

        IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN
            SetLW(h, newWeight);
            SetPenFore(h, 0,0,0);  
            SetFPat(H1,0) [zero];
            SetFillBack(h,0,0,0);

 

Only the SetLW procedure will be executed under the IF statement. All the other procedures following will be executed for all objects.

Link to comment
Quote

in the script, I had to use 'SetFillBack' rather than 'SetFBack', why is that

 

SetFillBack() is the call to edit a single object's background color. There is no SetFBack call, it was a typo. These calls are all documented in the Script Function Reference. If this were still a book printed on paper, you'd carry it with you everywhere, Consider it the VW Programmer's Bible.

 

HTH,

Raymond

 

PS - Pat, thank you for the compliment. Also, in your previous example you set the Fill BG color to WHITE. Shouldn't it be set to BLACK?  SetFBack(h, 0, 0, 0);

Edited by MullinRJ
Answer the question asked, and not the one I mistakenly read.
Link to comment

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.

×
×
  • Create New...