OlafU
Automotive
- Jan 31, 2012
- 19
Hello all.
With the Journal below I can select a Component and the Journal gives out the Position in an Information Windows and is also editing existing expressions in the work part.
It works fine for coordinates as whole numbers. But if one coordinate is not a whole number the Journal do not change the expressions.
E.g. if the first coordinate is a whole number, the second not and the third coordinate again a whole number, the Journal only modifies the Expression for the first coordinate, the Output to the Information Windows still works perfectly.
Has someone a hint?
Thanks in Advance
Olaf
NX11.0.0
With the Journal below I can select a Component and the Journal gives out the Position in an Information Windows and is also editing existing expressions in the work part.
It works fine for coordinates as whole numbers. But if one coordinate is not a whole number the Journal do not change the expressions.
E.g. if the first coordinate is a whole number, the second not and the third coordinate again a whole number, the Journal only modifies the Expression for the first coordinate, the Output to the Information Windows still works perfectly.
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim myComponent As NXObject
lw.Open()
If SelectComponent("Select component", myComponent) = Selection.Response.Cancel Then
Return
End If
lw.WriteLine(myComponent.Name)
Dim compPt As Point3d = CompPos(myComponent)
lw.WriteLine(" X" & compPt.X.ToString & " Y" & compPt.Y.ToString & " Z" & compPt.Z.ToString)
lw.WriteLine("")
Try
Dim x_pos As Expression = CType(workPart.Expressions.FindObject("X_Pos"), Expression)
Dim y_pos As Expression = CType(workPart.Expressions.FindObject("Y_Pos"), Expression)
Dim z_pos As Expression = CType(workPart.Expressions.FindObject("Z_Pos"), Expression)
workPart.Expressions.Edit(x_pos, compPt.X)
workPart.Expressions.Edit(y_pos, compPt.Y)
workPart.Expressions.Edit(z_pos, compPt.Z)
Catch ex as NXException
if ex.ErrorCode = 3520016 Then
lw.WriteLine("Expression not found!")
end if
end try
End Sub
Function SelectComponent(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select component"
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.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
Dim cursor As Point3d
With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_component_subtype
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 Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function CompPos(ByVal someComponent As Component) As Point3d
Dim pt As Point3d
Dim RotMat As Matrix3x3
someComponent.GetPosition(pt, RotMat)
Return pt
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
Has someone a hint?
Thanks in Advance
Olaf
NX11.0.0