Hello,
Below code which change font in feature "TEXT" on Modern. I use this to change current font e.g. Arial to Modern. Before changing font with this features is made "EXTRUDE" features. I cannot find command which will be find "EXTRUDE" features which are children "TEXT" features before changing font. When child features will be find I suppress it.
How to find children "TEXT" features in work part?
I suppose that it will be " Features.Future.GetChildren" but I don't know how to use it.
Could you help ? I use NX10
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module CzcionkaModern
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "CzcionkaModern")
lw.Open()
For Each theFeature As Features.Feature In workPart.Features.GetFeatures
If TypeOf theFeature Is Features.Text Then
'lw.writeline(theFeature.JournalIdentifier)
'lw.writeline("--" & theFeature.GetFeatureName)
Dim text1 As NXOpen.Features.Text = CType(workPart.Features.FindObject(theFeature.JournalIdentifier), NXOpen.Features.Text)
Dim textBuilder1 As NXOpen.Features.TextBuilder
textBuilder1 = workPart.Features.CreateTextBuilder(text1)
'textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
Dim dlugosc As String = textBuilder1.FrameOnPath.Length.RightHandSide
'lw.writeline("Length przed zmianą: " & dlugosc)
textBuilder1.SelectFont("Modern", NXOpen.Features.TextBuilder.ScriptOptions.Oem)
textBuilder1.FrameOnPath.Length.RightHandSide = dlugosc
'lw.writeline("Length po zmianie powinna być taka sama jak przed zmiana: " & dlugosc)
Dim nXObject1 As NXOpen.NXObject
nXObject1 = textBuilder1.Commit()
textBuilder1.Destroy()
Try
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Catch ex As NXException
MsgBox("Suppress all 'EXTRUDE' - children 'TEXT' features" , MsgBoxStyle.Critical, "WARNING !!!" )
Exit sub
End try
End if
Next
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
Regards
Marcin
re: edit feature
Have you tried recording a journal while editing a text feature? It may not be necessary to suppress all the of child features before the edit.
Alternatively, there is a .SetEditWithRollbackFeature method that might come in handy in your case. This will essentially suppress all the features below the one that you are editing. Record a journal and choose "edit with rollback" on the text feature before changing its font to see how it works.
Finally, if you really want to see all the features affected by a given feature, I'd suggest using the {feature}.GetChildren method along with recursion (similar to getting all of the components in an assembly). Below is a quick example that lists the child features of the first feature in the work part.
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
lw.Open()
Const undoMarkName As String = "report child features"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim firstFeature As Features.Feature = workPart.Features.ToArray(0)
lw.WriteLine(firstFeature.GetFeatureName)
GetChildFeatures(firstFeature, 0)
lw.WriteLine("")
lw.Close()
End Sub
Sub GetChildFeatures(ByVal theFeature As Features.Feature, ByVal indent As Integer)
indent += 2
Dim childFeatures() As Features.Feature = theFeature.GetChildren
For Each tempFeature As Features.Feature In childFeatures
lw.WriteLine(New String(" ", indent) & tempFeature.GetFeatureName)
GetChildFeatures(tempFeature, indent)
Next
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
re: Edit Feature
Hello,
I did not use "Edit with Rollback..." Feature because I consciously want suppress "Extrude" Features. This code will be use when someone want to write code for CNC Machine where is necessery to use "Modern" font.
Anyway your example was very helpful. Thanks you very much.
Below is complete code.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module CzcionkaModern
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main (ByVal args() As String)
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "CzcionkaModern")
lw.Open()
For Each theFeature As Features.Feature In workPart.Features.GetFeatures
If TypeOf theFeature Is Features.Text Then
'lw.writeline(theFeature.JournalIdentifier)
'lw.WriteLine("Text Feature: " & theFeature.GetFeatureName)
GetChildFeatures(theFeature, 0)
Dim text1 As NXOpen.Features.Text = CType(workPart.Features.FindObject(theFeature.JournalIdentifier), NXOpen.Features.Text)
Dim textBuilder1 As NXOpen.Features.TextBuilder
textBuilder1 = workPart.Features.CreateTextBuilder(text1)
'textBuilder1.FrameOnPath.AnchorPosition.Expression.RightHandSide = "50"
Dim dlugosc As String = textBuilder1.FrameOnPath.Length.RightHandSide
'lw.writeline("Length przed zmianą: " & dlugosc)
textBuilder1.SelectFont("Modern", NXOpen.Features.TextBuilder.ScriptOptions.Oem)
textBuilder1.FrameOnPath.Length.RightHandSide = dlugosc
'lw.writeline("Length po zmianie powinna być taka sama jak przed zmiana: " & dlugosc)
Dim nXObject1 As NXOpen.NXObject
nXObject1 = textBuilder1.Commit()
textBuilder1.Destroy()
Try
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Catch ex As NXException
MsgBox("Suppress all 'EXTRUDE' - children 'TEXT' features", MsgBoxStyle.Critical, "WARNING !!!" )
Exit sub
End try
End if
Next
End Sub
Sub GetChildFeatures(ByVal theFeature As Features.Feature, ByVal indent As Integer)
indent += 2
Dim childFeatures() As Features.Feature = theFeature.GetChildren
For Each tempFeature As Features.Feature In childFeatures
'lw.WriteLine(New String(" ", indent) & " Children: " & tempFeature.GetFeatureName)
If tempFeature.JournalIdentifier.Contains("EXTRUDE") then
Dim features1(0) As NXOpen.Features.Feature
Dim extrude1 As NXOpen.Features.Extrude = CType(workPart.Features.FindObject(tempFeature.JournalIdentifier), NXOpen.Features.Extrude)
features1(0) = extrude1
workPart.Features.SuppressFeatures(features1)
end if
GetChildFeatures(tempFeature, indent)
Next
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
Regards
Marcin