Submitted by Mohamed wael zakhama on Tue, 04/23/2013 - 06:45
Forums:
Hi every one,
i'm new in NX programming , but every day i learn new things through recording journals and also by reading what's in this wonderful site.I'm now working on a project for my final study project , (automatic meshing tool) and i succeed to do somethings , although i need your help for programming a selection journal with some specifications , i need to filter between curved faces and planar faces ...
any one can help me ??
thank you
re: face selection
The code below contains 2 selection functions; the first allows you to pick planar faces, the other non-planar faces.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Dim myPlanarFace As Face
Dim myNonPlanar As Face
If SelectPlanarFace("", myPlanarFace) = Selection.Response.Cancel Then
Exit Sub
End If
'do something with planar face
If SelectOtherFace("", myNonPlanar) = Selection.Response.Cancel Then
Exit Sub
End If
'do something with non-planar face
End Sub
Function SelectPlanarFace(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a planar 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.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function SelectOtherFace(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a non-planar 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.AnyInAssembly
Dim selectionMask_array(7) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BLENDING_FACE
End With
With selectionMask_array(1)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CONICAL_FACE
End With
With selectionMask_array(2)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_CYLINDRICAL_FACE
End With
With selectionMask_array(3)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SPHERICAL_FACE
End With
With selectionMask_array(4)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SWEPT_FACE
End With
With selectionMask_array(5)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SWUNG_FACE
End With
With selectionMask_array(6)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_TOROIDAL_FACE
End With
With selectionMask_array(7)
.Type = UFConstants.UF_b_surface_type
.Subtype = 0
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
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
End Function
End Module
Thank you very much ,
Thank you very much ,
I was thinking of selecting multiple faces ( like the selectobjects function ) , i will edit this code to be able to select multiple faces and if i succeed i will repost it.
:)
Hi again,
Hi again,
As i said , i'm sharing this journal for multiple selection with mask array for filtering faces (and assign a Cartesian coordinate system for all the faces).
i work on advanced modelation module so you may want to change the first lines if you are working on modeling module.
the code works excellent if i put " UF_UI_SEL_FEATURE_ANY_FACE " (line 59) as a maskarray ,which allows any face selection, so i must select manually the faces but if i put anything else like :
UF_UI_SEL_FEATURE_PLANAR_FACE
UF_UI_SEL_FEATURE_CYLINDRICAL_FACE
UF_UI_SEL_FEATURE_SPHERICAL_FACE
UF_UI_SEL_FEATURE_TOROIDAL_FACE
UF_UI_SEL_FEATURE_PARAMETRIC_FACE
UF_UI_SEL_FEATURE_BLENDING_FACE
UF_UI_SEL_FEATURE_OFFSET_FACE
UF_UI_SEL_FEATURE_SWEPT_FACE
UF_UI_SEL_FEATURE_SWUNG_FACE
UF_UI_SEL_FEATURE_FOREIGN_FACE
the program do not allow any selection , for information the part that i'm working on , have different types of faces , so i don't know why these maskarrays don't work ?
thanks for the help
--------------------------------------------------------------------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)
Dim displayFemPart As CAE.FemPart = CType(theSession.Parts.BaseDisplay, CAE.FemPart)
Dim mySelectedObjects as NXObject()
If SelectObjects1("Hey, select multiple somethings", _
mySelectedObjects) = Selection.Response.Ok Then
For Each mySelObj As NXObject in mySelectedObjects
Dim xform1 As Xform
xform1 = workFemPart.Xforms.CreateXform(myselobj, SmartObject.UpdateOption.AfterModeling)
Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem
cartesianCoordinateSystem1 = workFemPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.AfterModeling)
cartesianCoordinateSystem1.SetVisibility(SmartObject.VisibilityOption.Visible)
next
end if
End Sub
'----------------------------------------------------------------------------
Function SelectObjects1(byval prompt As String, _
ByRef selObj as NXObject()) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim includeFeatures As Boolean = true
Dim keepHighlighted As Boolean = true
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim typeArray() As Selection.SelectionType = _
{ _
Selection.SelectionType.faces
}
Dim cursor As Point3d
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_LINEAR_EDGE
end with
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "face selection for cartesian Csys ", _
Selection.SelectionScope.AnyInAssembly,selaction,includeFeatures, _
keepHighlighted, selectionMask_array, 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
'-------------------------------------------------------------------------------------
End Module
re: selection
There's a few things going on with your selection function...
First, the type array is doing nothing for you, delete it.
Dim typeArray() As Selection.SelectionType = _
{ Selection.SelectionType.faces}
The SelectObjects method is overloaded, you are using the version that takes the maskTriple array to filter the selection. The type array is used in another version of the method, but does nothing in your particular function.
Second, if you change
Dim includeFeatures As Boolean = true
to
Dim includeFeatures As Boolean = false
then the journal will allow you to select linear edges of a solid body (what your mask triple array is set up to filter). By including the feature, the selection function was trying to return the feature that created the linear edge; not what you had in mind, I think.
If you are trying to select faces, you may want to copy & paste from the previous code sample.
thanks for the reply , and
thanks for the reply , and for clarifying , my goal was to share in case any one need it.
Here what happens , the two codes are working well in Modeling module , but if i change to Advanced simulation module the program starts well but it doesn't allow me to select any surface , do you think that .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACES works only for modeling module ?
Increase no. of selection
Hi,
Based on the planar face selection, how can I modify the code to select more than 1 planar face?
thank you
M Nafis
Embeded to the recorded journaling
one more question, how can I embedded the planar selection code to the journaling recorded code. The recorded code as shown below:
_______________________________________________________________________________
' ----------------------------------------------
' Dialog Begin Cut Area
' ----------------------------------------------
Dim faces1(0) As Face
Dim extrude1 As Features.Extrude = CType(workPart.Features.FindObject("EXTRUDE(2)"), Features.Extrude)
Dim face1 As Face = CType(extrude1.FindObject("FACE 140 {(0,15,12.5) EXTRUDE(2)}"), Face)
faces1(0) = face1
Dim faceDumbRule1 As FaceDumbRule
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)
Dim scCollector1 As ScCollector
scCollector1 = geometrySet1.ScCollector
Dim rules1(0) As SelectionIntentRule
rules1(0) = faceDumbRule1
scCollector1.ReplaceRules(rules1, False)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cut Area")
theSession.DeleteUndoMark(markId4, Nothing)
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cut Area")
theSession.DeleteUndoMark(markId5, Nothing)
theSession.SetUndoMarkName(markId3, "Cut Area")
theSession.DeleteUndoMark(markId3, Nothing)
Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Rest Milling")
theSession.DeleteUndoMark(markId6, Nothing)
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Rest Milling")
Dim nXObject1 As NXObject
nXObject1 = cavityMillingBuilder1.Commit()
theSession.DeleteUndoMark(markId7, Nothing)
theSession.SetUndoMarkName(markId2, "Rest Milling")
cavityMillingBuilder1.Destroy()
theSession.DeleteUndoMark(markId2, Nothing)
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")
Dim cavityMillingBuilder2 As CAM.CavityMillingBuilder
cavityMillingBuilder2 = workPart.CAMSetup.CAMOperationCollection.CreateCavityMillingBuilder(CType(theUI.SelectionManager.GetSelectedObject(0), CAM.CavityMilling))
theSession.SetUndoMarkName(markId8, "Rest Milling Dialog")
_________________________________________________________________________
Thank you
M Nafis
re: selecting multiple planar faces
Below is some code demonstrating a selection function for multiple planar faces and how to call it. To incorporate it with your code, pass in the array of selected faces where your journal faces are used.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module2
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim myPlanarFaces() As NXObject
If SelectPlanarFaces("", myPlanarFaces) = Selection.Response.Cancel Then
Exit Sub
End If
'myPlanarFaces is array of selected planar faces
'do something with the selected planar faces
For Each temp As NXObject In myPlanarFaces
Dim tempFace As Face
tempFace = temp
lw.WriteLine("tag: " & tempFace.Tag.ToString)
lw.WriteLine("layer: " & tempFace.Layer.ToString)
lw.WriteLine("color: " & tempFace.Color.ToString)
If myPlanarFaces.Length > 1 Then
lw.WriteLine("")
End If
Next
End Sub
Function SelectPlanarFaces(ByVal prompt As String, byRef selObj() as NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select planar faces"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
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_PLANAR_FACE
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(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
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
Thank you, can you please
Thank you, can you please show me an example of how to pass the array on recorded code. Sorry, I make a few trials but failed. This is an example code for face selection:
Dim faces1(0) As Face
Dim extrude1 As Features.Extrude = CType(workPart.Features.FindObject("EXTRUDE(2)"), Features.Extrude)
Dim face1 As Face = CType(extrude1.FindObject("FACE 140 {(0,15,12.5) EXTRUDE(2)}"), Face)
faces1(0) = face1
Dim faceDumbRule1 As FaceDumbRule
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces1)
Dim scCollector1 As ScCollector
scCollector1 = geometrySet1.ScCollector
Dim rules1(0) As SelectionIntentRule
rules1(0) = faceDumbRule1
scCollector1.ReplaceRules(rules1, False)
Dim faces2(1) As Face
faces2(0) = face1
Dim face2 As Face = CType(extrude1.FindObject("FACE 170 {(12.5,15,0) EXTRUDE(2)}"), Face)
faces2(1) = face2
Dim faceDumbRule2 As FaceDumbRule
faceDumbRule2 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces2)
Dim rules2(0) As SelectionIntentRule
rules2(0) = faceDumbRule2
scCollector1.ReplaceRules(rules2, False)
M Nafis
re: remove selection stickiness
I think all the above code would be replaced by:
faceDumbRule2 = workPart.ScRuleFactory.CreateRuleFaceDumb(myPlanarFaces)
Dim rules2(0) As SelectionIntentRule
rules2(0) = faceDumbRule2
scCollector1.ReplaceRules(rules2, False)
Though I bet it is going to be more involved than that, hard to tell from the small code snippet posted. Feel free to email your code to info@nxjournaling.com and I'll take a closer look.
Message not showing
I copied the the exact same code the author posted.. it ran properly except in the message in is showing "Name" under title and not showing the "Select a planar face"... I am using NX 8.
Anyone know what is going wrong?
Thanks
Fathmi
Regards,
MFJ
re: select message
I'm not sure which code snippet you are referring to; could you post the timestamp info of the post that contains the code, or post the code that you are running?
Below is the portion of the
Below is the portion of the Code I was using.. I am getting the title but not the message text... in the massage field it is just showing "NAME". Please advice.
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a planar face"
Dim message As String = "Select a planar 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.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _
title, message, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
Regards,
MFJ
re: message
The message that you pass in does not appear inside the dialog box, rather it appears in the cue/status line of NX. The cue/status line appears at the top or bottom of your NX graphics screen depending on your preference (I think the default is the bottom of the screen).
Open an NX file and start the 'extrude' command; check the bottom (or top) left corner of the screen for the message "Select section geometry". This is the cue/status line; it is where the message you pass in will appear.
I agree that it would be nice if the message appeared in the dialog box itself, but the cue/status line is a holdover from older versions of UG/NX. It is some of the 'baggage' of older versions that we have to deal with. However, if you have a UI styler license, you can create your own modern looking selection dialog box and put the text where you want it.
Thanks for the reply. In my
Thanks for the reply. In my case it is appearing on top. I will try the UI styler for better instruction.
Regards,
MFJ