Create surface finish symbol - vb journal
Create surface finish symbol - vb journal
(OP)
thread561-383387: Create surface finish symbol - journal
Hi,
i fount this Code here that creates a surface finish symbol in a Drawing on edges from a Body.
As requested in the original Thread i also need to add this symbols on Dimensions and additional on GD&T.
Unfortunatelly the given Solution from cowski will run into an error in Line 30.
I think there must be changed something additional to get his change running fine.
But i am not familiar enough to find out what with this.
Can somebody help me out?
The original Thread:
Link
The given optimization as result of the original Thread:
Modifying your "select_a_curve_in_view" function to add another selection mask will allow you to select dimensions.
The original Code:
Regards, Frank
Hi,
i fount this Code here that creates a surface finish symbol in a Drawing on edges from a Body.
As requested in the original Thread i also need to add this symbols on Dimensions and additional on GD&T.
Unfortunatelly the given Solution from cowski will run into an error in Line 30.
I think there must be changed something additional to get his change running fine.
But i am not familiar enough to find out what with this.
Can somebody help me out?
The original Thread:
Link
The given optimization as result of the original Thread:
Modifying your "select_a_curve_in_view" function to add another selection mask will allow you to select dimensions.
CODE -->
With mask(4)
.Type = UFConstants.UF_dimension_type
.Subtype = UFConstants.UF_all_subtype
End With The original Code:
CODE --> vb
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Drawings
Module create_surface_finish_symbol
Private theSession As Session = Session.GetSession()
Private ufs As UFSession = UFSession.GetUFSession()
Private theUI As UI = UI.GetUI()
Private workPart As Part = theSession.Parts.Work
Private displayPart As Part = theSession.Parts.Display
Private lw As ListingWindow = theSession.ListingWindow
Sub Main(ByVal args() As String)
Dim edge1 As DisplayableObject = Nothing
Dim view1 As DraftingView = Nothing
Dim vwname As String = Nothing
Dim cursor As Point3d = Nothing
Dim obj_coords As Point3d = Nothing
Dim cur_coords As Point3d = Nothing
Dim nr As Integer = 1
lw.Open()
While select_a_curve_in_view("Select an edge in drafting view", edge1, cursor) = Selection.Response.Ok
ufs.Ui.AskLastPickedView(vwname)
view1 = CType(workPart.DraftingViews.FindObject(vwname), Drawings.DraftingView)
obj_coords = get_position_on_object(edge1, view1, cursor)
Dim screen_pos As Point3d
If select_screen_pos(screen_pos) <> Selection.Response.Ok Then
Return
End If
create_sf_symbol(edge1, obj_coords, screen_pos, view1)
End While
End Sub
Function get_position_on_object(ByVal obj As DisplayableObject, ByVal aView As View, ByRef coords As Point3d)
Dim guess1 As Double() = New Double(2) {}
Dim pt1 As Double() = New Double(2) {}
Dim pt2 As Double() = New Double(2) {}
Dim min_dist As Double
Dim loc_view As Point3d = MapAbs2View(aView, coords)
Dim sp_view As New Point3d(loc_view.X, loc_view.Y, loc_view.Z + 1000)
Dim ep_view As New Point3d(loc_view.X, loc_view.Y, loc_view.Z - 1000)
Dim sp_abs As Point3d = MapView2Abs(aView, sp_view)
Dim ep_abs As Point3d = MapView2Abs(aView, ep_view)
Dim line1 As Line = theSession.Parts.Work.Curves.CreateLine(sp_abs, ep_abs)
line1.SetVisibility(NXOpen.SmartObject.VisibilityOption.Visible)
line1.RedisplayObject()
ufs.Modl.AskMinimumDist(obj.Tag, line1.Tag, 0, guess1, 0, guess1, min_dist, pt1, pt2)
Dim markId2 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")
theSession.UpdateManager.AddToDeleteList(line1)
theSession.UpdateManager.DoUpdate(markId2)
get_position_on_object = New Point3d(pt1(0), pt1(1), pt1(2))
End Function
Function MapView2Abs(ByVal aView As View, ByVal coords As Point3d)
Dim vmx As Matrix3x3 = aView.Matrix
Dim vw() As Double = {0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim mx(11) As Double
Dim irc As Integer
Dim c() As Double = {coords.X, coords.Y, coords.Z}
ufs.Trns.CreateCsysMappingMatrix(vw, abs, mx, irc)
ufs.Trns.MapPosition(c, mx)
MapView2Abs = New Point3d(c(0), c(1), c(2))
End Function
Function MapAbs2View(ByVal aView As View, ByVal coords As Point3d)
Dim vmx As Matrix3x3 = aView.Matrix
Dim vw() As Double = {0, 0, 0, vmx.Xx, vmx.Xy, vmx.Xz, vmx.Yx, vmx.Yy, vmx.Yz}
Dim abs() As Double = {0, 0, 0, 1, 0, 0, 0, 1, 0}
Dim mx(11) As Double
Dim irc As Integer
Dim c() As Double = {coords.X, coords.Y, coords.Z}
ufs.Trns.CreateCsysMappingMatrix(abs, vw, mx, irc)
ufs.Trns.MapPosition(c, mx)
MapAbs2View = New Point3d(c(0), c(1), c(2))
End Function
Function create_sf_symbol(ByVal edge1 As DisplayableObject, ByVal origin As Point3d, _
ByVal screen_pos As Point3d, ByVal view1 As DraftingView)
Dim nullAnDrafSF As Annotations.DraftingSurfaceFinish = Nothing
Dim SurfFinish As Annotations.DraftingSurfaceFinishBuilder
Dim LeaderData As Annotations.LeaderData = workPart.Annotations.CreateLeaderData()
Dim nullView As View = Nothing
Dim model_pt As Double() = {origin.X, origin.Y, origin.Z}
Dim map_pt As Double() = New Double(1) {}
ufs.View.MapModelToDrawing(view1.Tag, model_pt, map_pt)
SurfFinish = workPart.Annotations.DraftingSurfaceFinishSymbols.CreateDraftingSurfaceFinishBuilder(nullAnDrafSF)
SurfFinish.Finish = Annotations.DraftingSurfaceFinishBuilder.FinishType.ModifierMaterialRemovalRequired
SurfFinish.Origin.SetInferRelativeToGeometry(True)
SurfFinish.A2 = "0.32"
SurfFinish.Style.LetteringStyle.GeneralTextSize = 2.5
If map_pt(1) < screen_pos.Y Then
SurfFinish.InvertText = False
SurfFinish.InvertSymbol = False
ElseIf map_pt(0) < screen_pos.X Then
SurfFinish.InvertText = True
SurfFinish.InvertSymbol = True
ElseIf map_pt(1) > screen_pos.Y Then
SurfFinish.InvertText = True
SurfFinish.InvertSymbol = True
ElseIf map_pt(0) > screen_pos.X Then
SurfFinish.InvertText = False
SurfFinish.InvertSymbol = False
End If
LeaderData.TerminatorType = Annotations.LeaderData.LeaderType.Flag
LeaderData.Leader.SetValue(edge1, view1, origin)
SurfFinish.Leader.Leaders.Append(LeaderData)
SurfFinish.Origin.Origin.SetValue(Nothing, nullView, screen_pos)
Dim nXObject1 As NXObject
nXObject1 = SurfFinish.Commit()
SurfFinish.Destroy()
End Function
Function select_a_curve_in_view(ByVal prompt As String, ByRef obj As DisplayableObject, ByRef cursor As Point3d)
Dim mask(3) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_line_type
.Subtype = 0
.SolidBodySubtype = 0
End With
With mask(1)
.Type = UFConstants.UF_section_edge_type
.Subtype = 0
.SolidBodySubtype = 0
End With
With mask(2)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE
End With
With mask(3)
.Type = UFConstants.UF_solid_silhouette_type
.Subtype = 0
.SolidBodySubtype = 0
End With
'With mask(4)
' .Type = UFConstants.UF_conic_type
' .Subtype = 0
' .SolidBodySubtype = 0
'End With
'With mask(5)
' .Type = UFConstants.UF_spline_type
' .Subtype = 0
' .SolidBodySubtype = 0
'End With
' With mask(6)
'.Type = UFConstants.UF_circle_type
'.Subtype = 0
'.SolidBodySubtype = 0
'End With
Dim ufs As UFSession = UFSession.GetUFSession()
ufs.Ui.SetCursorView(0)
Dim resp As Selection.Response = _
theUI.SelectionManager.SelectTaggedObject(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, obj, 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
Function select_screen_pos(ByRef loc As Point3d) As Selection.Response
Dim resp As Selection.DialogResponse = Selection.DialogResponse.None
Dim localView As View
ufs.Ui.SetCursorView(1)
resp = theUI.SelectionManager.SelectScreenPosition("Screen Position:", _
localView, loc)
If resp <> Selection.DialogResponse.Back And _
resp <> Selection.DialogResponse.Cancel Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module Regards, Frank





RE: Create surface finish symbol - vb journal
If you add the mask triple that I suggested, you will also need to change the mask array declaration so that it is big enough to hold the new mask triple.
Change line 164 to the following:
CODE
Beyond that, it looks like the error is as I predicted. The journal in its current state only handles drafting views. When a dimension is selected, the sheet view is returned and the journal errors out because it expects a drafting view.
www.nxjournaling.com
RE: Create surface finish symbol - vb journal
that was a really fast answer. Thank you.
I implemented your modification and can select Dimensions also. Thats a first step.
Unfortunatelly i can not select GD&T. Is this selectable with an additional mask?
But with your modification i got now a new error.
If i select a Dimension the Code give me the Error:
No Object found with this Name.
The Problem is in Line 32.
This is Line 32:
CODE -->
Did you have an idea how to fix this new error and in addition how to implement the GD&T as selection?
The error message seems to tell nothing with your named problem in View/Sheet.
If you will have a solution it will be absolute perfect
Kind regards,
Frank
RE: Create surface finish symbol - vb journal
Since i don't understand the code to the extent that i can tell the difference from what NX OOTB does.
Many years back, Surface finish symbols in NX was an add on program that somebody had written and was added to the install.
One had to set an environment variable to see the function in NX.
Regards,
Tomas
RE: Create surface finish symbol - vb journal
I would be interested in knowing what this code adds to the already existing functionality of Surface finish symbols...
Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2
Building new PLM environment from Scratch using NX11 / TC11
RE: Create surface finish symbol - vb journal
- allows the user to select a curve in a drafting view
- calculates a point on the curve nearest the pick point
- places a surface finish symbol on the calculated point
Modifying the selection function to allow the user to select a dimension or GD&T is easy. Fixing the view error when a dimension or GD&T is selected would be a bit more work. Calculating the point on the dimension or GD&T would be the tricky part (doable, but there are a lot of cases to consider).I'm reluctant to spend any time on this journal because, like Toost and NutAce, I don't really see what value this journal brings above and beyond the normal surface finish command. I don't often use the surface finish command, so perhaps I'm missing something obvious?
www.nxjournaling.com
RE: Create surface finish symbol - vb journal
first i want to say thank you for your commends and information.
Our main point is to reduce hundreds of clicks for the user in every Drawing we create.
The OOTB Function needs some clicks for every Symbol.
With this Code here this is reduced to just 1 click per Symbol.
So i am really interessted in this optimization
I realized that the selection function must be recreated!
Thank you cowski for this finger point.
In the last days i searched in every Forum, google u.s.o. that i found for some special tips.
Unfortunately i dont found an entry point for myself.
@cowski:
Can you give me some tips in functions that i need to use and additional give me some information what i have to look for? Than i want to try my own optimization in this code.
This would be extreme helpfull.
Regards, Frank
RE: Create surface finish symbol - vb journal
If you want to place the symbol on a dimension extension line, you will need to get information about the dimension components. This journal makes use of the Annotations.ComponentData to get a point on the dimension extension line (see the GetExtensionLines subroutine).
I'd also suggest having a look at GTAC's solution center; they have many code samples available there.
www.nxjournaling.com