creating multiple spheres on imported coordinates
creating multiple spheres on imported coordinates
(OP)
I have a box filled with (randomly generated) points. On these points i want to create spheres with a constant radius. I can do so by the 'create a sphere' method, but I can't select more than one point. Since I have over a hundred points in my box it is going to be time consuming to add all the spheres seperately. Is there a way to create all these spheres at once from the different points?





RE: creating multiple spheres on imported coordinates
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module Module1
Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim disppart As Part = s.Parts.Display
Sub Main()
Dim pnts As PointCollection = disppart.Points
Dim dia1 As Double = NXInputBox.GetInputNumber("Enter Sphere Diameter")
For Each pnt As Point In pnts
createSphere(pnt, dia1)
Next
End Sub
Public Sub createSphere(ByVal pnt As Point, ByVal dia1 As Double)
Dim nullFeatures_Sphere As Features.Sphere = Nothing
Dim sphereBuilder1 As Features.SphereBuilder
sphereBuilder1 = disppart.Features.CreateSphereBuilder(nullFeatures_Sphere)
sphereBuilder1.CenterPoint = pnt
sphereBuilder1.Diameter.RightHandSide = dia1.ToString
Dim nXObject1 As NXObject
nXObject1 = sphereBuilder1.Commit()
sphereBuilder1.Destroy()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Hope it helps
Frank Swinkels
RE: creating multiple spheres on imported coordinates
Thanks for the help so far.
Sander
RE: creating multiple spheres on imported coordinates
/ Tomas
RE: creating multiple spheres on imported coordinates
Sander
RE: creating multiple spheres on imported coordinates
your script gives me some errors when I run it. I don't know if there is anything that I should change to make it work with my file.
The errors I get are:
Dim nullFeatures_Sphere As Features.Sphere = Nothing
>>Type 'Features.Sphere' is not defined
Dim sphereBuilder1 As Features.SphereBuilder
>>Type 'Features.SphereBuilder' is not defined
sphereBuilder1 = disppart.Features.CreateSphereBuilder(nullFeatures_Sphere)
>>'CreateSphereBuilder' is not a member of 'NXOpen.Features.FeatureCollection'
I'm running NX5 if that makes any difference for the scripting. The newest version I could install here at the university is NX7.5.
Sander
RE: creating multiple spheres on imported coordinates
Frank Swinkels
RE: creating multiple spheres on imported coordinates
One last question though. Doesn't the script work with decimal numbers? My box has dimensions 1x1x1 mm and I want my spheres to be 0.05 mm. However when I enter that into the script the spheres get diameter 5 mm, so it doesn't seem to read the decimal. When I upscale the entire model to 100 mm and insert sphere diameters of 1 to 5 mm it works perfectly.
RE: creating multiple spheres on imported coordinates
RE: creating multiple spheres on imported coordinates
RE: creating multiple spheres on imported coordinates
RE: creating multiple spheres on imported coordinates
CODE
Imports System
Imports NXOpen
Imports NXOpenUI
Module Module1
Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim disppart As Part = s.Parts.Display
Dim USculture As system.globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
Sub Main()
Dim pnts As PointCollection = disppart.Points
Dim dia1 as Double = 0.0
while dia1 <= 0
NXInputBox.ParseInputNumber("Input sphere Diameter", "Diameter", 0.05, system.globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentCulture, dia1)
end while
For Each pnt As Point In pnts
createSphere(pnt, dia1)
Next
End Sub
Public Sub createSphere(ByVal pnt As Point, ByVal dia1 As Double)
Dim nullFeatures_Sphere As Features.Sphere = Nothing
Dim sphereBuilder1 As Features.SphereBuilder
sphereBuilder1 = disppart.Features.CreateSphereBuilder(nullFeatures_Sphere)
sphereBuilder1.CenterPoint = pnt
sphereBuilder1.Diameter.RightHandSide = dia1.ToString(USculture)
Dim nXObject1 As NXObject
nXObject1 = sphereBuilder1.Commit()
sphereBuilder1.Destroy()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
RE: creating multiple spheres on imported coordinates
RE: creating multiple spheres on imported coordinates
Frank Swinkels
RE: creating multiple spheres on imported coordinates
RE: creating multiple spheres on imported coordinates