×
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

NX VB

NX VB

(OP)
Hello,

In a little VB program, I would like to count the number of sketches in my active part, for move each sketch in his layer (skt_000 in layer 256, skt_001 in layer 255 etc...).
In my part, each sketch have the name : skt_000 / skt_001 / ... / skt_0xx.

Thank you very much for your support,

Sébastien Tytgat

RE: NX VB

Even for journals it is important to know the nx version. Below are the journals for this. The first is suitable for NX6 or NX7.5. The second is for NX8.

CODE --> NX7.5

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

Module organize_sketches
    Dim s As Session = Session.GetSession()
    Dim workPart As Part = S.Parts.Work
    Dim dispPart As Part = s.Parts.Display
    Dim lw As ListingWindow = s.ListingWindow
    Dim i As Integer
    Dim objArray(0) As DisplayableObject
    Sub Main()
        ' Get all sketches
        Dim allsketches As SketchCollection = workPart.Sketches
        ' Get the sketch feature name and then move the sketch to the approriate layer
        Dim sketchname As String = Nothing
        Dim sketchnumberstring As String = Nothing
        Dim sketchnumber As Integer = Nothing
        Dim length1 As Integer = Nothing
        Dim layernumber As Integer = Nothing
        Dim objArray(0) As DisplayableObject
        For Each sk As Sketch In allsketches
            sketchname = sk.Name.ToString
            length1 = Len(sketchname)
            sketchnumberstring = sketchname.Substring(length1 - 3, 3)
            Try
                sketchnumber = CInt(sketchnumberstring) ' Get the sketch number as an integer
                layernumber = 256 - sketchnumber ' The destination layer number
                objArray(0) = sk
                workPart.Layers.MoveDisplayableObjects(layernumber, objArray) ' Move the sketch
            Catch ex As Exception
                MsgBox("Invalid sketch name: " & sketchname)
            End Try
        Next
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module 

CODE --> NX8

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

Module organize_file
    Dim s As Session = Session.GetSession()
    Dim workPart As Part = S.Parts.Work
    Dim dispPart As Part = s.Parts.Display
    Dim lw As ListingWindow = s.ListingWindow
    Dim i As Integer
    Dim objArray(0) As DisplayableObject
    Sub Main()
        ' Get all sketches
        Dim allsketches As SketchCollection = workPart.Sketches
        ' Get the sketch feature name and then move the sketch to the approriate layer
        Dim sketchname As String = Nothing
        Dim sketchnumberstring As String = Nothing
        Dim sketchnumber As Integer = Nothing
        Dim skfeature As Feature
        Dim index1 As Integer = Nothing
        Dim layernumber As Integer = Nothing
        Dim objArray(0) As DisplayableObject
        For Each sk As Sketch In allsketches
            skfeature = sk.Feature ' Get the sketch feature
            sketchname = skfeature.GetFeatureName ' Get the sketch feature name
            Try
                index1 = sketchname.IndexOf(":") ' To extract the number portion
                sketchnumberstring = sketchname.Substring(index1 - 3, 3) ' To extract the number portion
                sketchnumber = CInt(sketchnumberstring) ' Get the sketch number as an integer
                layernumber = 256 - sketchnumber ' The destination layer number
                objArray(0) = sk
                workPart.Layers.MoveDisplayableObjects(layernumber, objArray) ' Move the sketch
            Catch ex As Exception
                MsgBox("Invalid sketch name: " & sketchname)
            End Try
        Next
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module 

Frank Swinkels

RE: NX VB

(OP)
Dear all,

Thanks a lot for your quick answers and thanks for your solutions.
Best regards,

RE: NX VB

(OP)
Hi again,

i would like to continue my program by selected all sheets bodies and move them in a specific layer.
i can selected all bodies (volume) but not specifics sheets (or surfaces).
How can i do?
Please find in attached file my code (Module1.vb).
My Nx version is 7.5

Thanks for your support and best regards,

Sébastien Tytgat

RE: NX VB

One way is to iterate through the part's body collection, which contains both sheet and solid bodies. The body class has .IsSheetBody and .IsSolidBody properties to distinguish sheets from solids. Here is some example code:

CODE

Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim lw As ListingWindow = theSession.ListingWindow  
        lw.Open()  

        Dim partBodies() As Body = workPart.Bodies.ToArray  
        For Each partBody As Body In partBodies  
            If partBody.IsSheetBody Then  
                lw.WriteLine("Sheet body, layer: " & partBody.Layer)  
            Else  
                lw.WriteLine("Solid body, layer: " & partBody.Layer)  
            End If  
        Next  

        lw.Close()  

    End Sub  


    Public Function GetUnloadOption(ByVal dummy As String) As Integer  

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

    End Function  

End Module 

www.nxjournaling.com

RE: NX VB

(OP)
Thanks a lot!

BR,

Sébastien Tytgat

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