Skip to main content

My First Assembly

In this chapter, we're going to create our first assembly. In this example, we will use the flange part from the chapter before to create an assembly. We will add the flange twice to the assembly and add a bolt and a nut. Both parts come from a library and already contain coordinate systems for assembling.

So let's start coding!

  1. Create the root assembly and load products
  2. Add the products to the assembly
  3. Adding constraints to the nodes

1. Create the root assembly and load products#

First, we create an empty assembly; it will be the root assembly. As explained in the beginning, we will add the flange twice, then a bolt and a nut. So we need to load these products into the assembly as arraybuffer. The bolt and the nut can be found in buerli-examples in the folder client/src/resources/history/Flange. Next, add the flange part saved in native file format to this directory. Use the following snippet in your template.

// Create the root assembly
const root = await api.createRootAssembly('FlangeAsm')
// Load all needed products
const [flange] = await api.loadProduct(flangeAB, 'ofb')
const [bolt] = await api.loadProduct(boltAB, 'ofb')
const [nut] = await api.loadProduct(nutAB, 'ofb')

You won't see anything on the screen; we just loaded the products but didn't add any instance yet. So let's go to the next chapter.


2. Add the products to the assembly#

Next, we add two nodes or instances of the flange, then a bolt node, and finally a nut node to the assembly. We then retrieve the necessary work coordinate systems (WCS) from the parts to connect the nodes using 3d constraints. Coordinate systems, also called mates, are used for positioning nodes in the assembly relative to each other. Copy the following code snippet to your template.

if (flange && bolt && nut) {
// Get all necessary work coordinate systems
const [wcsCenter] = await api.getWorkGeometry(flange, CCClasses.CCWorkCoordSystem, 'WCSCenter')
const [wcsHole1Top] = await api.getWorkGeometry(flange, CCClasses.CCWorkCoordSystem, 'WCSBoltHoleTop')
const [wcsBoltHead] = await api.getWorkGeometry(bolt, CCClasses.CCWorkCoordSystem, 'WCSHead')
const [wcsNut] = await api.getWorkGeometry(nut, CCClasses.CCWorkCoordSystem, 'WCSNut')
// Add the products as nodes to the root assembly
const [flange1Node, flange2Node, boltNode, nutNode] = await api.addNodes(
{
productId: flange,
ownerId: root,
transformation: [origin, xDir, yDir],
},
{
productId: flange,
ownerId: root,
transformation: [origin, xDir, yDir],
},
{
productId: bolt,
ownerId: root,
transformation: [origin, xDir, yDir],
},
{
productId: nut,
ownerId: root,
transformation: [origin, xDir, yDir],
},
)
}
return root

As result you should see the following graphics. All nodes have been added to the origin. We even can't see the two flanges, because they have exactly the same position.

drawing

Added all necessary nodes to assemble

As you probably expect, we have to fix the postions by adding constraints to the nodes.


3. Adding constraints to the nodes#

Depending on the constraints we set, the nodes will have different degrees of freedom. In our example we will simply use the fastened origin and the fastened constraint. We will follow the next steps to constrain the whole assembly.

  • Create a fastened origin constraint to fasten the first flange to the origin
await api.createFastenedOriginConstraint(
root,
{
matePath: [flange1Node],
wcsId: wcsCenter,
flip: FlipType.FLIP_Z,
reoriented: ReorientedType.REORIENTED_0,
}, 0, 0, 0, 'FOCFlange1',
)
  • Create a fastened constraint between the first and the second flange
await api.createFastenedConstraint(
root,
{
matePath: [flange1Node],
wcsId: wcsCenter,
flip: FlipType.FLIP_Z,
reoriented: ReorientedType.REORIENTED_0,
},
{
matePath: [flange2Node],
wcsId: wcsCenter,
flip: FlipType.FLIP_Z_INV,
reoriented: ReorientedType.REORIENTED_180,
},
0,0,0, 'FCFlange1Flange2'
)
  • Create a fastened constraint between the bolt and the first flange
await api.createFastenedConstraint(
root,
{
matePath: [flange1Node],
wcsId: wcsHole1Top,
flip: FlipType.FLIP_Z,
reoriented: ReorientedType.REORIENTED_0,
},
{
matePath: [boltNode],
wcsId: wcsBoltHead,
flip: FlipType.FLIP_Z,
reoriented: ReorientedType.REORIENTED_0,
},
0,0,0, 'FCFlange1Bolt'
)
  • Create a fastened constraint between the nut and the second flange
await api.createFastenedConstraint(
root,
{
matePath: [flange2Node],
wcsId: wcsHole1Top,
flip: FlipType.FLIP_Z,
reoriented: ReorientedType.REORIENTED_0,
},
{
matePath: [nutNode],
wcsId: wcsNut,
flip: FlipType.FLIP_Z_INV,
reoriented: ReorientedType.REORIENTED_0,
},
0,0,0, 'FCFlange2Nut'
)

Now we should have an assembly which is fully constrained. Save the assembly like we did with the part and open it in buerligons to see what we have created.

drawing

Assembled flange