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
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
Have a look at thread561-326361: Using a Journal to organize the file it might give you some ideas.
www.nxjournaling.com
RE: NX VB
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 ModuleCODE --> 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 ModuleFrank Swinkels
RE: NX VB
Thanks a lot for your quick answers and thanks for your solutions.
Best regards,
RE: NX VB
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
CODE
www.nxjournaling.com
RE: NX VB
BR,
Sébastien Tytgat