×
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

Changing body Line widths Journaling VB
2

Changing body Line widths Journaling VB

Changing body Line widths Journaling VB

(OP)
Hi All,

I found this piece of code on here which I tweaked to my needs..
Originally it changed the body color to red but I tweaked it to change the line width to 0,5 mm
Problem is that the type filter is wrong. I would like it to be set to solid body but that part isn't working.

CODE --> vb

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Edit->Object Display...
' ----------------------------------------------


' ----------------------------------------------
'   Dialog Begin Edit Object Display
' ----------------------------------------------
' ----------------------------------------------
'   Dialog Begin linewidth
' ----------------------------------------------
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = False

displayModification1.ApplyToOwningParts = False

displayModification1.NewWidth = DisplayableObject.ObjectWidth.Five

Dim objects1(0) As DisplayableObject
'Dim body1 As Body = CType(workPart.Bodies.FindObject("BLOCK(1)"), Body)

Dim body as DisplayableObject
Dim Resp as integer
Resp=SelectAnObject ("identify body",body)
objects1(0) = body
displayModification1.Apply(objects1)

displayModification1.Dispose()
' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
Function SelectAnObject(prompt As String, _
               ByRef selObj As DisplayableObject) As Selection.Response
 
       Dim theUI As UI = UI.GetUI
       Dim cursor As Point3d
       REM Dim typeArray() As Selection.SelectionType = _
          REM {   Selection.SelectionType.All, _
              REM Selection.SelectionType.Faces, _
              REM Selection.SelectionType.Edges, _
              REM Selection.SelectionType.Features}
	Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
        End With

        response = ui.SelectionManager.SelectObjects(message, title, scope, _
                                         selectionAction, includeFeatures, _
                                     keepHighlighted, selectionMask_array, _
                                                      selectedObjects)
 
       Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
               prompt, "Selection", _
               Selection.SelectionScope.AnyInAssembly, _
               False, typeArray, selobj, cursor)
 
       If resp = Selection.Response.ObjectSelected Or _
               resp = Selection.Response.ObjectSelectedByName Then
           Return Selection.Response.Ok
       Else
           Return Selection.Response.Cancel
       End If
 
    End Function

End Module 

What I changed is below.

CODE --> vb

Function SelectAnObject(prompt As String, _
               ByRef selObj As DisplayableObject) As Selection.Response
 
       Dim theUI As UI = UI.GetUI
       Dim cursor As Point3d
       Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
        End With

        response = ui.SelectionManager.SelectObjects(message, title, scope, _
                                         selectionAction, includeFeatures, _
                                     keepHighlighted, selectionMask_array, _
                                                      selectedObjects)
 
       Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
               prompt, "Selection", _
               Selection.SelectionScope.AnyInAssembly, _
               False, typeArray, selobj, cursor)
 
       If resp = Selection.Response.ObjectSelected Or _
               resp = Selection.Response.ObjectSelectedByName Then
           Return Selection.Response.Ok
       Else
           Return Selection.Response.Cancel
       End If
 
    End Function 

this gives me the following error...
UFConstants is not declared, and after that a bunch of other errors but I would like to tackle this one first...
What did I do wrong here?

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2
HPZ420 Intel(R) Xeon(R) CPU E5-1620 0 @ 3.60GHz, 32 Gb Win7 64B
Nvidea Quadro4000 2048MB DDR5

HP Zbook15
Intel(R) Core(TM) i7-4800MQ
CPU @ 2.70 GHz Win7 64b
Nvidia K1100M 2048 MB DDR5

RE: Changing body Line widths Journaling VB

Quote (nutace)

UFConstants is not declared, and after that a bunch of other errors but I would like to tackle this one first...

UFConstants lives in the NXOpen.UF namespace. To fix this particular error, you can do either of the following:

  1. import the NXOpen.UF namespace. At the beginning of your journal file add the line:

    CODE

    Option Strict Off
    Imports System
    Imports NXOpen
    Imports NXOpen.UF 


  2. OR

  3. Use the fully qualified name for UFConstants.

    CODE

    With selectionMask_array(0)
                .Type = NXOpen.UF.UFConstants.UF_solid_type
                .Subtype = 0
                .SolidBodySubtype = NXOpen.UF.UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
            End With 
    Technically, the NXOpen part highlighted above wouldn't be necessary because you have already imported the NXOpen namespace. Importing a namespace acts like a shortcut, eliminating some otherwise redundant typing.

www.nxjournaling.com

RE: Changing body Line widths Journaling VB

I think this is what you are looking for (I copied portions of a journal posted by cowski)

CODE --> VB

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As Session = Session.GetSession()

Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = False

displayModification1.ApplyToOwningParts = False

displayModification1.NewWidth = DisplayableObject.ObjectWidth.Five

Dim body() as TaggedObject
If SelectAnObject("identify body",body) = Selection.Response.Cancel Then
  Return
End If

Dim objects1 As New List(Of DisplayableObject)

For Each temp As TaggedObject In body
    objects1.Add(CType(temp, DisplayableObject))
Next

displayModification1.Apply(objects1.ToArray)

displayModification1.Dispose()

End Sub
Function SelectAnObject(prompt As String, _
               ByRef selObj() As TaggedObject) As Selection.Response
 
       Dim theUI As UI = UI.GetUI
       Dim title As String = "Select one or more bodies"
       Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
       Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
       Dim includeFeatures As Boolean = False
       Dim keepHighlighted As Boolean = False
       Dim selectionMask_array(0) As Selection.MaskTriple

       With selectionMask_array(0)
           .Type = UFConstants.UF_solid_type
           .Subtype = 0
           .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
       End With

       Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects( _
         prompt, title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj)
       If resp = Selection.Response.Ok Then
           Return Selection.Response.Ok
       Else
           Return Selection.Response.Cancel
       End If

End Function

End Module 

RE: Changing body Line widths Journaling VB

(OP)
Thanks Both!
Got it working!

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2
HPZ420 Intel(R) Xeon(R) CPU E5-1620 0 @ 3.60GHz, 32 Gb Win7 64B
Nvidea Quadro4000 2048MB DDR5

HP Zbook15
Intel(R) Core(TM) i7-4800MQ
CPU @ 2.70 GHz Win7 64b
Nvidia K1100M 2048 MB DDR5

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