Jump to content
Developer Wiki and Function Reference Links ×

GetCurrentMode() Does not work at all


Recommended Posts

According to the VS Reference

When I run:

vwMode := GetCurrentMode;

vwMode should have one of the following values

 

FUNCTION   GetCurrentMode:INTEGER ;

 

Python:

def  vs.GetCurrentMode():

   return INTEGER

Description:

Returns the current application protection mode.

Return values:
0 - Mode Not Set
1 - Full Mode
2 - Demo Mode
4 - Education Mode
8 - Student Mode
16 - Viewer Mode
32 - Unlicensed Mode
64 - Banner Mode
128 - Watermark New Files Mode
256 - Print Watermark Mode
512 - Save Educational File Format Mode
1024 - Open Educational File Format Mode
2048 - Vector Script Export Mode
4096 - Beta Serial Number Mode

 

It returns NONE of those.  On my machine it returns "2305"

On the one student registration that I checked it retuned "456"

 

If I need to determine if the running VW program is a student version, how do I do that?

Link to comment
On 3/31/2021 at 1:41 AM, Sam Jones said:

According to the VS Reference

When I run:

vwMode := GetCurrentMode;

vwMode should have one of the following values

 

FUNCTION   GetCurrentMode:INTEGER ;

 

Python:

def  vs.GetCurrentMode():

   return INTEGER

Description:

Returns the current application protection mode.

Return values:

[...]

8 - Student Mode

[...]

 

If I need to determine if the running VW program is a student version, how do I do that?

 

You must write something like:
bool( vs.GetCurrentMode() & 8 )

Edited by Nicolas Goutte
Link to comment
6 hours ago, Nicolas Goutte said:

You must write something like:
bool( vs.GetCurrentMode() & 8 )

 

"something like:"  I'm afraid I need you to be way more specific. 

 

In vectorscript:

VAR

     ok : BOOLEAN;

 

ok := GetCurrentMode & 8

Gives a meaningless result.  

 

As you can see from Patricks response the integer that is returned is "bit packed" and is not any of the values that are shown.  It should return the values that are shown.  Vlado has stated that changing the function to do so would break already created scripts.  At a bare bare minimum, the documentation should explain the results delivered by the function.  Ideally a new function, GetCurrentModeN() would work as the current documentation describes.  Currently, a coder needs to write a function that does the bit math to unpack the integer.  That is math that I do not know, but I have been given an example of a possible function.  Or, one has to construct a function that uses a case statement that checks for all the possible results.  Now one doesn't need to test 14 squared combinations because some combinations would not make any sense, but still, that's a painful case statement to write and to figure out.  

OK this is a bit of whining by someone who doesn't have the bit math knowledge required, but I think it is fair to ask that the documentation describe the results of the function.  Currently, the user of that function has no way of testing for results about licensed he does not own.  I wanted educational license users to be free of the requirement to register there running copy of my tools, so I wrote  a test based on the documentation.  I had no way of knowing that the test would fail.  Bad.

 

On 3/30/2021 at 7:29 PM, Pat Stanford said:

Sam, it is a bitwise OR.  Each bit is used as a flag to indicate what is allowable in a 16 bit byte.

 

456 in binary is 0000111001000.

Patrick, I would love to know how you figured this out.

Link to comment
1 hour ago, Sam Jones said:

 

"something like:"  I'm afraid I need you to be way more specific. 

 

In vectorscript:

VAR

     ok : BOOLEAN;

 

ok := GetCurrentMode & 8

Gives a meaningless result.  

 

Sorry, Imenat it in Python

 

 

1 hour ago, Sam Jones said:

Patrick, I would love to know how you figured this out.

 

That is classic way to do things (especially in old C days). If you see constants that are 1, 2, 4, 8, 16... you have a good chance that the values are ORed

Link to comment
1 hour ago, Sam Jones said:

 

"something like:"  I'm afraid I need you to be way more specific. 

 

In vectorscript:

VAR

     ok : BOOLEAN;

 

ok := GetCurrentMode & 8

 

I have ggogled a bit (my Pascal is really rusty meanwhile that I do not use neither Pascal nor VectorScript) any more:

 

ok := (GetCurrentMode & 8 ) = 8

 

(You cannot assigned an integer to a boolean in Pascal, like you can do in other languages.)

Link to comment
  • Vectorworks, Inc Employee

Try this:

 

Procedure ASDF;

Var
vwMode : LongInt;
ModeCheck : Boolean;


FUNCTION BitCheck(largeNum, smallNum :LONGINT) :BOOLEAN;
{Returns true if smallNum is a power of 2 present in largeNum.}

VAR
bit :INTEGER;
BEGIN
BitCheck := FALSE;
bit := 15;
while bit > -1 do BEGIN
if largeNum >= (2 ^ bit) then BEGIN
largeNum := largeNum - (2 ^ bit);
IF (2 ^ bit) = smallNum THEN BEGIN
BitCheck := TRUE;
bit := 0;
END;
END;
bit := bit - 1;
END;
END;

