×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

creating multiple spheres on imported coordinates
2

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

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

RE: creating multiple spheres on imported coordinates

(OP)
I'll give it a try, I'm not really experienced with Unigraphics.
Thanks for the help so far.

Sander

RE: creating multiple spheres on imported coordinates

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

/ Tomas

RE: creating multiple spheres on imported coordinates

(OP)
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

RE: creating multiple spheres on imported coordinates

(OP)
@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

 

RE: creating multiple spheres on imported coordinates

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

RE: creating multiple spheres on imported coordinates

(OP)
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.  

RE: creating multiple spheres on imported coordinates

(OP)
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.

RE: creating multiple spheres on imported coordinates

Could be a .net cultureinfo error, try replacing "sphereBuilder1.Diameter.RightHandSide = dia1.ToString" with "sphereBuilder1.Diameter.RightHandSide = dia1.ToString(System.Globalization.CultureInfo.InvariantCulture)"

 

RE: creating multiple spheres on imported coordinates

(OP)
Unfortunately that doesn't solve the problem.  

RE: creating multiple spheres on imported coordinates

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

RE: creating multiple spheres on imported coordinates

(OP)
Yes, that worked. Thank you very much!

RE: creating multiple spheres on imported coordinates

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

RE: creating multiple spheres on imported coordinates

(OP)
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.  

 

RE: creating multiple spheres on imported coordinates

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources