Submitted by sixpaws on Tue, 01/14/2014 - 07:03
Forums:
Hi,
I'm using the Pattern Feature in NX853 to create rectangular rows of holes. NX generates features of type Instance Feature for those holes. Given the tag of an Instance Feature, how can I extract its associated hole data (radius, center)?
Thanks
re: pattern features
If you need to know how to get to the master feature given an instance feature tag, see this thread: linear and circular pattern features
If you need to know how to extract the hole data given a hole feature (it looks like a lot of code, but only because it checks for a number of different hole types):
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
If myFeature.FeatureType = "HOLE PACKAGE" Then
Dim holeFeature As HolePackage = myFeature
Dim holeBuilder As HolePackageBuilder
holeBuilder = workPart.Features.CreateHolePackageBuilder(holeFeature)
Dim holeSection As Section = holeBuilder.HolePosition
Dim holeSectionData() As SectionData
holeSection.GetSectionData(holeSectionData)
Dim holeSectionElements() As SectionElementData
holeSectionData(0).GetSectionElementsData(holeSectionElements)
For Each temp As SectionElementData In holeSectionElements
Dim secElement As DisplayableObject
Dim stConnector As DisplayableObject
Dim stPoint As Point3d
Dim endConnector As DisplayableObject
Dim endPoint As Point3d
temp.GetSectionElementData1(secElement, stConnector, stPoint, endConnector, endPoint)
lw.WriteLine("start point: " & stPoint.ToString)
Next
lw.WriteLine("hole type: " & holeBuilder.Type.ToString)
If holeBuilder.Type = HolePackageBuilder.Types.GeneralHole Then
lw.WriteLine("general hole form: " & holeBuilder.GeneralHoleForm.ToString)
If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Simple Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralSimpleHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.GeneralSimpleHoleDepth.Value.ToString)
End If
If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Counterbored Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCounterboreHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.GeneralCounterboreHoleDepth.Value.ToString)
lw.WriteLine("counterbore diameter: " & holeBuilder.GeneralCounterboreDiameter.Value.ToString)
lw.WriteLine("counterbore depth: " & holeBuilder.GeneralCounterboreDepth.Value.ToString)
End If
If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Countersink Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCountersinkHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.GeneralCountersinkHoleDepth.Value.ToString)
lw.WriteLine("countersink diameter: " & holeBuilder.GeneralCountersinkDiameter.Value.ToString)
lw.WriteLine("countersink angle: " & holeBuilder.GeneralCountersinkAngle.Value.ToString)
End If
If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Tapered Then
'code for tapered holes
lw.WriteLine("hole diameter: " & holeBuilder.GeneralTaperedHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.GeneralTaperedHoleDepth.Value.ToString)
lw.WriteLine("taper angle: " & holeBuilder.GeneralTaperAngle.Value.ToString)
End If
End If
If holeBuilder.Type = HolePackageBuilder.Types.DrillSizeHole Then
lw.WriteLine("drill size: " & holeBuilder.DrillSize)
lw.WriteLine("drill size hole diameter: " & holeBuilder.DrillSizeHoleDiameter.Value.ToString)
lw.WriteLine("drill hole depth: " & holeBuilder.DrillSizeHoleDepth.Value.ToString)
End If
If holeBuilder.Type = HolePackageBuilder.Types.ScrewClearanceHole Then
lw.WriteLine("screw size: " & holeBuilder.ScrewSize)
lw.WriteLine("hole diameter: " & holeBuilder.ScrewClearanceHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.ScrewClearanceHoleDepth.Value.ToString)
End If
If holeBuilder.Type = HolePackageBuilder.Types.ThreadedHole Then
lw.WriteLine("thread size: " & holeBuilder.ThreadSize)
lw.WriteLine("thread depth: " & holeBuilder.ThreadDepth.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.ThreadedHoleDepth.Value.ToString)
End If
If holeBuilder.Type = HolePackageBuilder.Types.HoleSeries Then
lw.WriteLine("hole series")
End If
lw.WriteLine("")
End If
Next
lw.Close()
End Sub
End Module
Hi,
Hi,
No, it's not to retrieve hole data given a hole feature. It's to retrieve hole data given an Instance Feature feature (created by the Pattern Feature).
Prior to Pattern Feature there was the LINEAR_ISET, which created instances. Those instances were feature bodies, therefore geometry could be retrieved from them. Ie. I could retrieve the edge associated w/ the instance feature. But w/ NX853, it seems LINEAR_ISET can no longer be created and we have to use Pattern Features instead. The instances created by this new Pattern Feature are not feature bodies and no geometry can be retrieved from them. I just can't seem to be able to find a link btw the instance and the resulting hole (apart from them sharing the same name).
The objects in question are Features.PatternFeature, which creates Features.InstanceFeature.
Thanks
try it
Have you tried the code above? If not, create a hole, use the pattern feature command to create an array and run the code. It will report the diameter and location for each hole.
How are you retrieving the tag of the instance? Perhaps we can work from there...
I know how to retrieve all
I know how to retrieve all the holes created. My issue is to be able to link the instances to the resulting holes. There are user defined attributes in the instances that need to be exported along w/ the hole data.
re: link instance to hole
The
.GetFeatureName
method will return the same result for the instance feature as for the hole package feature. Perhaps you can relate the two with this?That is what I'm currently
That is what I'm currently doing, but it doesn't seem like a very foolproof way. I would've expected there'd be some sort of parent/child relationship btw the two.
Thanks for your help.
re: parent child
All the features are contained in the pattern feature. The "instance features" and "hole packages" have more of a 'sibling' relationship rather than 'parent/child'.
I agree that there should be a more elegant way of relating the instance to the hole; if a better way does exist, it needs to be more obvious...
To retrieve the instances,
To retrieve the instances, loop through the features to find a "Pattern Feature". Find the parent "HOLE PACKAGE". From the hole package, get the children of type "Instance Feature".