Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating multiple spheres on imported coordinates 2

Status
Not open for further replies.

webbier

Mechanical
Jan 30, 2012
9
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?
 
Replies continue below

Recommended for you

Below is a journal for creating spheres centered on al point objects in the display part.

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
 
I'll give it a try, I'm not really experienced with Unigraphics.
Thanks for the help so far.

Sander
 
May i ask why you want to create spheres on random points ?

/ Tomas
 
I want to analyse the mechanical behavior of a polymer matrix filled with filler particles. When the material is created for experiments the fillers will be randomly distributed throughout the matrix. Therefore the spheres have to be randomly distributed in the model as well.

Sander
 
@FrankSwinkels

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

 
Yes you need to run this on NX6 or later. I have tested the journal on NX6 and NX7.5. I am not sure but the earlier NX may still have the sphere as a non-feaure primative. If that was so it would error out as you described it. It may also be that spheres were not supported by journalling in NX5.

Frank Swinkels
 
Yes, that did the trick. Thank you very much.

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.
 
I tried to change the 'Double' entries to 'Decimal', but that doesn't seem to work. For example an entry of 1.5 for the diameter is seen as 15.
 
Could be a .net cultureinfo error, try replacing "sphereBuilder1.Diameter.RightHandSide = dia1.ToString" with "sphereBuilder1.Diameter.RightHandSide = dia1.ToString(System.Globalization.CultureInfo.InvariantCulture)"

 
Unfortunately that doesn't solve the problem.
 
Okay try this then

Code:
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
    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
 
Yes, that worked. Thank you very much!
 
Just for my benefit and education when I run my original program/journal and entered 0.05 I obtained the correct spheres. What were you doing that caused you not to get the spheres?

Frank Swinkels
 
I don't know. I got spheres, but the diameter was the first non-zero number in the number I entered for the diameter. So 0.1 became 1 and 0.10 became 10. For the rest I didn't change anything, just ran your script.

 
It has to do with how .net formats numbers for different regions. Usually "." are turned into "," by the toString() method which is not something NX likes. Thus the need for system.globalization class.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor