Exercise 2 - Create a shape
Updated : 20 November 2024
In this exercise, you will learn how to create a shape into a part document.
Note
After downloading the Automation_SelfLearning solution from GitHub, you will find the whole example code for this exercise in the Exercise_2 project.
- Set up your environment.
- Launch Visual Studio
- Open the project Automation_SelfLearning project to begin coding your own application. This project should contain your work from the first exercise. If not, you can get code directly from Exercise_1 project.
Design the Application Interface
- Open the design form of your application. This interface already contains a TextBox and a Button.
Add a Button to the form as shown below:
- Add a Button Click Event
- Double-click the button on the form to generate a click event handler.
- Implement the click event method to create a shape into a part document.
Important
To achieve this exercise, you will need more information about Documents and about Elements
Coding Steps
- Ensure the following functionalities are included in your method:
- Find or create target project (cf. Exercise 1)
Into the target project, create a part document.
Note
You will need to know document file extension to achieve this task. To retrieve the extension associated with a TopSolid document, you must first create the document in TopSolid, then select it in the project tree. Next, use the "Document Type..." command from the "Tools" menu in the context menu.
Note that TopSolid must be launched with the -a command line option, as this feature is only available in advanced mode.
Then, create a sketch into this document and add a rectangular profile to this sketch.
Important
To achieve this part of the exercise, you will need more information about Sketches and about Elements
Extrude the sketch to get a shape.
Important
To achieve this exercise, you will need more information about Shapes
Check out the method CreateExtrudedShape
from IShapes
interface in the API reference.
Test your application:
- From the Debug menu, select Start Debugging to run your project.
- Click the button on your form to execute the functionality
Self-Learning exercises table of content:
- Exercise 1 - Get or create a TopSolid Project
- Exercise 3 - Create an assembly
- Exercise 4 - Export / Import a document using STL format