Submitted by Robse-ponte on Thu, 04/22/2021 - 05:28
Forums:
Hello,
does anyone know a possibility to find out the solid that contains a flat pattern? I know how to find the component but this is not helpful. More than one body all with flat patterns (sheet metal welding part) exists in every file and i would be very happy to know if it is possible to check a flat pattern that is related to each solid.
Anyone here who had an similar problem?
Thank you and best regards
Robse
Other way
Hello, i tried to figure it out with feature to body but i wasn´t able to manage this.
A new approach would be to use the body and find the related features and filter for flat patterns. Unfortunately it does not work. I can see it finds bodies in my listwindow but the related feature is empty. Does someone knows how to use the .GetFeatures command in the right way?
Hereby my test code:
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim myPart As NXOpen.Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim myFeature As NXOpen.Features.Feature
Dim myFeatureName As String
lw.Open()
For Each myBody As NXOpen.Body In myPart.Bodies
lw.WriteLine(myBody.ToString)
myFeature = myBody.GetFeatures()(0)
myFeatureName = myFeature.Name
lw.WriteLine(myFeatureName)
Next
lw.Close()
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
Feature.Name Empty
Hello again,
I am sorry to ask again, but i do not get a name of the feature. Unfortunately there is no result from the name when i run the code below. Flat pattern seems not to be related to any solid. Is there any other way?
See code and result below.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Module Module1
Sub Main()
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim myPart As NXOpen.Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each myBody As NXOpen.Body In myPart.Bodies
lw.WriteLine(myBody.ToString)
Dim featArray() As Feature = myBody.GetFeatures()
For Each myFeature As Feature In featArray
lw.WriteLine("++" & myFeature.ToString)
lw.WriteLine("**" & myFeature.Name)
Next
Next
lw.Close()
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
Result:
Body 50514
++Tab 50883
**
Body 50521
++ExtractFace 50884
**
++FlatSolid 50885
**
Body 50508
++ExtractFace 50886
**
re: feature name
The .Name property of a feature will return the custom name that you assign to a feature. For instance, if you have "Extrude (1)" in your feature tree (part navigator),you can right click and choose "rename" and enter "base"; the feature in the part navigator will now be something like "Extrude (1) 'base'". The .Name property for this feature would return "base". If you have not renamed the feature, the .Name property will return an empty string. Instead of myFeature.Name, try myFeature.GetFeatureName; this would return "Extrude (1)" in our example.
Are you working with multiple sheet metal flat patterns in a single part file? If you have an example file that you are willing to share, please email it to info@nxjournaling.com. I don't often work with the sheet metal application, so I don't have any parts to test.
Thank you
Hello
Yes unfortunately we are working with more than one flat pattern in a file
.GetFeatureName made it. I did not realize that .Name is just the customized name.
Hereby a working example that seems to work. If someone knows a better and easier way please let me know. Code cycles through all features and its parents to find the relevant body feature and then cycles through all bodies with its features to find the corresponding links between the feature:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim FlatPatternNo As String
Dim sortList (2, 0) As String
Dim i As Integer = 0
lw.Open()
'Check all features and get parents
For Each partFeature As Features.Feature In workPart.Features
If TypeOf partFeature Is Features.FlatPattern Or TypeOf partFeature Is NXOpen.Features.ExtractFace Then
Dim ParentArray() As Features.Feature = partFeature.GetParents ()
For Each parentFeature As Features.Feature In ParentArray
If TypeOf parentFeature Is NXOpen.Features.Tab Or TypeOf parentFeature Is NXOpen.Features.ConvertToSheetmetal Or TypeOf parentFeature Is NXOpen.Features.SheetMetalFromSolid Then
'lw.WriteLine("-- " & partFeature.GetFeatureName)
'lw.WriteLine("## " & parentFeature.GetFeatureName)
'lw.WriteLine("oo " & parentFeature.GetType.ToString)
'lw.WriteLine("%% " &FlatPatternNo)
FlatPatternNo = Regex.Match(partFeature.GetFeatureName, "\(.*\)").Value
ReDim Preserve sortlist(2, i)
sortList (0 , i) = "Flat Pattern " & FlatPatternNo
sortList (1 , i) = parentFeature.GetFeatureName
i= i + 1
End If
Next
End If
Next
lw.WriteLine("")
Dim ct As Integer = sortList.GetLength(1)-1 'To find out dimension on array'
'Check all bodies and its features
For Each myBody As NXOpen.Body In workPart.Bodies
Dim FeatureArray() As Features.Feature= myBody.GetFeatures()
For Each myFeature As Features.Feature In FeatureArray
If TypeOf myFeature Is NXOpen.Features.Tab Or TypeOf myFeature Is NXOpen.Features.ConvertToSheetmetal Or TypeOf myFeature Is NXOpen.Features.SheetMetalFromSolid Then
'lw.WriteLine("++ " & mybody.ToString)
'lw.WriteLine("** " & myFeature.GetFeatureName)
'lw.WriteLine("xx " & myFeature.GetType.ToString)
For i = 0 To ct
If sortList (1 , i) = myFeature.GetFeatureName Then
sortList (2 , i) = mybody.ToString
' Do something with body...
End If
Next
End If
Next
Next
'Highlight Result
For i = 0 To ct
lw.WriteLine(sortList (0 , i) & " ; " & sortList (1 , i) & " ; " & sortList (2 , i) )
Next
lw.Close()
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