We continue the cycle of articles on working with the CAD API KOMPAS-3D Sergey Norseev, an engineer-programmer of the All-Russian Scientific-Research Institute “Signal”, the author of the book “Development of applications for KOMPAS in Delphi”. C ++ Builder is used as the medium. In previous lessons on the API KOMPAS
Basics and
Drawing Design, we proceeded from the fact that KOMPAS is not running, in the Lesson
Correct connection to KOMPAS we checked for the presence of already running KOMPAS and connected to it. In the last lesson, the
Main Inscription dealt with how to fill the main inscription of the drawing. In this lesson, we’ll continue to look at the COMPASS system interfaces and finally begin to draw.

Before creating complex drawings, it is necessary to learn how to build graphic primitives, such as points, lines, segments, and circles. We will talk today about how to do this.
Point
To build the point, use the
ksPoint method of the
ksDocument2D interface. Below is a prototype of this method.
')
long ksPoint ( double x, // double y, long style).
Valid point styles are shown in the table below.
Dot stylesIf successful, the
ksPoint method returns a pointer to the created point, and in case of error, the value is
zero .
Below is a fragment of a program that builds a point.
Document2D->ksPoint(100, 100, 0)
In this and subsequent examples from this article I will give only the most important parts of the 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 proceeding to the consideration of the construction of segments and circles, it is necessary to mention the styles of lines. KOMPAS offers several system line styles, each of which is defined by a positive integer. There are
25 styles in total. I will not give a complete list of them. I will name only the most frequently used.
Most used line stylesFor a complete list of styles, see the documentation (
Parameter Structures and Constants / Constants / Constants of Graphic Objects / System Line Styles ).
Description of the system line styles in the SDKStraight
To build a straight line, use the
ksLine method of the
ksDocument2D interface. Its prototype is:
long ksLine ( double x, // double y, double Angle).
This method has only three parameters: the coordinates of the point through which the straight line passes, and the angle (in degrees) between the straight 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 error, the number zero.
Below is an example of a program building a line.
Document2D->ksLine(100, 100, 45)
I draw your attention to the fact that the ksLine method does not allow you to specify a line style. He always builds auxiliary lines, since lines in COMPAS are auxiliary constructions.
The figure below shows a fragment of a straight line.
Fragment straightSection
To build a segment, use the
ksLineSeg method of the
ksDocument2D interface. Here is its 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 error, the value is
zero .
Below is an example of a program building a segment.
Document2D->ksLineSeg(100, 100, 150, 150, 1)
The figure below shows the segment itself constructed by this program.
SectionCircle
To construct a circle, use the
ksCircle method of the
ksDocument2D interface. Here is its 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 error, the value is
zero .
Below is an example of a program building a circle.
Document2D->ksCircle(100, 100, 30, 1)
The figure below shows the constructed circle.
CircleI draw your attention to the fact that the circle is constructed without designation of the center. How to build it will be discussed in one of the following articles of the cycle.
ConclusionIn this article, we learned about the line styles and learned how to build simple geometric objects: a point, a straight line, a segment, and a circle. In the next articles of the cycle, we will consider in detail the construction of more complex objects and operations on them.
To be continued, stay tuned to the blog.
Sergey Norseev, author of the book “Development of applications for KOMPAS in Delphi”.