×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Find current feature number not counting Sketches

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.

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.  

RE: Find current feature number not counting Sketches

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

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources