Creating Parametric Objects in nanoCAD Mechanica Part 3

Create implementation. Add constraints.

In the previous part, we’ve seen how to work with the nanoCAD ScriptMaster of the MechWizard to create parametric objects. We’ve also learned how to add parameters to the created library object. The main benefit of parameterizing objects lies in the creation of implementations and the inclusion of external constraints with other library objects for designing intelligent assemblies managed through object parameters.

In this part, we will use the nanoCAD MechWizard toolbar, which is specifically designed for creating comprehensive parametric objects and effectively managing the addition of constraints.

Navigate to the User Folder in the Library folder list, then right-click (RMB) on the newly created object Washer-10H205-00-414-01. From the context menu, choose the option "Open with ScriptMaster" (refer to Fig. 1).


Fig. 1

Right-click on the Implementations branch and select Add Implementation from the context menu (Fig. 2). Next, let's create a view based on the first implementation. Right-click on the new Implementation that appears in the right part of the MechWizard window, call the context menu and select Parametric recognize view. Use the same geometry as the sketch for the first implementation.

Fig. 2

In this case, we will limit ourselves to only one view (see part 1, "Preparing the object's geometry. Creating a library element" fig. 5). Now as the geometry of the object has been added to the new implementation, let's make some changes to the script of the object.

For easy navigation, expand the Methods branch, and then expand the Event Handler. We will see a list of all the main functions used in the script opened. To generate a new implementation, the following handlers will be required:

ActHeader, OnInitialization, OnMakeParameters, OnDialog.

In ActHeader (See Fig. 3), the Protected section, set the following parameters:

(seted, B1, B2, b1, b2);


Fig. 3

In OnInitialization (Fig. 4), assign values to b and B to add new parameters as follows:

B1 = 6; B2 = 4; b1 = 3; b2 = 2

Fig. 4

In OnMakeParameters, let's add the following code, passing certain variable values to the implementations (Fig. 5):

if (strDesignName == “Implementation1”) {b=b1};
if (strDesignName == “Implementation2”) {b=b2};
if (strDesignName == “Implementation1”) {B=B1};
if (strDesignName == “Implementation2”) {B=B2};

Fig. 5

To display all implementations in the insertion dialog, add the following to the OnDialog (Fig. 6):

VIDS, strDesignName, “All”,


Fig. 6

Save the changes and close the MechWizard. Let's check the script. Insert the modified washer from the object library into the model space. Now two implementations will be available in the insert window for the Washer-10H205-00-414-01 (Fig. 7).


Fig. 7

Select the second implementation and click OK. The width of the washer will change as per the parameter values specified in OnInitialization.

