Jump to content
Developer Wiki and Function Reference Links ×

Vectorscript troubleshooting


Recommended Posts

Hi Everyone, 

 

quick question, have a VS script here, taken from a script that calculated occupancy load calculations from a space object using custom fields in the space plugin object. After VW has now transferred alot of the space objects capabilities into regular, geoemetry, I was curious if anyone can help me port a similar functioning script for polygons / rectangle objects. Script (and original author name is below)

 

I attached a VW that shows some of the information I use in my documents. What I wanted to do is integrate occupancy in these areas, and some building code information. 

 

Note - The script operates without any errors, but, for some reason it doesn't actually change the record. Maybe someone can be pointed in the right direction from some of the VSwizards out there? (This is a duplicate post from the architectural forum, but I deleted that post, and reposted in here, since I thought it could be more relevant) Thanks in advance!!!

 

Modified Script (Original Script at the bottom)

 

 

Procedure MaxOccupancy;
{Badly scripted by Michael Klaers modified to General Object Areas}

{November, 2015}
{© 2015, Small Group, Inc - Michael Klaers michaelk@verysmallgroup.com}
{Licensed under the GNU Lesser General Public License}

VAR
    
    recordhand, WSResource, WSImgHand                :    HANDLE;                 
    StringOccRating                                                :    STRING;
    xArea, OccRating                                            :    REAL;
    TruncOccSpace, SqrFeetPerPerson                                :    LONGINT;
    
PROCEDURE HowManyPeople(recordhand:HANDLE);

BEGIN  {How Many People}
    
    SqrFeetPerPerson :=Str2Num(GetRField(recordhand,'!Zoning_Area','BC_persons/sf'));
    
    xArea := AreaN((INSYMBOL & INOBJECT & INVIEWPORT & (R IN ['!Zoning_Area'])));
    
    OccRating := xArea/SqrFeetPerPerson;
    
    TruncOccSpace := Trunc(OccRating);
    
    StringOccRating := Num2Str(0,TruncOccSpace);
    
    SetRField(recordhand,'!Zoning_Area','BC_#ofpersons',StringOccRating);

    ResetObject(recordhand);
    
    END;

BEGIN
    ForEachObject(HowManyPeople, ((INSYMBOL & INOBJECT & INVIEWPORT & (R IN ['!Zoning_Area']))));

    WSResource := GetObject('Zoning Area Summations_Poly');
    WSImgHand :=GetWSImage(WSResource);
    RecalculateWS(WSResource);
    ResetObject(WSImgHand);
    
    END;

RUN(MaxOccupancy);

 

Original Script Below 

 

Procedure MaxOccupancy;
{Badly scripted by Michael Klaers}

{November, 2015}
{© 2015, Small Group, Inc - Michael Klaers michaelk@verysmallgroup.com}
{Licensed under the GNU Lesser General Public License}

VAR
    
    SpaceHand, WSResource, WSImgHand        :    HANDLE;                 
    StringOccRating                            :    STRING;
    xArea, OccRating                        :    REAL;
    TruncOccSpace, SqrFeetPerPerson            :    LONGINT;
    
PROCEDURE HowManyPeople(SpaceHand:HANDLE);

BEGIN  {How Many People}
    
    SqrFeetPerPerson :=Str2Num(GetRField(SpaceHand,'Space','11_User-Def Info 2'));
    
    xArea := Str2Num(GetRField(SpaceHand,'Space','Area'));
    
    OccRating := xArea/SqrFeetPerPerson;
    
    TruncOccSpace := Trunc(OccRating);
    
    StringOccRating := Num2Str(0,TruncOccSpace);
    
    SetRField( SpaceHand ,'Space','11_User-Def Info 1',StringOccRating);

    ResetObject(SpaceHand);

    END;

BEGIN
    ForEachObject(HowManyPeople, ((PON='Space')));

    WSResource := GetObject('Space Occupancy Schedule');
    WSImgHand :=GetWSImage(WSResource);
    RecalculateWS(WSResource);
    ResetObject(WSImgHand);
    
    END;


RUN(MaxOccupancy);

 

 

Area Test_Poly v2020.vwx

Link to comment

The ForEachObject call is not passing a handle to the record, but rather to the object with the record attached. You should use a different variable name for the handle being passed to HowManyPeople. You will then need to get a handle to the record that is attached.

 

You will need to do something like this to find the right record:

N1:=NumRecord(myHand);
N2:=1;
Done:=False;
While ((N2<=N1) and (Done<>true)) do
  Begin
    RecHand:=GetRecord(mYHand,N2);
	RecName:=GetName(RecHand);
	If RecName='My_Field_Name' then Done:=True;
  End;

and then use RecHand in your Str2Num function.

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