Work with the KOMPAS-3D API → Lesson 2 → Drawing Design
- Tutorial
And again about the CAD CAD COMPASS API. New article by Sergei Norseev, software engineer at VNII Signal JSC, author of the book "Application Development for COMPASS in Delphi". The first article can be read here .
To design a drawing, several interfaces are used, among them:
- ksSheetPar - sets the basic design options, such as: the used design library and the specific design from this library;
- ksStandartSheet - sets the parameters of the standard sheet. It determines the size of the sheet, the orientation of the title block and the multiplicity;
- ksSheetSize - sets the parameters of a non-standard sheet (its sizes).
In this article we will consider the issue of creating drawings on both standard and non-standard sheets.
Basic design options
Interface pointer ksSheetPar returned by GetLayoutParam () interface ksDocumentParam , describing the parameters of the document.
The ksSheetPar interface has two properties:
- layoutName is the name of the design library. Usually, this is the graphic.lyt library , stored in the Sys subdirectory of the KOMPAS directory ;
- shtType - type of stamp ( title block ) from the specified design library.
In order to understand the purpose of these properties, open (or create a new) drawing in KOMPAS. Expand the Sheets list in the drawing tree. A line opens with the properties of the document sheet. Document Tree (Image is clickable)
In previous versions, instead of a tree, the Document Manager was used
In order to understand the purpose of these properties, open (or create a new) drawing in KOMPAS. Select the menu item “Service / Document Manager”. You will see the document manager window.
Document Manager
The line in the “Design Library” column is the name of the library indicated in the “layoutName” field . The shtType property sets the value of the Appearance column . To see the valid values of this property for the current design library, double-click on the line in the document manager window. A window will appear in front of you.
Document Manager
The line in the “Design Library” column is the name of the library indicated in the “layoutName” field . The shtType property sets the value of the Appearance column . To see the valid values of this property for the current design library, double-click on the line in the document manager window. A window will appear in front of you.
The shtType property sets the value of the column with GOST under the "Sheets" list . To see the valid values of this property for the current design library, double-click the left mouse button on a line in the document tree. A window will appear in front of you.
“Design” window The
line in the “Library” column is the name of the library indicated in the “layoutName” field .
Click on the "..." button to the right of the "Title" field. A window will appear in front of you.
Design Selection Dialog shtType
Propertycontains the value from the “Number” column and determines the appropriate design. For example, for the document “Design Drawing. First sheet. GOST 2.104-2006 ”(highlighted in the figure above) the value of the shtType property must be equal to 1 , and for the document“ Cover page. GOST 2.104-2006. ”- 42 , etc.
There are only two methods for the ksSheetPar interface :
- Init () - resets property values to default values;
- GetSheetParam () - returns a pointer to the interface ksStandartSheet (for a sheet of standard sizes) or ksSheetSize (for a sheet of custom sizes).
The type of sheet sizes (standard or not) is set in the properties of the ksDocumentParam interface when creating a drawing. In the beginning we will consider work with sheets of standard sizes.
Standard sheets
The parameters of a standard sheet are described by the ksStandartSheet interface , which has three properties:
- direct - the location of the title block ( FALSE - along the short side of the sheet, TRUE - along the long side);
- format - sheet format ( 0 - A0, 1 - A1, 2 - A2, 3 - A3, 4 - A4, 5 –A5);
- multiply - the multiplicity of the sheet format.
The following is the source code for a program that creates an empty A4 drawing with a frame and an empty title block.
KompasObjectPtr kompas;
//Запускаем КОМПАС
kompas.CreateInstance(L"KOMPAS.Application.5");
//Подготавливаем параметры документа
DocumentParamPtr DocumentParam;
DocumentParam=(DocumentParamPtr)kompas->GetParamStruct(ko_DocumentParam);
DocumentParam->Init();
DocumentParam->type= lt_DocSheetStandart;//Чертеж на стандартном листе
SheetParPtr SheetPar;
SheetPar = (SheetParPtr)DocumentParam->GetLayoutParam();
SheetPar->layoutName[0] = L'0';
SheetPar->shtType = 1; //Тип документа
//Подготавливаем параметры листа
StandartSheetPtr StandartSheet;
StandartSheet = (StandartSheetPtr)SheetPar->GetSheetParam();
StandartSheet->direct = false; //надпись вдоль короткой стороны
StandartSheet->format = 4; //А4
StandartSheet->multiply = 1; //кратность
//Создаем чертеж
Document2DPtr Document2D;
Document2D = (Document2DPtr)kompas->Document2D();
Document2D->ksCreateDocument(DocumentParam);
//Делаем КОМПАС видимым
kompas->Visible = true;
kompas.Unbind();
I draw your attention to the fact that the property layoutName interface ksSheetPar an empty string. If you specify the full path to the graphic.lyt library in this property , the program does not work correctly. The following is the appearance of the created drawing.
Design drawing frame with standard sizes. First sheet. GOST 2.104-2006
Custom sheets
Custom sheet options are described by the ksSheetSize interface with the following properties:
- height - the height of the sheet in millimeters;
- width - width of the sheet in millimeters.
Below is the source code of the program that creates an empty drawing with a sheet size of 300x300 millimeters and an empty title block.
KompasObjectPtr kompas;
//Запускаем КОМПАС
kompas.CreateInstance(L"KOMPAS.Application.5");
//Подготавливаем параметры документа
DocumentParamPtr DocumentParam;
DocumentParam=(DocumentParamPtr)kompas->GetParamStruct(ko_DocumentParam);
DocumentParam->Init();
DocumentParam->type = lt_DocSheetUser; //Чертеж на нестандартном листе
SheetParPtr SheetPar;
SheetPar = (SheetParPtr)DocumentParam->GetLayoutParam();
SheetPar->layoutName[0] = L'0';
SheetPar->shtType = 1; //Тип документа
//Подготавливаем параметры листа
SheetSizePtr SheetSize;
SheetSize = (SheetSizePtr)SheetPar->GetSheetParam();
SheetSize->Init();
SheetSize->width = 300;
SheetSize->height = 300;
//Создаем чертеж
Document2DPtr Document2D;
Document2D = (Document2DPtr)kompas->Document2D();
Document2D->ksCreateDocument(DocumentParam);
//Делаем КОМПАС видимым
kompas->Visible = true;
kompas.Unbind();
I draw your attention to the fact that to create a drawing on a sheet of custom size, you need to specify the value lt_DocSheetUser in the type property of the ksDocumentParam interface . After this method GetSheetParam () interface ksSheetPar returns a pointer to the interface ksSheetSize . The figure below shows the result of this program. Design drawing frame for sheet with dimensions of 300 by 300 mm
When working with sheets of custom sizes, you need to remember that many formats of the main labels are designed for sheets of certain sizes. When the COMPASS system tries to adapt the title block to a sheet for which it is not designed, nothing good comes of it. One such result is shown in the figure below.
Design drawing frame for sheet with dimensions of 100 to 100 mm. Parts of the stamp went beyond the borders of the sheet.
In this example, a sheet of size 100x100 millimeters was created, and the main inscription of type 1 was applied to it ("Design drawing. First sheet. GOST 2.104-2006").
The third part.
Sergey Norseev, author of the book "Application Development for COMPAS in Delphi."