Now, let’s create constraints so we could use the new object in a parametric assembly. These constraints should be specified in the OnConnect handler. In the object Washer, within the Sample Folder of the library the required constraints are already defined. (Follow the process of inserting this object to the library as described in part 2: "Working with the script of an object. Script Wizard".

Open this object in the MechWizard, copy part of the script describing the OnConnect function, and paste this code into OnConnect function of the Washer-10H205-00-414-01 (Fig. 8).

Fig. 8

The first part of this script creates an assembly constraint between the previously added object and the bearing in such a way that when the bearing is selected the working plane of the object (in this case, the end of the washer) will coincide with the nearest plane of the bearing. The washer will be displayed on the same side as the bearing chosen on the median plane.

The second part describes the constraint of the shaft segment and the inner (landing) surface of the washer, the diameter of which is indicated by the variable "d". Once you specify the surface, you can move the inserted object to any point along the axis.

After inserting the code into the new object (Washer-10H205-00-414-01), let's navigate to the Event Handlers branch in BeforeConnect. This handler allows displaying a message prompt about the necessary actions after adding the object to the model space. Add the following expression after ResetLastConstraint();

if(rPart == 0) {strPromt = “Select bearing or shaft stage”};

In ActHeader, let's add a variable NSelect with a value of 2, which determines the number of object queries during insertion. If necessary, you can control the seating diameter of the washer by selecting the desired shaft diameter after specifying the bearing. Save changes and close the MechWizard.

To test the final object, let's take a simple assembly created from the standard objects of the nanoCAD Mechanica library. You can download the assembly file with the link:
Open the assembly and add the new object (Washer-10H205-00-414-01) to it. An informational message, which was specified in the BeforeConnect handler, will appear. In the command line, the program will display the prompt: "Select insertion point." It is necessary to indicate the bearing in such a way that the washer is positioned to the left of it (Fig. 9).


Fig. 9

Let’s fix the position with a mouse click. With a second click, select the shaft step on which the washer is installed to adjust the internal diameter. The familiar insertion dialog window will appear, where we can change parameter values, select types, and modify implementations. Select the Implementation2, and press Apply. The width of the washer will change in accordance with the specified parameters while preserving constraints with the bearing and shaft (Fig. 10).

Fig. 10

Click OK to confirm the changes. In the future, if you need to change the implementation, you can open the insertion window with a double click on the object (Washer-10H205-00-414-01).

Now let's move on to constraint management.

The bearing used here is a parametric assembly — all objects are connected by specific constraints, so if, for example, the sizes of the bearings are changed, the dimensions of all interconnected components will also change.

Use the Add Constraints command to create or delete various constraints between the parameters of various library objects, including custom ones.

The standard library objects used in this example already have all the necessary constraints. For a custom object, such constraints have not been defined yet, but it is easy to add them. For example, let's create a constraint between the washer and the cup diameters, which will help avoid errors related to component overlap when significantly reducing the outer diameters of the bearings and, consequently, reducing the size of the cup.

To run the command, go to Mechanica in the menu, then click Standard parts, and select the Add constraint command (Fig. 11).

Fig. 11

In the opened window, click on the Child Object icon and select the washer. Then, we choose the Cup component as the Parent object. Expand the parameter branches of both objects and double-click on the D diameter for the washer and the Dv diameter for the cup. The parameters will be added to the input field below. Mathematical expressions can be entered on the right side of the equation. Add "-0.25" after the parameter symbol, thus providing a gap between the components. Press the Save Constraints button and close the window by clicking OK (Fig. 12). The made changes will be displayed on the screen.

Fig. 12

To verify the functionality of the created constraint, let's change the parameters of the bearings. To do this, enter the object insertion dialog and modify the outer diameter from 85 to 75 or 100, then press OK. The dimensions of the bearings and, consequently, the diameter of the cup will change, but the diameter of the cup's hole will remain the same, preserving the specified gap size (Fig. 13).

Fig. 13

This way, you can link any parameters of different parts and make changes to the created constraints using mathematical expressions.

Finally, for clarity and ease of visual identification, you can use the MechWizard to add an image or a 3D model to the object preview window.

To do this, while in the MechWizard, right-click on the topmost element in the tree and select one of the first two options from the context menu.
In our case, a 3D model of the washer has been prepared (which can be downloaded here:, so select Set Object Preview (Fig. 14). The corresponding model must be open in the modeling space. Click on the model, press Enter, and the washer model will be displayed in the preview window.


Fig. 14

Save and close the MechWizard. To display the model in the preview window, click the Refresh Refresh.jpg button on the toolbar of the Library tab. To rotate the model in the preview window, hover the cursor over it and drag it while holding the mouse button (Fig. 15).

Fig. 15

We have explored some of the features of nanoCAD Mechanica related to the creation and manipulation of parametric objects. We’ve learned about the process and nuances of preparing geometry for creating parametric elements and adding new library objects. We’ve seen how to import files and connect them, as well as analyzed the methods of parameterizing library objects using the Script Master and non-parametric objects. We have mastered the process of adding constraints for custom parts to work with parametric assemblies.

No doubt, parametrization is, in a sense, a departure from traditional techniques, but when applied skillfully, it significantly speeds up the design process and improves its quality. As a result, parametric modeling is slowly but steadily becoming the new standard in design.

In nanoCAD Mechanica development program, the improvement of its parametric modeling tools has already become one of the main objectives.
We collect Cookies
We use cookies to ensure that we give you the best experience on our website. By clicking “Accept”, you agree to our website’s cookie use as described in our Privacy Statement.