⬆️ ⬇️

Using the KOMPAS-3D API → Lesson 2 → Drawing Design





And again about the CAD API KOMPAS. New article by Sergey Norseev, software engineer at VNII Signal, the author of the book Developing Applications for KOMPAS in Delphi. The first article can be read here .



For drawing the drawing uses several interfaces, among them:





Basic design options



A pointer to the ksSheetPar interface is returned by the GetLayoutParam () method of the ksDocumentParam interface, which describes the parameters of the document.

')

The ksSheetPar interface has two properties:





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 string opens with the properties of the document sheet.





Document tree (Picture is clickable)



In previous versions, Document Manager was used instead of a tree.
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 ​​for this property for the current design library, double-click 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 library of designs, double-click on the line in the document tree. A window will appear in front of you.





Window "Design"



The row in the "Library" column is the name of the library indicated in the "layoutName" field.

Click on the "..." button to the right of the "Name" field. A window will appear in front of you.





Dialogue choice of design



The shtType property contains the value from the “Number” column and determines the appropriate design. For example, for the document Design Drawing. The first sheet. GOST 2.104-2006 "(highlighted in the figure above), the value of the shtType property should be equal to 1 , and for the document" Title page. GOST 2.104-2006. "- 42 , etc.



There are only two methods for the ksSheetPar interface:





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 working with sheets of standard sizes.



Standard sheets



Standard sheet parameters are described by the ksStandartSheet interface, which has three properties:





Below is the source code of the program that creates an empty A4 format drawing with a frame and an unfilled 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 empty line is specified in the layoutName property of the ksSheetPar interface. If this property is set to the full path to the graphic.lyt library, the program does not work correctly. Below is the appearance of the created drawing.





Frame design drawing with standard sizes. The first sheet. GOST 2.104-2006



Non-standard sheets



The custom sheet parameters are described by the ksSheetSize interface with the following properties:





Below is the source code of the program that creates an empty drawing with a sheet size of 300x300 millimeters and an unfilled 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 non-standard size, you need to specify the value lt_DocSheetUser in the type property of the ksDocumentParam interface. After this, the GetSheetParam () method of the ksSheetPar interface will return a pointer to the ksSheetSize interface.

The figure below shows the result of this program.





Design frame for 300 mm by 300 mm sheet



When working with sheets of non-standard sizes, you need to remember that many formats of basic inscriptions are designed for sheets of certain sizes. When the KOMPAS system tries to adapt the main inscription to a sheet for the dimensions of which it is not designed, then nothing good will come of it. One of these results is shown in the figure below.





Frame design drawing for a sheet with dimensions of 100 per 100 mm. Parts of the stamp have gone beyond the boundaries of the sheet



In this example, a sheet with a size of 100x100 millimeters was created, and a type 1 type body letter was applied to it ("Drawing designs. First sheet. GOST 2.104-2006").



The third part.



Sergey Norseev, author of the book “Development of applications for KOMPAS in Delphi”.

Source: https://habr.com/ru/post/330588/



All Articles