My First Model
In this tutorial, you will learn how to create a first simple model with the Solid API. First, we will start with a simple box. Then, to get an idea about what's possible with the Solid API, we're going to make the model more and more complex.
Let's follow these steps:
- Create a simple box
- Modify model by adding more features
- Make it a real example
- Make the model configurable
#
1. Create a simple boxFirst, you must create a new code environment where you will make your first example.
- Create a copy of templateCreator.ts in the solid folder and name it, for example, cube.ts
- You will now have an empty create method where you can put code into it.
- Create a simple box with length = 32, width = 16 and height = 9.6
- Return the id of the box
- As result you will see a simple colored box
💡 Tip: Length, width and height of the box relates to x-, y- and z-axis in global coordinate system.
#
2. Modify model by adding more featuresThere are many features we can use to modify this simple cube. First, let's make the cube hollow at the bottom with a defined thickness. Then, follow the next steps to get the result.
- First of all, create some variables for width, height, length, and thickness
- Create another box that is a bit smaller than the first one
- Move the new box to the correct position
- Create a boolean operation, in that case, a subtraction, to subtract the second box from the first one
- As result you will see a red box which is hollow at the bottom
#
3. Make it a real exampleIn the previous chapter, we learned that we could use features to modify our model. We used moveTo() and subtract(), but there are many more to explore. Visit Solid API for a list of all methods we can use.
At the moment, it's only a hollow box; let's add some more features to make it a real example. Add the following code to your template.
Do you have any idea what the code will create? Then, copy the code to the template and see what you get on the screen!
#
4. Make the model configurableIf the result of the last chapter looks like a lego brick, well done! You've created your first real example by code. The next step will be to make the model configurable. Currently, we're only able to create a brick of the size 2 x 2. So what do we need to add to the code to make various bricks? Follow the next steps to create a configurable lego brick:
- Add rows and columns as new variables to the code. With these variables, we will control the size of the brick.
- Refactor existing variables. Make them depend on each other.
Now, the size of the brick (width, length) depends on the number of rows and columns. The code section where the body is built, is fine like it is. No changes are needed. We need to update now the dots and tubes.
- Create a loop to iterate over the number of columns
- Within the loop create another loop to iterate over the number of rows
- Each dot will be moved a specific distance and united with the box
- Do the same with the tubes
That's all! You can now change row and column to get an individual lego brick. Of course, we could extend the brick even more. But this will be fine to get the idea of how code could help us make models individually.
💡 Tip: You can export the model as stp file (not available in the free version!) or in our native file format ofb.