Syntax

code

Function: GetRect(Var p1x: double; Var p1y: double; Var p2x: double; Var p2y: double; Hint: String): Integer;

Description

Prompts the user to click 2 points on the active plan to define a rectangle then returns the coordinates in p1 and p2.

Returns 1 if the function is successfull or 0 if the user cancels.

Code Reference

  • 1. Create a New Form application
  • 2. Add a button to the form
  • 3. add Planswift to reference (Planswift9_tlb in the uses)
  • 4. copy code to button onclick event

code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

procedure TForm1.psGetRect(Sender: TObject);

var

  ps: IPlanSwift;

  Est,sect,Area: IItem;

  psline: ILine;

  pt1,pt2: IPoint;

begin

  //Get Planswift Interface

  ps := CoPlanswift.Create;

  //Place planswift into update mode

  ps.BeginUpdate;

  // Get the Takeoff Folder (Estimating Tab in Planswift);

  Est := ps.GetItem('Job\Takeoff');

  //Create a New Area Item in the Estimating Tab

  Area := Est.NewItem('Area','Get Rect Demo');

  //Create a new Section for the Area

  sect := Area.NewSection('Get Rect Demo Section');

  //Call the Get Rect functions

  psline := ps.GetRect('Draw Area');

  //Get the two points from the iLine Returned by the GetRect function

  pt1 := psline.Point1;

  pt2 := psline.Point2;

  //Add Points to section to create a box

  sect.NewPoint(pt1.X,pt1.y);

  sect.NewPoint(pt2.X,pt1.y);

  sect.NewPoint(pt2.X,pt2.y);

  sect.NewPoint(pt1.X,pt2.y);

  sect.NewPoint(pt1.X,pt1.y);

  //EndUpdate;

  ps.EndUpdate;

  //Free the Planswift Interface

  ps := nil;

end;