Kenja824
Automotive
- Nov 5, 2014
- 950
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.
) 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
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.
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