×
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

NX9 - Journal code glitch? or system glitch?

NX9 - Journal code glitch? or system glitch?

NX9 - Journal code glitch? or system glitch?

(OP)
I have the following code that will add a REF appended text below a dimension. I have several others that are similar with just different notes. TYP, START, etc... I then made a drop down letting the detailer just select a dimension, click the appended text they want, and it is automatically added. No typing or anything.

The Problem ....
These codes seemed to work perfect but someone pointed out a glitch to me recently. Any dimensions we use these codes to add appended text to, become temporarily indestructible. You can select it, but it will not delete. The only way to get rid of the dimension if you need to, is to close the file and re-open it. Once it is re-opened, it is fine and you can delete the dimension. I have seen this glitch on other dims in the past, but this is the first time I have seen anything that causes this glitch to happen. And it happens every time.

I was wondering if someone can see if there is something in the code that might cause this problem? Or maybe someone has already dealt with this glitch on their system and knows how to fix it? Or is this a local glitch only and the problem is in our own system somewhere?

Note: I am a complete amateur with code. clown I am trying to learn it but its one of those old dog new trick problems I think. lol


Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities

Module DimensionAppendedText
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim wp As Part = s.Parts.Work()
Sub Main()
Dim response1 As Selection.Response = Selection.Response.Cancel
Dim obj(-1) As TaggedObject
Dim prompt As String = "Select Dimensions"
Dim appendedstring As String = Nothing
' Dim prompt1 As String = "Enter Dimension Text"
' appendedstring = NXInputBox.GetInputString(prompt1)
response1 = select_dimensions(prompt, obj)
For Each dim1 As TaggedObject In obj
SetDimensionAppendedtext(appendedstring, dim1)
Next
End Sub

Function select_dimensions(ByVal prompt As String, ByRef obj() As TaggedObject) As Selection.Response
Dim mask(0) As Selection.MaskTriple
mask(0).Type = UFConstants.UF_dimension_type
mask(0).Subtype = 0
mask(0).SolidBodySubtype = 0
Dim resp As Selection.Response = _
ui.SelectionManager.SelectTaggedObjects(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, False, False, obj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Sub SetDimensionAppendedtext(ByVal appendedtext As String, ByVal dim1 As Dimension)
Dim appendedTextEditorBuilder1 As Annotations.AppendedTextEditorBuilder
appendedTextEditorBuilder1 = wp.Dimensions.CreateAppendedTextEditorBuilder(dim1​)

Dim lines1(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetBefore(lines1)

Dim lines2(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetAfter(lines2)

Dim lines3(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetAbove(lines3)

Dim lines4(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetBelow(lines4)

Dim lines5(0) As String
lines5(0) = "REF"
appendedTextEditorBuilder1.AppendedTextBuilder.SetBelow(lines5)
Dim nXObject1 As NXObject
nXObject1 = appendedTextEditorBuilder1.Commit()
Dim objects1() As NXObject
objects1 = appendedTextEditorBuilder1.GetCommittedObjects()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module

RE: NX9 - Journal code glitch? or system glitch?

Try this one.

CODE

Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities

Module DimensionAppendedText
Dim s As Session = Session.GetSession()
Dim ui As UI = ui.GetUI()
Dim wp As Part = s.Parts.Work()
Sub Main()
Dim response1 As Selection.Response = Selection.Response.Cancel
Dim obj(-1) As TaggedObject
Dim prompt As String = "Select Dimensions"
Dim appendedstring As String = Nothing
' Dim prompt1 As String = "Enter Dimension Text"
' appendedstring = NXInputBox.GetInputString(prompt1)
response1 = select_dimensions(prompt, obj)
For Each dim1 As TaggedObject In obj
SetDimensionAppendedtext(appendedstring, dim1)
Next
End Sub

Function select_dimensions(ByVal prompt As String, ByRef obj() As TaggedObject) As Selection.Response
Dim mask(0) As Selection.MaskTriple
mask(0).Type = UFConstants.UF_dimension_type
mask(0).Subtype = 0
mask(0).SolidBodySubtype = 0
Dim resp As Selection.Response = _
ui.SelectionManager.SelectTaggedObjects(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, False, False, obj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Sub SetDimensionAppendedtext(ByVal appendedtext As String, ByVal dim1 As Dimension)
Dim appendedTextEditorBuilder1 As Annotations.AppendedTextEditorBuilder
appendedTextEditorBuilder1 = wp.Dimensions.CreateAppendedTextEditorBuilder(dim1​)

Dim lines1(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetBefore(lines1)

Dim lines2(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetAfter(lines2)

Dim lines3(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetAbove(lines3)

Dim lines4(-1) As String
appendedTextEditorBuilder1.AppendedTextBuilder.SetBelow(lines4)

Dim lines5(0) As String
lines5(0) = "REF"
appendedTextEditorBuilder1.AppendedTextBuilder.SetBelow(lines5)
Dim nXObject1 As NXObject
nXObject1 = appendedTextEditorBuilder1.Commit()
'Dim objects1() As NXObject
'objects1 = appendedTextEditorBuilder1.GetCommittedObjects()
appendedTextEditorBuilder1.Destroy
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module 

www.nxjournaling.com

RE: NX9 - Journal code glitch? or system glitch?

(OP)
Thanks once again cowski

This seems to make the difference. I compared the two and the only difference I see is that you made these two line active late in the journal...

'Dim objects1() As NXObject
'objects1 = appendedTextEditorBuilder1.GetCommittedObjects()

Is that all it was or did I miss another difference? Can I ask what exactly these lines do?

RE: NX9 - Journal code glitch? or system glitch?

(OP)
Ah...
I also found this line extra...
appendedTextEditorBuilder1.Destroy

RE: NX9 - Journal code glitch? or system glitch?

(OP)
and I was looking at them wrong. You made those two lines inactive. Not active. lol (sigh) I gotta start getting more sleep. lol

RE: NX9 - Journal code glitch? or system glitch?

As you learned, the problem was not destroying the builder.
It helps me to think of the builder like a dialog in the UI. Commit is like Apply, and Destroy is like closing the dialog.

Mark Rief
NX CAM Customer Success
Siemens PLM Software

RE: NX9 - Journal code glitch? or system glitch?

CODE

Dim objects1() As NXObject
objects1 = appendedTextEditorBuilder1.GetCommittedObjects() 

The objects1 variable gives you a reference to the newly created appended text. Since this variable isn't used after it is created (at least not in the original code shown), you can get rid of it. I commented the lines out so that you can easily add them back in if needed.

The real problem (as pointed out by Mark) is that the builder object wasn't cleaned up when we were done with it. This causes some stuff to "hang around" and can lead to errors or strange behavior. In this case, NX wouldn't let you delete the dimension because the builder was still referencing it.

www.nxjournaling.com

RE: NX9 - Journal code glitch? or system glitch?

(OP)
Great info. Thank you very much.

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