Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Ron247 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing body Line widths Journaling VB 2

Status
Not open for further replies.

NutAce

Mechanical
Apr 22, 2010
1,192
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:
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:
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

 
Replies continue below

Recommended for you

nutace said:
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:

[ol 1]
[li]import the NXOpen.UF namespace. At the beginning of your journal file add the line:
Code:
Option Strict Off
Imports System
Imports NXOpen
[highlight #FCE94F]Imports NXOpen.UF[/highlight]
[/li]

OR

[li]Use the fully qualified name for UFConstants.
Code:
        With selectionMask_array(0)
            .Type = [highlight #FCE94F]NXOpen.UF.[/highlight]UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = [highlight #FCE94F]NXOpen.UF.[/highlight]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.
[/li]
[/ol]


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

Code:
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
 
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor