Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find current feature number not counting Sketches

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
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.

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 )

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.
 
Replies continue below

Recommended for you

There is a sketch collection you can use to access the sketches. They also show up as features; however, they do seem to be treated slightly differently. Sketches may be internal or external, my guess is that is at least part of the reason they get different treatment.

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:
Option Strict Off
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor