The problem is that you're using the Join operation when you create each sphere so it's joining that sphere to the existing sphere(s). You need to be creating a new body for each sphere. Here's a modified version of the previous program that does that. I've created a function where I can pass in the position and radius and it will create a sphere at that location. It also modifies the names of the parameters so it's easy to find which parameters control the position of which sphere. By changing the parameters you can reposition any sphere at any location after it's been created.
Public Sub CreateRevolutions()
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
Dim points(5) As Point
Set points(0) = tg.CreatePoint(4, 0, 0)
Set points(1) = tg.CreatePoint(0, -4, 0)
Set points(2) = tg.CreatePoint(0, 4, 0)
Set points(3) = tg.CreatePoint(4, 4, 0)
Set points(4) = tg.CreatePoint(-4, 4, 0)
Dim moves(5) As MoveFeature
Dim i As Integer
For i = 0 To 4
Set moves(i) = CreateSphere(1.5, points(i))
Next
End Sub
Public Function CreateSphere(Radius As Double, Position As Point) As MoveFeature
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
Dim partDef As PartComponentDefinition
Set partDef = partDoc.ComponentDefinition
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
' Create a new sketch on the X-Y base plane.
Dim sketch As PlanarSketch
Set sketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(3))
' Draw a circle.
Dim circ As SketchCircle
Set circ = sketch.SketchCircles.AddByCenterRadius(tg.CreatePoint2d(0, 0), Radius)
' Draw a center line through the circle.
Dim lin As SketchLine
Set lin = sketch.SketchLines.AddByTwoPoints(tg.CreatePoint2d(-Radius, 0), tg.CreatePoint2d(Radius, 0))
lin.Centerline = True
' Constrain the line to circle.
Call sketch.GeometricConstraints.AddCoincident(circ.CenterSketchPoint, lin)
Call sketch.GeometricConstraints.AddCoincident(lin.StartSketchPoint, circ)
Call sketch.GeometricConstraints.AddCoincident(lin.EndSketchPoint, circ)
' Create a profile from the sketch.
Dim prof As Profile
Set prof = sketch.Profiles.AddForSolid()
' Two paths were created in the profile but we only need one (half of the circle)
' so delete one of the paths.
prof.Item(1).Delete
' Create a revolve feature.
Dim revolve As RevolveFeature
Set revolve = partDef.Features.RevolveFeatures.AddFull(prof, lin, kNewBodyOperation)
' Move it to the specified position.
Dim objColl As ObjectCollection
Set objColl = ThisApplication.TransientObjects.CreateObjectCollection
Call objColl.Add(revolve.Faces.Item(1).SurfaceBody)
Dim moveDef As MoveDefinition
Set moveDef = partDef.Features.MoveFeatures.CreateMoveDefinition(objColl)
Call moveDef.AddFreeDrag(Position.x, Position.y, Position.Z)
Set CreateSphere = partDef.Features.MoveFeatures.Add(moveDef)
' Rename the parameters to they're easily identified in the parameters dialog.
Dim freeDrag As FreeDragMoveOperation
Set freeDrag = CreateSphere.Definition.MoveOperation(1)
Dim name As String
name = CreateSphere.name & " X"
name = Replace(name, " ", "_")
freeDrag.XOffset.name = name
name = CreateSphere.name & " Y"
name = Replace(name, " ", "_")
freeDrag.YOffset.name = name
name = CreateSphere.name & " Z"
name = Replace(name, " ", "_")
freeDrag.ZOffset.name = name
End Function