Ehaviv
Computer
- Jul 2, 2003
- 1,012
Hi
In this journal (that I revised from internet one) I get error in line 31
line 31 ==> attrInfo = body_object.GetUserAttribute("test",NXObject.AttributeType.String,-1)
Using NX8.5
What's wrong here
My goal is to read the body attribute (Title = Value) for a given title gets its value
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
Module report_attrs_by_title_and_type
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim body As NXOpen.Tag
While select_a_body(body) = Selection.Response.Ok
Dim loopVar As Integer = 0
Dim body_object As NXObject = CType(NXObjectManager.Get(body), NXObject)
MsgBox("Body Object:" & body_object.ToString())
Dim attrInfo As NXObject.AttributeInformation
Try
attrInfo = body_object.GetUserAttribute("test",NXObject.AttributeType.String,-1)
ufs.Ui.OpenListingWindow()
ufs.Ui.WriteListingWindow("Attribute Title: " & attrInfo.Title & vbCrLf)
ufs.Ui.WriteListingWindow("Attribute Type: " & attrInfo.Type.ToString & vbCrLf)
ufs.Ui.WriteListingWindow("Attribute StringValue: " & attrInfo.StringValue & vbCrLf)
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical)
End Try
End While
End Sub
Function select_a_body(ByRef body As NXOpen.Tag) As Selection.Response
Dim message As String
Dim title As String = "Select a body"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer
Dim obj As NXOpen.Tag
Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim ip As UFUi.SelInitFnT = AddressOf mask_for_bodies
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _
Nothing, response, body, cursor, view)
Finally
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try
'ufs.Disp.SetHighlight(body, 0)
If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
Return Selection.Response.Cancel
Else
Return Selection.Response.Ok
End If
End Function
Function mask_for_bodies(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_solid_type
mask_triples(0).object_subtype = UFConstants.UF_solid_body_subtype
mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_BODY
ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
THANKS in advanced
In this journal (that I revised from internet one) I get error in line 31
line 31 ==> attrInfo = body_object.GetUserAttribute("test",NXObject.AttributeType.String,-1)
Using NX8.5
What's wrong here
My goal is to read the body attribute (Title = Value) for a given title gets its value
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
Module report_attrs_by_title_and_type
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim body As NXOpen.Tag
While select_a_body(body) = Selection.Response.Ok
Dim loopVar As Integer = 0
Dim body_object As NXObject = CType(NXObjectManager.Get(body), NXObject)
MsgBox("Body Object:" & body_object.ToString())
Dim attrInfo As NXObject.AttributeInformation
Try
attrInfo = body_object.GetUserAttribute("test",NXObject.AttributeType.String,-1)
ufs.Ui.OpenListingWindow()
ufs.Ui.WriteListingWindow("Attribute Title: " & attrInfo.Title & vbCrLf)
ufs.Ui.WriteListingWindow("Attribute Type: " & attrInfo.Type.ToString & vbCrLf)
ufs.Ui.WriteListingWindow("Attribute StringValue: " & attrInfo.StringValue & vbCrLf)
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical)
End Try
End While
End Sub
Function select_a_body(ByRef body As NXOpen.Tag) As Selection.Response
Dim message As String
Dim title As String = "Select a body"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer
Dim obj As NXOpen.Tag
Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim ip As UFUi.SelInitFnT = AddressOf mask_for_bodies
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _
Nothing, response, body, cursor, view)
Finally
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try
'ufs.Disp.SetHighlight(body, 0)
If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
Return Selection.Response.Cancel
Else
Return Selection.Response.Ok
End If
End Function
Function mask_for_bodies(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_solid_type
mask_triples(0).object_subtype = UFConstants.UF_solid_body_subtype
mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_BODY
ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
THANKS in advanced