Find current feature number not counting Sketches
Find current feature number not counting Sketches
(OP)
This monster program I am writing places a point, datum, offset line, then sketch. I want it to name each feature. This was working perfectly until I added sketches into the mix. For some reason, the array is not counting the sketches.
The first point, datum, and line are named as usual but as soon as it reaches this point in the workflow after the first sketch has been put in place, it can no long for the feature needing to be renamed so errors out.
I have a different callout for datums and points, so the problem is not because it is trying to find a point and calling a line, if I comment out my code to add the sketch this works fine. Does anyone know what is different about sketches? Is there a way to count them separately? If they are not a feature, what would they be classified as?
I know I'm posting a lot of questions on here and I promise I am looking elsewhere for the answers.
CODE
Dim featArray() As Feature = myFeats.ToArray()
Dim lastFeatNum As Integer = featArray.GetUpperBound(0)
Dim lastFeat As Feature = featArray(lastFeatNum)
ufs.Modl.SetCurrentFeature(lastFeat.Tag())
Dim oldLName As String
Dim newLName As String
oldLName = "LINE(" & lastFeatNum &")"
Dim associativeLine1 As Features.AssociativeLine = CType(workPart.Features.FindObject(oldLName), Features.AssociativeLine)
newLName = "S" & counter
associativeLine1.SetName( newLName )
Dim lastFeatNum As Integer = featArray.GetUpperBound(0)
Dim lastFeat As Feature = featArray(lastFeatNum)
ufs.Modl.SetCurrentFeature(lastFeat.Tag())
Dim oldLName As String
Dim newLName As String
oldLName = "LINE(" & lastFeatNum &")"
Dim associativeLine1 As Features.AssociativeLine = CType(workPart.Features.FindObject(oldLName), Features.AssociativeLine)
newLName = "S" & counter
associativeLine1.SetName( newLName )
The first point, datum, and line are named as usual but as soon as it reaches this point in the workflow after the first sketch has been put in place, it can no long for the feature needing to be renamed so errors out.
I have a different callout for datums and points, so the problem is not because it is trying to find a point and calling a line, if I comment out my code to add the sketch this works fine. Does anyone know what is different about sketches? Is there a way to count them separately? If they are not a feature, what would they be classified as?
I know I'm posting a lot of questions on here and I promise I am looking elsewhere for the answers.





RE: Find current feature number not counting Sketches
The journal below will report all the sketches then all the features for the current work part. You will notice that sketches do show up in the feature list, but without the timestamp number.
CODE
Imports System
Imports NXOpen
Imports NXOpen.Features
Module NXJournal
Sub Main
Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim lw As ListingWindow = s.ListingWindow
lw.Open()
lw.WriteLine("Sketches:")
For Each sk As Sketch In s.Parts.Work.Sketches
lw.WriteLine(sk.Feature.GetFeatureName & " (" & sk.Feature.TimeStamp.ToString & ") " & """" & sk.Name & """")
Next
lw.WriteLine("")
Dim featArray() As Feature = s.Parts.Work.Features.GetFeatures()
Dim lastFeatNum As Integer = featArray.GetUpperBound(0)
Dim lastFeat As Feature = featArray(lastFeatNum)
lw.WriteLine("Last Feature: " & lastFeat.GetFeatureName)
lw.WriteLine("")
lw.WriteLine("*** All Features ***")
For each myFeature as Feature in featArray
lw.WriteLine(myFeature.GetFeatureName)
Next
lw.Close
End Sub
End Module
www.nxjournaling.com