# Work with the KOMPAS-3D API → Lesson 5 → Graphic Primitives

• Tutorial
We continue the series of articles on working with the KOMPAS-3D CAD API Sergey Norseev, software engineer at VNII Signal JSC, author of the book "Application Development for KOMPAS in Delphi." The environment used is C ++ Builder. In previous lessons on the KOMPAS API Basics and Drawing Design, we assumed that KOMPAS was not running, in the Correct Connection to KOMPAS lesson, we checked that KOMPAS was already running and connected to it. In the last lesson, the main inscription was discussed how to fill in the main inscription of the drawing. In this lesson, we continue to review the KOMPAS system interfaces and finally begin to draw.

Before creating complex drawings, you need to learn how to build graphic primitives, such as points, lines, lines, and circles. Today we’ll talk about how to do this.

## Point

To construct the point of the method ksPoint interface ksDocument2D . The following is a prototype of this method.

``````long ksPoint (	double x,	//Координаты точки
double y,
long style).	//Стиль точки
``````

Valid point styles are shown in the table below.

Point Styles

If successful, the ksPoint method returns a pointer to the created point, and in case of an error, returns zero .
The following is a snippet of a point-building program.

``````Document2D->ksPoint(100, 100, 0);
``````

In this and subsequent examples from this article, I will provide only the most important pieces of code related to the topic of the article. How to get the ksDocument2D interface was described in previous articles in the series.

## Line styles

Before moving on to the construction of segments and circles, we need to mention the line styles. KOMPAS offers several system line styles, each of which is determined by a positive integer. There are 25 styles in total . I will not give their complete list. I will name only the most frequently used.

The most used line

styles See the documentation ( Parameter structures and constants / Constants / Graphic object constants / System line styles ) for a complete list of styles .

Description of system line styles in the SDK

## Straight

To construct the straight line method is used ksLine interface ksDocument2D . Its prototype:

``````long ksLine (	double x, 	//Координаты точки
double y,
double Angle).	//Угол наклона
``````

This method has only three parameters: the coordinates of the point through which the line passes, and the angle (in degrees) between the line and the horizontal line. The angle is delayed counterclockwise.
If successful, the ksLine method returns a pointer to the created line, and in case of an error, returns the number zero.
The following is an example of a straight line building program.

``````Document2D->ksLine(100, 100, 45);
``````

I draw your attention to the fact that the ksLine method does not allow you to specify the line style. He always builds auxiliary lines, because straight lines in COMPASS are auxiliary constructions.

The figure below shows a fragment of the constructed line.

Fragment of a straight line

## Section

To draw a line using the method ksLineSeg interface ksDocument2D . Here is his prototype:

``````long ksLineSeg (	double x1, 		//Координаты первой точки
double y1,
double x2, 	//Координаты второй точки
double y2,
long style).	//Стиль линии
``````

If successful, the ksLineSeg method returns a pointer to the created segment, and in case of an error, returns zero .
The following is an example of a program constructing a segment.

``````Document2D->ksLineSeg(100, 100, 150, 150, 1);
``````

The figure below shows the segment itself constructed by this program.

Section

## Circle

To construct a circle using the method ksCircle interface ksDocument2D . Here is his prototype:

``````long ksCircle (	double xc, 	    //Координаты центра
double yc,
double rad,	//Радиус
long style).	//Стиль линии
``````

If successful, this method returns a pointer to the created circle, and in case of an error, the value is zero .
The following is an example of a program that constructs a circle.

``````Document2D->ksCircle(100, 100, 30, 1);
``````

The figure below shows the plotted circle.

Circle

I draw your attention to the fact that the circle is constructed without a center. How to build it will be described in one of the following articles of the cycle.

Conclusion
In this article we got acquainted with line styles and learned how to build simple geometric objects: a point, a line, a line segment and a circle. In the following articles of the series, we will consider in detail the construction of more complex objects and operations on them.

To be continued, follow the news of the blog.

Sergey Norseev, author of the book "Application Development for COMPAS in Delphi."