Join Separate
This example provides information on joining and separating bodies. Three bodies are created. We use surfaces in this example
First we join Surface 1 and Surface 2, which creates Surface 4.
Then we join all three surfaces (1, 2 and 3), which creates Surface 5.
Next, we join all three surfaces again, but this time we separate the disjunct lumps, which results in two surfaces (Surface 6). One surface is the same as Surface 1, and the other is Surface 2 and 3 combined. In the last step we take Surface 5 and separate the disjunct lumps, which gives the same result as when we created Surface 6.
If you go to the Modeling browser and expand My_Surfaces, you can see all the different bodies. It might be easier to see the different bodies if you first makes them invisible (the bodies, not the part), and then make them visible one at a time.
Use this procedure to join and separate the bodies.
Create parts and bodies.
Place (Transform) the bodies.
Join b1 and b2.
Join the first element in b4 with b3.
Separate the first element in b7.
Solution
Create parts and bodies.
Part p = new Part(); p.Name = "My_Surfaces"; station.GraphicComponents.Add(p); Body b1 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1); b1.Name = "Surface 1"; p.Bodies.Add(b1); Body b2 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1); b2.Name = "Surface 2"; p.Bodies.Add(b2); Body b3 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1); b3.Name = "Surface 3"; p.Bodies.Add(b3);
Place(Transform) the bodies.
b1.Transform.X = 0; b1.Transform.Y = 0; b2.Transform.X = 2; b2.Transform.Y = 0; b3.Transform.X = 2; b3.Transform.Y = 1;
Join b1 and b2.
Note
When the second parameter is false, only one element is created. This creates a new array b4, with one element, created from b1 and b2.
Body[] b4 = b1.Join(b2, false); foreach (Body b in b4) { b.Name = "Surface 4: Surface 1 joined with Surface 2."; p.Bodies.Add(b); }
Join the first element in b4 with b3.
Note
This creates a new array b7, with one element, created from b3 and the first element in b4.
Body[] b7 = b4[0].Join(b3, false); foreach (Body b in b7) { b.Name = "Surface 5: Surface 1 joined with Surface 2 and Surface 3. Not separated."; p.Bodies.Add(b); }
Join the first element in b4 with b3.
Note
The elements in b5 is created from each disjunct piece in b3 and the first element in b4.
Body[] b5 = b4[0].Join(b3, true); foreach (Body b in b5) { b.Name = "Surface 6: Surface 1 joined with Surface 2" + "and Surface 3. Disjunct lumps separated."; p.Bodies.Add(b); }
Separate the first element in b7.
Note
Each disjunct piece in the first element in b7 creates a new element in b8.
Body[] b8 = b7[0].Separate(); foreach (Body b in b8) { b.Name = "Surface 7: Disjunct lumps separated from Surface 5."; p.Bodies.Add(b); }
Example
This example provides information on joining and separating bodies.
public void BodyJoinSeparate()
{
NewStation();
Project.UndoContext.BeginUndoStep("BodyJoinSeparate");
try
{
Station station = Station.ActiveStation;
// Create parts and bodies.
Part p = new Part();
p.Name = "My_Surfaces";
station.GraphicComponents.Add(p);
Body b1 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1);
b1.Name = "Surface 1";
p.Bodies.Add(b1);
Body b2 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1);
b2.Name = "Surface 2";
p.Bodies.Add(b2);
Body b3 = Body.CreateSurfaceRectangle(Matrix4.Identity, 1, 1);
b3.Name = "Surface 3";
p.Bodies.Add(b3);
// Place the bodies.
b1.Transform.X = 0;
b1.Transform.Y = 0;
b2.Transform.X = 2;
b2.Transform.Y = 0;
b3.Transform.X = 2;
b3.Transform.Y = 1;
// Join b1 and b2.
// When the second parameter is false, only one element is created.
// This creates a new array b4, with one element, created from b1 and b2.
Body[] b4 = b1.Join(b2, false);
foreach (Body b in b4)
{
b.Name = "Surface 4: Surface 1 joined with Surface 2.";
p.Bodies.Add(b);
}
// Join the first element in b4 with b3.
// This creates a new array b7, with one element, created from b3 and the first element in b4.
Body[] b7 = b4[0].Join(b3, false);
foreach (Body b in b7)
{
b.Name =
"Surface 5: Surface 1 joined with Surface 2 and Surface 3. Not separated.";
p.Bodies.Add(b);
}
// Join the first element in b4 with b3.
// The elements in b5 is created from each disjunct piece in b3 and the first element in b4.
Body[] b5 = b4[0].Join(b3, true);
foreach (Body b in b5)
{
b.Name = "Surface 6: Surface 1 joined with Surface 2" +
"and Surface 3. Disjunct lumps separated.";
p.Bodies.Add(b);
}
// Separate the first element in b7.
// Each disjunct piece in the first element in b7 creates a new element in b8.
Body[] b8 = b7[0].Separate();
foreach (Body b in b8)
{
b.Name =
"Surface 7: Disjunct lumps separated from Surface 5.";
p.Bodies.Add(b);
}
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.