×
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

Help in Journal Error

Help in Journal Error

Help in Journal Error

(OP)
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

RE: Help in Journal Error

Quote (a984928)

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)

What does the error message say?

www.nxjournaling.com

RE: Help in Journal Error

The error message is telling us that the body that was selected does not have a string attribute named "test". Are you sure that the attribute was applied to the body and not a feature or the part itself?

www.nxjournaling.com

RE: Help in Journal Error

(OP)

The part contain an extrude of a sketch rectangle
that I right click on it and in the opened dialog on attribute tab
I set Title to "test" and a string type value I set it to "t3"

so I have Title = "test" and its value = "t3"

and for select a body I selected the extruded rectangle

and that give this err

Thank you again

RE: Help in Journal Error

Double check to see that you have assigned the attribute to the solid body itself and not the extrude feature. Go to Edit -> properties, change your selection filter to solid body and check to see if the attribute exists. Repeat with your selection filter set to "feature" and see if the attribute exists there.

www.nxjournaling.com

RE: Help in Journal Error

(OP)

You are right

I set the attribute with filter solid body and that works
thank you very much

Cowski if I want to do that for all the atributtes of that solid body
can you help what functions to use

Thank you a lot

RE: Help in Journal Error

To get all the attributes of the body, you can use the .GetUserAttributes method; this will return an array of NXObject.AttributeInformation structures that you can query.

www.nxjournaling.com

RE: Help in Journal Error

(OP)

I get it

it is near to me and I didn't see it

Thank you for this whole help

RE: Help in Journal Error

(OP)

Hi cowski

If you see this

My finished journal works very well but I need it in DLL, but when I compile I get this errors

using nx8.5 and this compiling command

========================================================================================================================
C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc /libpath:C:\hvv\_VBC\managed /t:library /r:NXOpen.dll /r:NXOpen.Utilities.dll /r:NXOpen.UF.dll /r:NXOpenUI.dll report_body_attribute_for_title_ref_des_value_13.vb > o3.txt
=========================================================================================================================

o3.txt output

Microsoft (R) Visual Basic Compiler version 9.0.30729.5420
Copyright (c) Microsoft Corporation. All rights reserved.

C:\haviv\dev\__UniGraphics_VB__\_VBC\report_body_attribute_for_title_ref_des_value_13.vb(32) : error BC30456: 'GetUserAttributes' is not a member of 'NXOpen.NXObject'.

attrInfo = body_object.GetUserAttributes()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\haviv\dev\__UniGraphics_VB__\_VBC\report_body_attribute_for_title_ref_des_value_13.vb(40) : error BC30456: 'StringValue' is not a member of 'NXOpen.NXObject.AttributeInformation'.

def_res_value = attrInfo(loopVar).StringValue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\haviv\dev\__UniGraphics_VB__\_VBC\report_body_attribute_for_title_ref_des_value_13.vb(45) : error BC30456: 'StringValue' is not a member of 'NXOpen.NXObject.AttributeInformation'.

geom_name_value = attrInfo(loopVar).StringValue
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\haviv\dev\__UniGraphics_VB__\_VBC\report_body_attribute_for_title_ref_des_value_13.vb(76) : warning BC42024: Unused local variable: 'obj'.

Dim obj As NXOpen.Tag
~~~
C:\haviv\dev\__UniGraphics_VB__\_VBC\report_body_attribute_for_title_ref_des_value_13.vb(84) : warning BC42104: Variable 'message' is used before it has been assigned a value. A null reference exception could result at runtime.

ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _


=============================================================================================================================
journal code
======================
Option Strict Off

Imports System

Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.UF

Module report_body_attribute_for_title_ref_des_value

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()

Sub Main()

Dim body As NXOpen.Tag
Dim def_res_title As String
Dim geom_name_title As String
Dim def_res_value As String
Dim geom_name_value As String

While select_a_body(body) = Selection.Response.Ok

Dim loopVar As Integer = 0

Dim body_object As NXObject = CType(NXObjectManager.Get(body), NXObject)

Dim attrInfo() As NXObject.AttributeInformation
Try
attrInfo = body_object.GetUserAttributes()

Dim cntr As Integer = attrInfo.Length - 1

Do While loopVar <= cntr

If attrInfo(loopVar).Title = "REF_DES" Then
def_res_title = attrInfo(loopVar).Title
def_res_value = attrInfo(loopVar).StringValue
End If

If attrInfo(loopVar).Title = "GEOM_NAME" Then
geom_name_title = attrInfo(loopVar).Title
geom_name_value = attrInfo(loopVar).StringValue
End If

loopVar = loopVar + 1
Loop

theUI.NXMessageBox.Show("logo name" , _
NXMessageBox.DialogType.Information, _
def_res_title & " = " & def_res_value & vbCrLf _
& vbCrLf & geom_name_title & " = " & geom_name_value)
def_res_value = ""
geom_name_value = ""
def_res_title = ""
geom_name_title = ""

ufs.Disp.SetHighlight(body, 0)

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) this line here
'give error so I moved it to main sub

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
=======================================================================================================================

I see a lot about this error in the internet
but I found nothing that can help

Thank you in advanced

RE: Help in Journal Error

Do you have any older versions of NX installed?
If so, make sure that the compiler is referencing the NX 8.5 dll files and not the older versions.

www.nxjournaling.com

RE: Help in Journal Error

(OP)
Hi Cowski

Without your help I'll never never come to it
The internet not helped me you do

Thank you very 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