×
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

new to journaling

new to journaling

new to journaling

(OP)
Hi,

I am trying to write a journal where the user is prompted to select multiple faces of a block so that the journal can "Offset Face" a specified distance.
I have been able to put together a journal where a single face is selected and offset and I have example code for multi-selections. I just can't figure out how to combine the programs.

Any help would be greatly appreciated.
Thanks,
Kevin

RE: new to journaling

(OP)
Here is what I have so far for a single selection, I realize there are issues if the user cancels out of the selection process but I think I can figure that out.
Also I would like to have the offset distance controlled by a user selected value from a dialog box, but first I need to figure out the multiple selections.
Thanks in advance,
Kevin

Option Strict Off
Imports System
Imports NXOpen

Imports NXOpen.UF
Imports NXOpenUI

Module NXJournal
Sub Main()

Dim face1 As Face = SelectFace()

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Insert->Offset/Scale->Offset Face...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_Feature As Features.Feature = Nothing


If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim offsetFaceBuilder1 As Features.OffsetFaceBuilder
offsetFaceBuilder1 = workPart.Features.CreateOffsetFaceBuilder(nullFeatures_Feature)


theSession.SetUndoMarkName(markId1, "Offset Face Dialog")


Dim boundaryFaces1(-1) As Face
Dim faceTangentRule1 As FaceTangentRule
faceTangentRule1 = workPart.ScRuleFactory.CreateRuleFaceTangent(face1, boundaryFaces1)

Dim rules1(0) As SelectionIntentRule
rules1(0) = faceTangentRule1
offsetFaceBuilder1.FaceCollector.ReplaceRules(rules1, False)


offsetFaceBuilder1.Distance.RightHandSide = ".01"

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Offset Face")

Dim nXObject1 As NXObject
nXObject1 = offsetFaceBuilder1.Commit()

Dim expression1 As Expression = offsetFaceBuilder1.Distance

nXObject1.SetName("Grind Stock")

offsetFaceBuilder1.Destroy()

End Sub

' ----------------------------------------------
' Selecting The Face
' ----------------------------------------------
Public Function SelectFace() As Face

Dim ui As UI = ui.GetUI
Dim message As String = "Select Face"
Dim title As String = "Selection"

Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True

Dim selectionAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific

Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_face_type
.Subtype = 0
.SolidBodySubtype = 0
End With

Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d

ui.SelectionManager.SelectObject(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObject, cursor)

Dim face As Face = CType(selectedObject, Face)

If face Is Nothing Then
Return Nothing
End If

Return face

End Function




End Module

RE: new to journaling

(OP)
This is the code I was attempting to use for selecting multiple faces:

'
' MultiSelection of Faces
'
Function SelectObjects(prompt As String, _
ByRef selObj as NXObject()) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.Faces}

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If

End Function

RE: new to journaling

The current code uses a tangent face rule. When you switch to multiple face selections, do you want to use the tangent face rule or only offset the faces directly selected by the user?

Also, what version of NX are you using?

www.nxjournaling.com

RE: new to journaling

(OP)
Prefer to only offset the faces directly selected by the user. I assume I could replace "faceTangentRule1" with "faceDumbRule1"?

I am on NX7.5

RE: new to journaling

Here is one solution:

CODE

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

Module Module4
    Sub Main()


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

        Dim displayPart As Part = theSession.Parts.Display

        'Dim face1 As Face = SelectFace()
        Dim face1 As New List(Of Face)
        If SelectFaces("Select faces", face1) = Selection.Response.Cancel Then
            Exit Sub
        End If

        ' ----------------------------------------------
        ' Menu: Insert->Offset/Scale->Offset Face...
        ' ----------------------------------------------
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

        Dim nullFeatures_Feature As Features.Feature = Nothing


        If Not workPart.Preferences.Modeling.GetHistoryMode Then
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
        End If

        Dim offsetFaceBuilder1 As Features.OffsetFaceBuilder
        offsetFaceBuilder1 = workPart.Features.CreateOffsetFaceBuilder(nullFeatures_Feature)


        theSession.SetUndoMarkName(markId1, "Offset Face Dialog")

        Dim faceDumbRule1 As FaceDumbRule
        faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(face1.ToArray)

        Dim rules1(0) As SelectionIntentRule
        rules1(0) = faceDumbRule1

        offsetFaceBuilder1.FaceCollector.ReplaceRules(rules1, False)

        offsetFaceBuilder1.Distance.RightHandSide = ".01"

        Dim markId2 As Session.UndoMarkId
        markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Offset Face")

        Dim nXObject1 As NXObject
        nXObject1 = offsetFaceBuilder1.Commit()

        Dim expression1 As Expression = offsetFaceBuilder1.Distance

        nXObject1.SetName("Grind Stock")

        offsetFaceBuilder1.Destroy()

    End Sub

    ' ----------------------------------------------
    ' Selecting The Faces
    ' ----------------------------------------------

    Function SelectFaces(ByVal prompt As String, _
    ByRef theFaces As List(Of Face)) As Selection.Response

        Dim selObj() As NXObject
        Dim theUI As UI = UI.GetUI
        Dim typeArray() As Selection.SelectionType = _
        {Selection.SelectionType.Faces}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
        prompt, "Selection", _
        Selection.SelectionScope.AnyInAssembly, _
        False, typeArray, selObj)

        If resp = Selection.Response.ObjectSelected Or _
        resp = Selection.Response.ObjectSelectedByName Or _
        resp = Selection.Response.Ok Then
            For Each tempFace As Face In selObj
                theFaces.Add(tempFace)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


End Module 

www.nxjournaling.com

RE: new to journaling

(OP)
Cowski,

Thank you, that is very helpful!

Kevin

RE: new to journaling

(OP)
Cowski,

Is there any chance you could help me out again? I am trying to use AskFaceMinRadii with no luck.

I have added the below code after line 82 to the first code I posted in this thread.

FaceTag = face1.Tag


ufs.Modl.AskFaceMinRadii ( FaceTag, num_radii, radii, positions, params)

lw.Open
lw.WriteLine("Object Tag: " & FaceTag.ToString)
lw.WriteLine(radii.ToString)

I get an error that parameter radii has a null value, I can select the same face with "Analysis/MinimumRadius and it returns a radius value.
Any ideas???

Thanks,
Kevin

RE: new to journaling

You must also declare the num_radii, radii, positions, and params variables.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim theFace As Face
        If SelectFace("Select a face", theFace) = Selection.Response.Cancel Then
            Exit Sub
        End If

        'MsgBox(theFace.Tag.ToString)

        Dim numRadii As Integer
        Dim radii(1) As Double
        Dim positions(5) As Double
        Dim params(3) As Double

        theUfSession.Modl.AskFaceMinRadii(theFace.Tag, numRadii, radii, positions, params)

        lw.WriteLine("number of radii: " & numRadii.ToString)
        lw.WriteLine("radius 1: " & radii(0).ToString)
        lw.WriteLine("radius 2: " & radii(1).ToString)

        lw.Close()

    End Sub

    Function SelectFace(ByVal prompt As String, ByRef tempFace As Face) As Selection.Response

        Dim selObj As TaggedObject
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a face"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

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

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            tempFace = selObj
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module 

www.nxjournaling.com

RE: new to journaling

(OP)
Thanks you!
I had them declared but not properly.
This is what I had:
Dim num_radii As Integer
Dim radii As Double()
Dim positions As Double()
Dim params As Double()

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