Begin
vwMode := GetCurrentMode;
{vwMode := 456;}
ModeCheck := (BitCheck(vwMode, 4)) | (BitCheck(vwMode, 8));
{ModeCheck := (BitCheck(vwMode,1));}
AlrtDialog(Concat(vwMode,':',ModeCheck));
End;

Run(ASDF);

 

Link to comment

Thank you Kevin,

 

To clarify for later vectorscript users:

 

PROCEDURE TestCurrentMode;
{DEBUG}

CONST
    kcr =                 chr(13);
    
    Educational =        4;
    Student =            8;
    Banner =                64;
    WaterNewFiles =    128;
    PrintWatermark =    256;
    SaveEd =                512;
    OpenEd =                1024;
    BetaSerial =        4096;
    
VAR
    VWMode                :LONGINT;
    IsFull                :BOOLEAN;
    IsEd                    :BOOLEAN;
    IsStudent            :BOOLEAN;
    IsMakeWater            :BOOLEAN;
    IsPrintWater        :BOOLEAN;
    IsBanner                :BOOLEAN;
    IsBeta                :BOOLEAN;
    

{================================================================================}

    FUNCTION BitSet(largeNum, smallNum :LONGINT) :BOOLEAN;
    {Returns true if smallNum is a power of 2 present in largeNum.}
    
    VAR
    bit :INTEGER;
    
    BEGIN
        BitSet := FALSE;
        bit := 15;
        WHILE bit > -1 DO 
            BEGIN
                IF largeNum >= (2 ^ bit) THEN {IF vwMode >= 2 to the power of bit}
                    BEGIN
                        largeNum := largeNum - (2 ^ bit); {Strip large bit off largeNum (off of vwMode)}
                        IF (2 ^ bit) = smallNum THEN {IF 2 to the power of bit = smallNum (2 ^bit = smallNum[requested test number])}
                                                                             {requested is mode found in wvMode }
                            BEGIN
                                {END while loop. }
                                BitSet := TRUE;
                                bit := 0;
                            END; {IF (2 ^ bit) = smallNum}
                    END; {if largeNum >= (2 ^ bit)}
                bit := bit - 1; {strip large bit to test next smallest bit}
            END; {while bit > -1 }
    END; {FUNCTION BitSet}

{================================================================================}

BEGIN
    vwMode := 456;
    vwMode := GetCurrentMode;
    
    IsFull := BitSet(vwMode, 1);
    isEd := BitSet(vwMode, Educational);
    IsStudent := BitSet(vwMode, Student);
    IsMakeWater := BitSet(vwMode, WaterNewFiles);
    IsPrintWater := BitSet(vwMode, PrintWatermark);
    IsBanner := BitSet(vwMode, Banner);
    IsBeta := BitSet(vwMode, BetaSerial);
    
    AlrtDialog(CONCAT('vwMode = ', vwMode, kcr, kcr,'IsFull = ', IsFull, kcr,
                            'isEd = ', isEd, kcr,
                            'IsStudent = ', IsStudent, kcr,
                            'IsMakeWater = ', IsMakeWater, kcr,
                            'IsPrintWater = ', IsPrintWater, kcr,
                            'IsBanner = ', IsBanner, kcr,
                            'IsBeta = ', IsBeta));
END;
RUN(TestCurrentMode);
 

Link to comment

If you are testing for a specific mode, we can extrapolate on Nicholas's method a little.

 

ok:= (GetCurrentMode & BitToCheck) <>0;

 

As long as you pass a power of 2 as BitToCheck, you will only be checking if that one specific bit is set in Get Current Mode. I will only do the example for 3 bits, but it extrapolates up linearly.

 

0 Dec = 000 Binary

1 Dec = 001 Bin

2 Dec = 010 Bin

3 Dec = 011 Bin

4 Dec = 100 Bin

5 Dec = 101 Bin

6 Dec = 110 Bin

7 Dec = 111 Bin.

 

Notice that 1, 2, 4 each have only a single bit set to one. This applied to all powers of 2 in a binary system. Plus in a Binary system a logical AND returns a 1 only in those locations where both of the inputs have a 1.

 

I don't know if it is possible or not, but for a demo let's assume that someone has a GetCurrent Record of 5 (Full Mode and Ed Mode).

 

5 = 101

 

    101

&. 001

=  001   Since this is not equal to zero you can use 5 & 1 <> 0 to find that you have Full Mode

 

     101

&. 100

=  100.    5 & 4 <> 0 so you find you have Ed Mode.

 

As to how I know this It goes back to an Electrical Engineering degree and 30 years of bit twiddling in both hardware and software.

 

 

Link to comment

At that level, the binary math is not that foreign to me and pretty straight forward.  I keep needing to wrap my head around the "anding" of boolean values, but it ends up being pretty simple.  I needed the routine above that Kevin provided to extract the values from the integers yielded by the function.

I confess that Julian generously and privately offered a simpler solution, but I was/am pissed off that the documentation let put out what I thought was a simple solution that totally hosed my student users and without my knowledge.

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