Extract positions of pattern feature

Hello,

I need to extract all positions in the pattern general of a linked body.
The following code not working, the section1 have not information of linked body's.
have you an idea of the good way :).
Sorry for my bad english

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

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 featArray() As Feature = workPart.Features.GetFeatures()

For Each myFeature As Feature In featArray
lw.WriteLine("Feature: " & myFeature.FeatureType.ToString)
If myFeature.FeatureType = "Pattern Feature" Then

Dim pattfeaturebuilder As PatternFeatureBuilder = workPart.Features.CreatePatternFeatureBuilder(myFeature)
Dim section1 As NXOpen.Section
section1 = pattfeaturebuilder.PatternService.GeneralDefinition.ToPoints

Do you mean that you have a pattern of linked bodies or that the linked body definition uses a pattern feature?

If you have a pattern of linked bodies, you will need to query the part (usually an assembly) that has the pattern feature.

If the linked body contains a feature pattern, you will need to query the part that the linked body is based on to find the pattern feature. The linked body itself will not contain any features.

Hello NXJournaling,

Thank you for your response, I have a "general Pattern" includes some linked bodies , my question is "where are located data of each component of "general pattern", is it in the PatternFeatureBuilder or Patterservices ? or somewhere else ?...

Thank you in advance if you have a clued, because I am lost :).

Regards

Do you want to get references to the bodies created by the pattern? If so, it appears that you can get them from the pattern feature. I don't have example code, but I'd try .GetAllContainedFeatures() and .GetAssociatedBodies.

If you want to get the pattern definition, it appears that you can get it through the pattern feature builder's .PatternService property.

Yes, you are right :). I want the "get reference" for each position setting in the spreadsheet

You can get the bodies with the .GetAssociatedBodies method of the pattern feature object.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")

lw.Open()

For Each tempFeat As Features.Feature In theSession.Parts.Work.Features

If TypeOf (tempFeat) Is Features.PatternFeature Then
Dim patternFeat As Features.PatternFeature = tempFeat
Dim patternBodies() As Body = patternFeat.GetAssociatedBodies

lw.WriteLine("number of bodies: " & patternBodies.Length.ToString)

End If

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

Hello,

Thank you for your help, your code is much better than mine,

Dim featArray() As Feature = workPart.Features.GetFeatures()

For Each myFeature As Feature In featArray
If myFeature.FeatureType = "Instance Feature" Then
Dim instbuil As InstanceFeatureBuilder = workPart.Features.CreateInstanceFeatureBuilder(myFeature)
Dim inst As InstanceFeature = CType(myFeature, InstanceFeature)

Dim corps() As Body
corps = inst.GetAssociatedBodies()

but how I get the location of evry bodies, because the final destination of this development is to get every location of all the bodies.