Jump to content
Developer Wiki and Function Reference Links Read more... ×
VectorGeek

Help(!) with NIL handle

Recommended Posts

Hey y'all:

 

We have a custom Path PIO that we use to track various areas (unit overall, storage, balcony) for apartment units. So that I can create a database worksheet that summarizes all the areas, unit by unit, I am working on a command that posts the areas from two small path polys to a larger path poly. The user would run this command before recalculating the database worksheet. I'm using a few ForEachObject() procedures (one in the main procedure, and two in a subroutine) to cycle through the objects, looking for a match by "unit number". Here is the code:

 

Procedure bindareas;

VAR
    h : HANDLE;
    hProcessStorage, hProcessBalcony : HANDLE;
    TheUnitNumber, StorageArea, BalconyArea : STRING;

 

Procedure process_storage (hProcessStorage : HANDLE);
BEGIN
    IF GetRField(hProcessStorage,'VG-Area Poly','unitnumber') = TheUnitNumber THEN
    BEGIN
        {get the storage area and post it to the source object}
        StorageArea := GetRField(hProcessStorage,'VG-Area Poly','calculatedarea');
        SetRField(h,'VG-Area Poly','boundstorage', StorageArea);    
    END;
END;

 

Procedure process_balcony (hProcessBalcony : HANDLE);
BEGIN
    IF GetRField(hProcessBalcony,'VG-Area Poly','unitnumber') = TheUnitNumber THEN
    BEGIN
        {get the balcony area and post it to the source object}
        BalconyArea := GetRField(hProcessBalcony,'VG-Area Poly','calculatedarea');
        SetRField(h,'VG-Area Poly','boundbalcony', BalconyArea);        
    END;
END;

    
Procedure do_me (h : HANDLE);
BEGIN
    TheUnitNumber := GetRField(h,'VG-Area Poly','unitnumber');
    ForEachObject(process_storage,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Storage'))));
    ForEachObject(process_balcony,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Balcony Open'))));
END;
    
BEGIN {main}
    ForEachObject(do_me,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Strata'))));
    ResetObject(h);
END;

Run(bindareas);

 

When I run it, it works, except for the posting of values to the main Path PIOs (the SetRField() procedures). In the subroutines “process_storage” and “process_balcony”, I am getting an error in the debugger that the handle called “h” is NIL so it doesn't execute the SetRField() routine. I don’t really understand passing handles to subroutines very well so I think it’s probably something simple.

 

Any help would be greatly appreciated.

 

All the best,

 

V-G

 

Share this post


Link to post

You are not setting the variable "h" as defined by VAR h : HANDLE; in the main procedure.

 

Procedure do_me (h : HANDLE); only sets "h" in that function. It is by chance the same name as the "h" variable of the main procedure but it is not the same variable.

Edited by Nicolas Goutte

Share this post


Link to post

Thanks Nicolas - I'm still confused however. If I declare h:HANDLE in the main procedure, isn't it available throughout the entire script? How would you recommend that I setup the handles in the sub-procedures then?

 

V-G

Share this post


Link to post

It is available, but as you do not set it, it has a default value that is NIL.

 

May be you can try something like:

 

Procedure do_me (myH : HANDLE);
BEGIN
    h := myH;
    TheUnitNumber := GetRField(h,'VG-Area Poly','unitnumber');
    ForEachObject(process_storage,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Storage'))));
    ForEachObject(process_balcony,((NOTINDLVP & NOTINREFDLVP & (R IN ['VG-Area Poly']) & ('VG-Area Poly'.'polyclass'='Area-Balcony Open'))));
END;

 

Share this post


Link to post

I think the score of variables with the same name is confusing. You have h defined as a global variable. Do_me also defines h, which is local for do_me and takes precedence— the arguments in a function definition are essentially like a VAR block for that function. 

 

If you rename your global as gH, and in do_me set gH := h, you may be good. 

 

You also may want to restructure your script a bit to make calculated area a global and add an & statement to the do_me FEO criteria so you also only search for object matching the unit number. 

Share this post


Link to post

May be the problem is another one: what means the variable h in the main procedure for you? Why do you want to reset only one object by ResetObject(h); ? Are you missing to set h to the first selected object (or similar)?

Edited by Nicolas Goutte

Share this post


Link to post

Many many thanks Nicolas and Josh. The assigning of the global variable "h" to a new variable works perfectly!

 

V-G.

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

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.

×