### Complete KOMPAS Document Workflow Example Source: https://context7.com/frei480/-22-sdk/llms.txt This C++ code demonstrates a complete workflow for creating, modifying, saving, and opening a KOMPAS-3D document. It covers document creation, view setup, layer management, drawing basic geometry (rectangle, circle), adding centerlines, and saving/closing the document. ```cpp void CompleteWorkflow_Example() { reference pDoc; DocumentParam doc; // Initialize document parameters memset(&doc, 0, sizeof(DocumentParam)); lstrcpy(doc.fileName, "c:\\projects\\complete_example.cdw"); lstrcpy(doc.comment, "Complete Workflow Example"); lstrcpy(doc.author, "SDK Developer"); doc.regim = 0; // Visible mode doc.type = 1; doc.stPar.Toleranceat = 3; doc.stPar.multiply = 1; doc.stPar.direct = 0; doc.stPar.shtType = 1; // Create document pDoc = CreateDocument(&doc); // Create custom view ViewParam viewPar; viewPar.x = 100; viewPar.y = 150; viewPar.scale = 1; viewPar.ang = 0; viewPar.color = RGB(0, 0, 0); viewPar.state = stACTIVE; strcpy(viewPar.name, "Main View"); int viewNumber = 1; CreateSheetView(&viewPar, &viewNumber); // Create layer Layer(1); // Draw geometry - Rectangle with dimensions double x = 20, y = 20; double width = 80, height = 50; LineSeg(x, y, x + width, y, 1); LineSeg(x + width, y, x + width, y + height, 1); LineSeg(x + width, y + height, x, y + height, 1); LineSeg(x, y + height, x, y, 1); // Add circle double cx = x + width/2; double cy = y + height/2; Circle(cx, cy, 15, 1); // Add centerlines LineSeg(cx - 20, cy, cx + 20, cy, 3); LineSeg(cx, cy - 20, cx, cy + 20, 3); // Save document SaveDocument(pDoc, NULL); // Close document CloseDocument(pDoc); // Reopen to verify OpenDocument("c:\\projects\\complete_example.cdw", 0); } ``` -------------------------------- ### Access Assembly Component - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Provides an interface for working with parts and subassemblies within a 3D KOMPAS document. It allows accessing the active 3D document, getting the top-level part, creating new entities like sketches or planes, and iterating through entity collections such as faces. ```cpp // Access part from 3D document ksDocument3D doc(kompas.ActiveDocument3D()); if (doc.m_lpDispatch) { // Get top-level part ksPart part(doc.GetPart(pTop_Part)); // Create new entity (sketch, plane, axis, etc.) ksEntity entity(part.NewEntity(o3d_sketch)); // Get entity collection ksEntityCollection entities(part.EntityCollection(o3d_face)); // Iterate through entities for (int i = 0; i < entities.GetCount(); i++) { ksEntity face(entities.GetByIndex(i)); // Process each face... } } ``` -------------------------------- ### Create Closed Contour Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a closed contour from a series of sequential geometric primitives, such as line segments. The contour can have fill capabilities. The process involves starting the contour, adding primitives, and ending the object definition. ```cpp void Contour_Example() { reference p; // Begin contour definition (1 = with fill capability) Contour(1); // Add line segments forming closed shape LineSeg(10, 10, 10, 20, 1); LineSeg(10, 20, 40, 20, 1); LineSeg(40, 20, 40, 30, 1); LineSeg(40, 30, 70, 30, 1); LineSeg(70, 30, 70, 10, 1); LineSeg(70, 10, 10, 10, 1); // End contour formation p = EndObj(); // Returns: reference to contour object } ``` -------------------------------- ### Initialize KompasObject Interface (C++) Source: https://context7.com/frei480/-22-sdk/llms.txt Demonstrates how to obtain the KompasObject interface, the main entry point for KOMPAS-3D SDK operations. It covers methods for accessing 2D and 3D documents, and handling existing documents. ```cpp // Getting KompasObject interface // For standard *.rtw libraries - use export function: IDispatch* pKompas = CreateKompasObject(); // For ActiveX libraries - after ExternalRunCommand(): KompasObject kompas; kompas.m_lpDispatch = pKompas; // Access 2D document ksDocument2D doc2d(kompas.Document2D()); // Access active 3D document ksDocument3D doc3d(kompas.ActiveDocument3D()); // Access existing document by reference ksDocument3D activeDoc(kompas.ActiveDocument3D()); if (activeDoc.m_lpDispatch) { // Work with active 3D document } ``` -------------------------------- ### Open Existing Document - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Opens an existing KOMPAS document file. The function takes the file path and a режим parameter (0 for visible, 1 for invisible) as input. It returns a reference to the opened document if successful, which can then be used for further operations or closed. ```cpp // Syntax: reference OpenDocument(char *name, unsigned char regim) // regim: 0 - visible, 1 - invisible // 3 - specification visible without assembly sync // 4 - specification invisible without assembly sync void OpenExistingDocument() { // Open in visible mode reference doc = OpenDocument("c:\\drawings\\existing.cdw", 0); if (doc) { // Document opened successfully and is now current // Perform operations... // Close when done CloseDocument(doc); } } // Open in batch mode (invisible) reference batchDoc = OpenDocument("c:\\data\\batch_process.cdw", 1); ``` -------------------------------- ### Create and Manipulate 2D Document (C++) Source: https://context7.com/frei480/-22-sdk/llms.txt Illustrates the process of creating a new 2D document, adding a view with specific parameters, drawing basic geometric primitives (a rectangle), and then saving and closing the document. ```cpp // Create a new 2D document DocumentParam doc; memset(&doc, 0, sizeof(DocumentParam)); lstrcpy(doc.fileName, "c:\\drawings\\sample.cdw"); lstrcpy(doc.comment, "Sample Drawing"); lstrcpy(doc.author, "Engineer"); doc.regim = 0; // 0 - visible, 1 - invisible (batch mode) doc.type = 1; // Document type reference pDoc = CreateDocument(&doc); // Create a view ViewParam viewPar; viewPar.x = 10; viewPar.y = 20; viewPar.scale = 2; viewPar.ang = 0; viewPar.state = stACTIVE; strcpy(viewPar.name, "Main View"); int number = 1; CreateSheetView(&viewPar, &number); // Draw primitives in the document LineSeg(0, 0, 100, 0, 1); // Horizontal line LineSeg(100, 0, 100, 50, 1); // Vertical line LineSeg(100, 50, 0, 50, 1); // Horizontal line LineSeg(0, 50, 0, 0, 1); // Vertical line (rectangle complete) // Save and close SaveDocument(pDoc, "c:\\drawings\\sample.cdw"); CloseDocument(pDoc); ``` -------------------------------- ### Register KOMPAS AddIn using .reg File Source: https://context7.com/frei480/-22-sdk/llms.txt This is a sample .reg file content for registering a KOMPAS AddIn. It specifies the 'ProgID', 'Path', and 'AutoConnect' settings for the AddIn directly in the Windows Registry. ```registry ; File: MyLibrary.reg REGEDIT4 [HKEY_CURRENT_USER\Software\ASCON\KOMPAS-3D\AddIns\MyLibrary] "ProgID"="MyLibrary.class1" "Path"="c:\\MyLibrary.rtw" "AutoConnect"=dword:00000001 ``` -------------------------------- ### Create and Edit 3D Model Document (C++) Source: https://context7.com/frei480/-22-sdk/llms.txt Shows how to access an active 3D document, create a new sketch entity on the XY plane, and prepare it for editing. This is a foundational step for adding 3D geometry. ```cpp // Get active 3D document KompasObject kompas; ksDocument3D doc(kompas.ActiveDocument3D()); if (doc.m_lpDispatch) { // Get the top-level part ksPart part(doc.GetPart(pTop_Part)); if (part.m_lpDispatch) { // Create a new sketch entity ksEntity sketchEntity(part.NewEntity(o3d_sketch)); // Get sketch definition ksSketchDefinition sketchDef(sketchEntity.GetDefinition()); // Set sketch plane (XY plane) ksEntity planeXY(part.GetDefaultEntity(o3d_planeXOY)); sketchDef.SetPlane(planeXY); // Begin editing sketch sketchDef.BeginEdit(); // Draw sketch geometry (2D operations available here) // ... // End sketch editing sketchDef.EndEdit(); // Create the sketch sketchEntity.Create(); } } ``` -------------------------------- ### ksPart - Assembly Component Interface Source: https://context7.com/frei480/-22-sdk/llms.txt Interface for working with parts and subassemblies within a KOMPAS assembly document. ```APIDOC ## ksPart - Assembly Component Interface ### Description Interface for working with parts and subassemblies within an assembly document. ### Method (Not specified, likely class methods within the SDK) ### Endpoint (Not applicable, this is an SDK interface) ### Parameters (This section describes usage of the `ksPart` class and related objects, not typical API parameters) ### Request Example ```cpp // Access part from 3D document ksDocument3D doc(kompas.ActiveDocument3D()); if (doc.m_lpDispatch) { // Get top-level part ksPart part(doc.GetPart(pTop_Part)); // Create new entity (sketch, plane, axis, etc.) ksEntity entity(part.NewEntity(o3d_sketch)); // Get entity collection ksEntityCollection entities(part.EntityCollection(o3d_face)); // Iterate through entities for (int i = 0; i < entities.GetCount(); i++) { ksEntity face(entities.GetByIndex(i)); // Process each face... } } ``` ### Response (This section describes the functionality and methods of the `ksPart` interface, not typical API responses.) **Key functionalities include:** - Accessing the active 3D document. - Getting parts from the document. - Creating new entities (sketch, plane, axis, etc.). - Accessing entity collections (e.g., faces). - Iterating through entities. ``` -------------------------------- ### Create New Document - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a new KOMPAS document (drawing, fragment, text document, part, or assembly). It requires a DocumentParam structure to specify the file name, comment, author, and document type. The function returns a reference to the newly created document. ```cpp // Syntax: reference CreateDocument(DocumentParam *par) void CreateNewDrawing() { DocumentParam par; memset(&par, 0, sizeof(DocumentParam)); lstrcpy(par.fileName, "c:\\projects\\new_drawing.cdw"); lstrcpy(par.comment, "Project Drawing"); lstrcpy(par.author, "Designer"); par.regim = 0; // 0 = visible, 1 = invisible (batch) par.type = 1; // Document type // Standard parameters par.stPar.Toleranceat = 3; par.stPar.multiply = 1; par.stPar.direct = 0; par.stPar.shtType = 1; reference doc = CreateDocument(&par); // Document becomes current automatically // Returns: document reference on success, 0 on failure } ``` -------------------------------- ### Circle - Create Circle Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a circle with specified center coordinates, radius, and line style. ```APIDOC ## Circle - Create Circle ### Description Creates a circle with specified center coordinates, radius, and line style. ### Method Implicitly called by the `Circle` function. ### Endpoint N/A (Internal SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Syntax: reference Circle(double xc, double yc, double rad, int type) void DrawCircleWithAxes(double x, double y, double radius) { int solidLine = 1; // Solid main line int centerLine = 3; // Centerline style // Draw centerlines (axes) LineSeg(x - radius - 5, y, x + radius + 5, y, centerLine); LineSeg(x, y - radius - 5, x, y + radius + 5, centerLine); // Draw circle reference circle = Circle(x, y, radius, solidLine); // Returns: reference to circle on success, 0 on failure } ``` ### Response #### Success Response (200) Returns a reference to the created circle object. #### Response Example ``` // Returns: reference to circle object ``` ``` -------------------------------- ### Create Arcs Source: https://context7.com/frei480/-22-sdk/llms.txt Provides multiple functions for creating arcs with different parameter specifications, including arcs defined by angle, three points, or center and two points. Each function takes styling parameters. ```cpp void Arc_Example() { int solidMain = 1; // Solid main line int solidThin = 2; // Solid thin line // Arc by angle - center, radius, start angle, end angle, direction // ArcByAngle(xc, yc, radius, startAngle, endAngle, direction, style) ArcByAngle(50, 50, 40, 0, 90, 1, solidMain); // Arc by 3 points // ArcBy3Points(x1, y1, x2, y2, x3, y3, style) ArcBy3Points(80, 50, 50, 80, 50, 50, solidThin); // Arc by center, radius and 2 points // ArcByPoint(xc, yc, x1, y1, x2, y2, direction, style) ArcByPoint(50, 50, 100, 50, 50, 100, 1, solidThin); } ``` -------------------------------- ### Arc Functions - Create Arcs Source: https://context7.com/frei480/-22-sdk/llms.txt Provides multiple functions for creating arcs with different parameter specifications. ```APIDOC ## Arc Functions - Create Arcs ### Description Multiple functions for creating arcs with different parameter specifications. ### Method Implicitly called by `ArcByAngle`, `ArcBy3Points`, `ArcByPoint`. ### Endpoint N/A (Internal SDK functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp void Arc_Example() { int solidMain = 1; // Solid main line int solidThin = 2; // Solid thin line // Arc by angle - center, radius, start angle, end angle, direction // ArcByAngle(xc, yc, radius, startAngle, endAngle, direction, style) ArcByAngle(50, 50, 40, 0, 90, 1, solidMain); // Arc by 3 points // ArcBy3Points(x1, y1, x2, y2, x3, y3, style) ArcBy3Points(80, 50, 50, 80, 50, 50, solidThin); // Arc by center, radius and 2 points // ArcByPoint(xc, yc, x1, y1, x2, y2, direction, style) ArcByPoint(50, 50, 100, 50, 50, 100, 1, solidThin); } ``` ### Response #### Success Response (200) Arcs are drawn based on the provided parameters. #### Response Example None provided for arc creation functions. ``` -------------------------------- ### Create Hatching Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a hatched area within a closed boundary. This function requires defining hatch parameters (type, angle, step, offsets, color) and then drawing the boundary using geometric primitives before completing the hatch formation. ```cpp void Hatch_Example() { reference p; // Define hatch parameters // Hatch(type, angle, step, x_offset, y_offset, color) Hatch(1, 45, 3, 0, 0, 0); // Draw boundary (same as contour) LineSeg(10, 10, 10, 20, 1); LineSeg(10, 20, 40, 20, 1); LineSeg(40, 20, 40, 30, 1); LineSeg(40, 30, 70, 30, 1); LineSeg(70, 30, 70, 10, 1); LineSeg(70, 10, 10, 10, 1); // Complete hatch formation p = EndObj(); } ``` -------------------------------- ### Register KOMPAS AddIn DLL Library Source: https://context7.com/frei480/-22-sdk/llms.txt This C++ code demonstrates how to register and unregister a KOMPAS AddIn library by manipulating registry keys. It includes functions for setting the AddIn path and auto-connect settings. ```cpp #define ADDINS_PATH "HKEY_CURRENT_USER\Software\ASCON\KOMPAS-3D\AddIns\MyLibrary" STDAPI DllRegisterServer() { HRESULT hr = NOERROR; TCHAR szModulePath[MAX_PATH]; GetModuleFileName(theApp.m_hInstance, szModulePath, sizeof(szModulePath)/sizeof(TCHAR)); CString strPath(ADDINS_PATH); HKEY hKey; DWORD dwDisposition; if (RegCreateKeyEx(HKEY_CURRENT_USER, strPath, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS) { hr = E_UNEXPECTED; } else { hr = RegSetValueEx(hKey, "Path", 0L, REG_SZ, (CONST BYTE*)szModulePath, strlen(szModulePath)); DWORD dwVal = 1; hr = RegSetValueEx(hKey, "AutoConnect", 0L, REG_DWORD, (CONST BYTE*)&dwVal, sizeof(DWORD)); } return hr; } STDAPI DllUnregisterServer() { HRESULT hr = NOERROR; if (RegDeleteKey(HKEY_CURRENT_USER, ADDINS_PATH) != ERROR_SUCCESS) { hr = E_UNEXPECTED; } return hr; } ``` -------------------------------- ### Create Circle with Axes Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a circle with specified center coordinates and radius, along with its axes. It utilizes the Circle function and LineSeg for drawing axes. Returns a reference to the created circle or 0 on failure. ```cpp // Syntax: reference Circle(double xc, double yc, double rad, int type) void DrawCircleWithAxes(double x, double y, double radius) { int solidLine = 1; // Solid main line int centerLine = 3; // Centerline style // Draw centerlines (axes) LineSeg(x - radius - 5, y, x + radius + 5, y, centerLine); LineSeg(x, y - radius - 5, x, y + radius + 5, centerLine); // Draw circle reference circle = Circle(x, y, radius, solidLine); // Returns: reference to circle on success, 0 on failure } // Example: concentric circles void ConcentricCircles_Example() { double x = 30, y = 20; double innerRadius = 5; double outerRadius = 8; // Axis lines LineSeg(x - outerRadius - 5, y, x + outerRadius + 5, y, 3); LineSeg(x, y - outerRadius - 5, x, y + outerRadius + 5, 3); // Circles Circle(x, y, innerRadius, 1); Circle(x, y, outerRadius, 1); } ``` -------------------------------- ### Point - Create Point Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a point at specified coordinates with a given display style. ```APIDOC ## Point - Create Point ### Description Creates a point at specified coordinates with a given display style. ### Method Implicitly called by the `Point` function. ### Endpoint N/A (Internal SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Syntax: reference Point(double x, double y, unsigned int style) // Point is created in current layer of current view void MarkPoints_Example() { // Style values define point appearance reference p1 = Point(10.0, 20.0, 1); // Point at (10, 20) reference p2 = Point(30.0, 40.0, 1); // Point at (30, 40) reference p3 = Point(50.0, 60.0, 2); // Different style // Returns: reference to point object on success, 0 on failure } ``` ### Response #### Success Response (200) Returns a reference to the created point object. #### Response Example ``` // Returns: reference to point object ``` ``` -------------------------------- ### Hatch - Create Hatching Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a hatched area within a closed boundary. ```APIDOC ## Hatch - Create Hatching ### Description Creates a hatched area within a closed boundary. ### Method Implicitly called by the `Hatch` and `EndObj` functions. ### Endpoint N/A (Internal SDK functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp void Hatch_Example() { reference p; // Define hatch parameters // Hatch(type, angle, step, x_offset, y_offset, color) Hatch(1, 45, 3, 0, 0, 0); // Draw boundary (same as contour) LineSeg(10, 10, 10, 20, 1); LineSeg(10, 20, 40, 20, 1); LineSeg(40, 20, 40, 30, 1); LineSeg(40, 30, 70, 30, 1); LineSeg(70, 30, 70, 10, 1); LineSeg(70, 10, 10, 10, 1); // Complete hatch formation p = EndObj(); } ``` ### Response #### Success Response (200) Returns a reference to the created hatch object. #### Response Example ``` // Returns: reference to hatch object ``` ``` -------------------------------- ### Document Management Functions Source: https://context7.com/frei480/-22-sdk/llms.txt Functions for creating, opening, saving, and closing KOMPAS documents. ```APIDOC ## CreateDocument - Create New Document ### Description Creates a new KOMPAS document (drawing, fragment, text document, part, or assembly). ### Method (Not specified, likely a function call within the SDK) ### Endpoint (Not applicable, this is an SDK function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **par** (pointer to DocumentParam) - Required - Structure containing parameters for document creation. - **fileName** (char array) - Path and name of the new document. - **comment** (char array) - Comment for the document. - **author** (char array) - Author of the document. - **regim** (int) - Mode: 0 = visible, 1 = invisible (batch). - **type** (int) - Type of the document. - **stPar.Toleranceat** (int) - Tolerance setting. - **stPar.multiply** (int) - Multiplication factor. - **stPar.direct** (int) - Direction setting. - **stPar.shtType** (int) - Sheet type. ### Request Example ```cpp DocumentParam par; memset(&par, 0, sizeof(DocumentParam)); lstrcpy(par.fileName, "c:\\projects\\new_drawing.cdw"); lstrcpy(par.comment, "Project Drawing"); lstrcpy(par.author, "Designer"); par.regim = 0; par.type = 1; // Standard parameters par.stPar.Toleranceat = 3; par.stPar.multiply = 1; par.stPar.direct = 0; par.stPar.shtType = 1; reference doc = CreateDocument(&par); ``` ### Response #### Success Response (200) - **return value** (reference) - A reference to the newly created document. Returns 0 on failure. ``` ```APIDOC ## OpenDocument - Open Existing Document ### Description Opens an existing KOMPAS document file. ### Method (Not specified, likely a function call within the SDK) ### Endpoint (Not applicable, this is an SDK function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **name** (char pointer) - Required - Path to the document file. - **regim** (unsigned char) - Required - Mode: 0 = visible, 1 = invisible (batch), 3 = specification visible without assembly sync, 4 = specification invisible without assembly sync. ### Request Example ```cpp // Open in visible mode reference doc = OpenDocument("c:\\drawings\\existing.cdw", 0); if (doc) { // Document opened successfully and is now current // Perform operations... // Close when done CloseDocument(doc); } // Open in batch mode (invisible) reference batchDoc = OpenDocument("c:\\data\\batch_process.cdw", 1); ``` ### Response #### Success Response (200) - **return value** (reference) - A reference to the opened document. Returns 0 on failure. ``` ```APIDOC ## SaveDocument - Save Document ### Description Saves a KOMPAS document to a file. ### Method (Not specified, likely a function call within the SDK) ### Endpoint (Not applicable, this is an SDK function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **sheet** (reference) - Optional - Reference to the document to save. If 0, saves the current document. - **fileName** (char pointer) - Optional - The new filename to save the document as. If NULL, uses the document's existing filename. ### Request Example ```cpp void SaveDocumentExample(reference doc) { // Save with new name (Save As) int result = SaveDocument(doc, "c:\\output\\saved_drawing.cdw"); if (result == 1) { // Save successful } else { // Save failed } // Save current document with existing name SaveDocument(0, NULL); } ``` ### Response #### Success Response (200) - **return value** (int) - 1 on success, 0 on failure. ``` ```APIDOC ## CloseDocument - Close Document ### Description Closes an open KOMPAS document. ### Method (Not specified, likely a function call within the SDK) ### Endpoint (Not applicable, this is an SDK function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **sheet** (reference) - Optional - Reference to the document to close. If 0, closes the current document. ### Request Example ```cpp void CloseDocumentExample(reference doc) { // Close specific document int result = CloseDocument(doc); // Close current document CloseDocument(0); // Note: If document has unsaved changes, error flag is set } ``` ### Response #### Success Response (200) - **return value** (int) - 1 on success, 0 on failure. ``` -------------------------------- ### Create Point Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a point at specified coordinates with a given display style. The point is created in the current layer of the current view. Returns a reference to the point object or 0 on failure. ```cpp // Syntax: reference Point(double x, double y, unsigned int style) // Point is created in current layer of current view void MarkPoints_Example() { // Style values define point appearance reference p1 = Point(10.0, 20.0, 1); // Point at (10, 20) reference p2 = Point(30.0, 40.0, 1); // Point at (30, 40) reference p3 = Point(50.0, 60.0, 2); // Different style // Returns: reference to point object on success, 0 on failure } ``` -------------------------------- ### Create a Sketch Entity in KOMPAS-3D Source: https://context7.com/frei480/-22-sdk/llms.txt This C++ function demonstrates how to create a new sketch entity within a KOMPAS-3D part. It involves creating a sketch entity, defining its placement on a plane (XY plane in this case), and then drawing basic 2D geometry (a circle) before finalizing the sketch. ```cpp void CreateSketchEntity(ksPart& part) { // Create new sketch entity ksEntity sketchEntity(part.NewEntity(o3d_sketch)); if (sketchEntity.m_lpDispatch) { // Get sketch definition ksSketchDefinition sketchDef(sketchEntity.GetDefinition()); // Get XY plane for sketch placement ksEntity planeXY(part.GetDefaultEntity(o3d_planeXOY)); sketchDef.SetPlane(planeXY); // Begin edit mode sketchDef.BeginEdit(); // Draw 2D geometry in sketch // (use 2D functions: LineSeg, Circle, Arc, etc.) Circle(0, 0, 50, 1); // End edit mode sketchDef.EndEdit(); // Create the entity sketchEntity.Create(); } } ``` -------------------------------- ### Draw Line Segment with Style (C++) Source: https://context7.com/frei480/-22-sdk/llms.txt A utility function that creates a line segment between two points using the LineSeg function. It demonstrates how to specify the line style, such as 'solid main'. ```cpp // Syntax: reference LineSeg(double x1, double y1, double x2, double y2, unsigned int style) // style: 1 - solid main, 2 - solid thin, 3 - centerline void DrawRectangle(double x, double y, double width, double height) { int style = 1; // Solid main line // Draw four sides of rectangle reference l1 = LineSeg(x, y, x + width, y, style); reference l2 = LineSeg(x + width, y, x + width, y + height, style); reference l3 = LineSeg(x + width, y + height, x, y + height, style); reference l4 = LineSeg(x, y + height, x, y, style); // Returns: reference to line object on success, 0 on failure } ``` -------------------------------- ### Save Document - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Saves a KOMPAS document to a file. It can save the current document with a new name (Save As) or overwrite the existing file. The function returns 1 on success and 0 on failure. It takes an optional document reference and file name. ```cpp // Syntax: int SaveDocument(reference sheet, char *fileName) // If sheet = 0, saves current document // If fileName = NULL, uses document's existing filename void SaveDocumentExample(reference doc) { // Save with new name (Save As) int result = SaveDocument(doc, "c:\\output\\saved_drawing.cdw"); if (result == 1) { // Save successful } else { // Save failed } // Save current document with existing name SaveDocument(0, NULL); } ``` -------------------------------- ### Contour - Create Closed Contour Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a closed contour from sequential geometric primitives. ```APIDOC ## Contour - Create Closed Contour ### Description Creates a closed contour from sequential geometric primitives. ### Method Implicitly called by the `Contour` and `EndObj` functions. ### Endpoint N/A (Internal SDK functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp void Contour_Example() { reference p; // Begin contour definition (1 = with fill capability) Contour(1); // Add line segments forming closed shape LineSeg(10, 10, 10, 20, 1); LineSeg(10, 20, 40, 20, 1); LineSeg(40, 20, 40, 30, 1); LineSeg(40, 30, 70, 30, 1); LineSeg(70, 30, 70, 10, 1); LineSeg(70, 10, 10, 10, 1); // End contour formation p = EndObj(); // Returns: reference to contour object } ``` ### Response #### Success Response (200) Returns a reference to the created contour object. #### Response Example ``` // Returns: reference to contour object ``` ``` -------------------------------- ### Create Angular Dimension Source: https://context7.com/frei480/-22-sdk/llms.txt Creates an angular dimension between two lines or for a specified angle. It requires setting dimension parameters, including text properties, anchor points, arc radius, direction, and display options. Returns a reference to the dimension object. ```cpp void AngDimension_Example() { reference p; ADimParam angPar; memset(&angPar, 0, sizeof(ADimParam)); // Draw reference lines LineSeg(40, 0, 40, 40, 1); LineSeg(40, 0, 60, 20, 1); // Text parameters angPar.tPar.bitFlag = _AUTONOMINAL | _DEVIATION; angPar.tPar.sign = 0; angPar.tPar.pText = CreateArray(CHAR_STR_ARR, 0); AddArrayItem(angPar.tPar.pText, -1, "+0.3", 5); // Upper deviation AddArrayItem(angPar.tPar.pText, -1, "-0.3", 5); // Lower deviation // Dimension anchor points angPar.sPar.xc = 40; angPar.sPar.yc = 0; // Center point angPar.sPar.x1 = 40; angPar.sPar.y1 = 40; // First extension line point angPar.sPar.x2 = 60; angPar.sPar.y2 = 20; // Second extension line point angPar.sPar.rad = 50; // Dimension arc radius angPar.sPar.dir = -1; // Clockwise direction // Display parameters angPar.dPar.textPos = 0; // Auto placement angPar.dPar.textBase = 0; // Above dimension line center angPar.dPar.pl1 = 0; // First extension line visible angPar.dPar.pl2 = 0; // Second extension line visible angPar.dPar.pt1 = 1; // Arrow inside at first line angPar.dPar.pt2 = 1; // Arrow inside at second line angPar.dPar.shelfDir = 0; // No shelf p = AngDimension(&angPar); } ``` -------------------------------- ### Create Diameter Dimension - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a diameter dimension for circles and arcs in KOMPAS drawings. It requires setting up RDimParam with text, anchor, and display parameters before calling DiamDimension. The function returns a reference to the created dimension. ```cpp void DiamDimension_Example() { reference p; RDimParam dimPar; memset(&dimPar, 0, sizeof(RDimParam)); // Draw circle to dimension Circle(50, 50, 70, 1); // Text parameters dimPar.tPar.bitFlag = _AUTONOMINAL; // Auto nominal value dimPar.tPar.pText = 0; dimPar.tPar.sign = 0; // Diameter symbol auto // Anchor parameters dimPar.sPar.xc = 50; dimPar.sPar.yc = 50; // Circle center dimPar.sPar.rad = 70; // Circle radius // Display parameters dimPar.dPar.textPos = 75; // Text position dimPar.dPar.pt1 = 1; // Arrow type - inside dimPar.dPar.pt2 = 1; // Arrow type - inside dimPar.dPar.shelfDir = 1; // Shelf direction - right dimPar.dPar.ang = -30; // Dimension line angle p = DiamDimension(&dimPar); } ``` -------------------------------- ### DiamDimension - Diameter Dimension Source: https://context7.com/frei480/-22-sdk/llms.txt Creates a diameter dimension for circles and arcs in a drawing. ```APIDOC ## DiamDimension - Diameter Dimension ### Description Creates a diameter dimension for circles and arcs. ### Method (Not specified, likely a function call within the SDK) ### Endpoint (Not applicable, this is an SDK function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **dimPar** (pointer to RDimParam) - Required - Structure containing dimension parameters. - **tPar.bitFlag** (int) - Auto nominal value. - **tPar.pText** (pointer to char) - Text for the dimension. - **tPar.sign** (int) - Diameter symbol sign. - **sPar.xc** (double) - X-coordinate of the circle center. - **sPar.yc** (double) - Y-coordinate of the circle center. - **sPar.rad** (double) - Radius of the circle. - **dPar.textPos** (double) - Position of the text. - **dPar.pt1** (int) - Arrow type for point 1. - **dPar.pt2** (int) - Arrow type for point 2. - **dPar.shelfDir** (int) - Direction of the shelf. - **dPar.ang** (double) - Angle of the dimension line. ### Request Example ```cpp reference p; RDimParam dimPar; memset(&dimPar, 0, sizeof(RDimParam)); // Draw circle to dimension Circle(50, 50, 70, 1); // Text parameters dimPar.tPar.bitFlag = _AUTONOMINAL; dimPar.tPar.pText = 0; dimPar.tPar.sign = 0; // Anchor parameters dimPar.sPar.xc = 50; dimPar.sPar.yc = 50; dimPar.sPar.rad = 70; // Display parameters dimPar.dPar.textPos = 75; dimPar.dPar.pt1 = 1; dimPar.dPar.pt2 = 1; dimPar.dPar.shelfDir = 1; dimPar.dPar.ang = -30; p = DiamDimension(&dimPar); ``` ### Response #### Success Response (200) - **return value** (reference) - A reference to the created dimension object. ``` -------------------------------- ### AngDimension - Angular Dimension Source: https://context7.com/frei480/-22-sdk/llms.txt Creates an angular dimension between two lines or a specified angle. ```APIDOC ## AngDimension - Angular Dimension ### Description Creates an angular dimension between two lines or a specified angle. ### Method Implicitly called by the `AngDimension` function. ### Endpoint N/A (Internal SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp void AngDimension_Example() { reference p; ADimParam angPar; memset(&angPar, 0, sizeof(ADimParam)); // Draw reference lines LineSeg(40, 0, 40, 40, 1); LineSeg(40, 0, 60, 20, 1); // Text parameters angPar.tPar.bitFlag = _AUTONOMINAL | _DEVIATION; angPar.tPar.sign = 0; angPar.tPar.pText = CreateArray(CHAR_STR_ARR, 0); AddArrayItem(angPar.tPar.pText, -1, "+0.3", 5); // Upper deviation AddArrayItem(angPar.tPar.pText, -1, "-0.3", 5); // Lower deviation // Dimension anchor points angPar.sPar.xc = 40; angPar.sPar.yc = 0; // Center point angPar.sPar.x1 = 40; angPar.sPar.y1 = 40; // First extension line point angPar.sPar.x2 = 60; angPar.sPar.y2 = 20; // Second extension line point angPar.sPar.rad = 50; // Dimension arc radius angPar.sPar.dir = -1; // Clockwise direction // Display parameters angPar.dPar.textPos = 0; // Auto placement angPar.dPar.textBase = 0; // Above dimension line center angPar.dPar.pl1 = 0; // First extension line visible angPar.dPar.pl2 = 0; // Second extension line visible angPar.dPar.pt1 = 1; // Arrow inside at first line angPar.dPar.pt2 = 1; // Arrow inside at second line angPar.dPar.shelfDir = 0; // No shelf p = AngDimension(&angPar); } ``` ### Response #### Success Response (200) Returns a reference to the created angular dimension object. #### Response Example ``` // Returns: reference to angular dimension object ``` ``` -------------------------------- ### Add Curves to an Imported Surface in KOMPAS-3D Source: https://context7.com/frei480/-22-sdk/llms.txt This C++ function demonstrates adding curves to an imported surface definition in KOMPAS-3D. It involves creating a SAFEARRAY of points and then using the AddCurve method within a loop to append multiple curves, each defined by a set of 3D coordinates. ```cpp void CreateImportedSurface(KompasObject& kompas) { int pointCountAll = 6; // Must be multiple of 3 (x, y, z) int curveCount = 3; double x = 50, dx = 30; double y = 50, dy = 40; double z = 0, dz = 100; int pointCount = pointCountAll / 3; // Create SAFEARRAY for points SAFEARRAYBOUND sabound[1]; sabound[0].cElements = pointCountAll; sabound[0].lLbound = 0; SAFEARRAY FAR *psa = ::SafeArrayCreate(VT_R8, 1, sabound); VARIANT v; VariantInit(&v); V_VT(&v) = VT_ARRAY | VT_R8; V_ARRAY(&v) = psa; if (kompas.m_lpDispatch) { ksDocument3D doc(kompas.ActiveDocument3D()); if (doc.m_lpDispatch) { ksPart part(doc.GetPart(pTop_Part)); if (part.m_lpDispatch) { ksEntity entity(part.NewEntity(o3d_importedSurface)); if (entity.m_lpDispatch) { ksImportedSurfaceDefinition surfDef(entity.GetDefinition()); if (surfDef.m_lpDispatch) { // Add curves with points for (int i = 0; i < curveCount; i++) { for (int j = 0; j < pointCount; j++) { long index = j * 3; double d = x + dx * i; ::SafeArrayPutElement(psa, &index, &d); index = j * 3 + 1; d = y - dy * (i % 2); ::SafeArrayPutElement(psa, &index, &d); index = j * 3 + 2; d = z + dz * j; ::SafeArrayPutElement(psa, &index, &d); } surfDef.AddCurve(v); } entity.Create(); } } } } } if (psa) ::SafeArrayDestroy(psa); } ``` -------------------------------- ### Close Document - C++ Source: https://context7.com/frei480/-22-sdk/llms.txt Closes an open KOMPAS document. It can close a specific document by its reference or the currently active document if the reference is 0. The function returns 1 on success and 0 on failure. Unsaved changes may set an error flag. ```cpp // Syntax: int CloseDocument(reference sheet) // If sheet = 0, closes current document void CloseDocumentExample(reference doc) { // Close specific document int result = CloseDocument(doc); // Close current document CloseDocument(0); // Note: If document has unsaved changes, error flag is set // Returns: 1 on success, 0 on failure } ```