Altojoe
New member
- Mar 16, 2013
- 23
Hi,
I Have following conditions to be Changed to Code.
1. I have a Axis and movement value along the axis I want Translation Vector for this.
2. I have a axis Which need to be converted to Double in this format "Dim MyAxis as Double ={Axis.XXX, Axis.YYY, Axis.ZZZ}" it is to find Rotation Matrix for DragbyTransform method.
If MovementType = "Fixed" Then
Continue For
ElseIf MovementType = "Alongaxis" Then
Dim NewAxis As NXOpen.Axis = Nothing
For Each Myaxis As NXOpen.Axis In workPart.Axes
Try
If Myaxis.GetStringAttribute("Curve Name") = "MovementReference" Then
NewAxis = Myaxis
End If
Catch ex As NXException
End Try
Next
componentPositioner1.BeginMoveComponent()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
componentNetwork1.NonMovingGroupGrounded = True
componentNetwork1.MoveObjectsState = True
componentNetwork1.RemoveAllConstraints()
componentNetwork1.SetMovingGroup(GroupObjects)
Dim loaded1 As Boolean
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()
componentNetwork1.BeginDrag()
Dim translation1 As Vector3d = New Vector3d(0.1, 0, 0) 'Instead of New Vector3D, This Should Be generated from Newaxis and input value like 25 mm in NewAxis
componentNetwork1.DragByTranslation(translation1)
componentNetwork1.EndDrag()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
componentPositioner1.DeleteNonPersistentConstraints()
componentPositioner1.EndMoveComponent()
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
ElseIf MovementType = "Aboutaxis" Then
Dim NewAxis As NXOpen.Axis = Nothing
For Each Myaxis As NXOpen.Axis In workPart.Axes
Try
If Myaxis.GetStringAttribute("Curve Name") = "MovementReference" Then
NewAxis = Myaxis
End If
Catch ex As NXException
End Try
Next
MsgBox("Got the Axis")
Dim AboutPoints() As String = Split(MovementPivot, " ", 3)
Dim RotPoint() As Double = {AboutPoints(0), AboutPoints(1), AboutPoints(2)}
Dim RotAxis() As Double = {NewAxis.DirectionVector.X, NewAxis.DirectionVector.Y, NewAxis.DirectionVector.Z} 'This I want to get from New Axis
Dim RotAngle As Double = MovementValue
Dim RotMatr4D(15) As Double
Dim RotMatr3D(8) As Double
Dim TransVec(2) As Double
ufs.Mtx4.Rotation(RotPoint, RotAxis, RotAngle, RotMatr4D)
ufs.Mtx4.AskRotation(RotMatr4D, RotMatr3D)
ufs.Mtx4.AskTranslation(RotMatr4D, TransVec)
Dim RotMatr As Matrix3x3 = convertToMatrix3x3(RotMatr3D)
componentPositioner1.BeginMoveComponent()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
componentNetwork1.NonMovingGroupGrounded = True
componentNetwork1.MoveObjectsState = True
componentNetwork1.RemoveAllConstraints()
componentNetwork1.SetMovingGroup(GroupObjects)
Dim loaded1 As Boolean
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()
componentNetwork1.BeginDrag()
Dim translation1 As Vector3d = New Vector3d(TransVec(0), TransVec(1), TransVec(2))
componentNetwork1.DragByTransform(translation1, RotMatr)
componentNetwork1.EndDrag()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
componentPositioner1.DeleteNonPersistentConstraints()
componentPositioner1.EndMoveComponent()
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
End If
I Have following conditions to be Changed to Code.
1. I have a Axis and movement value along the axis I want Translation Vector for this.
2. I have a axis Which need to be converted to Double in this format "Dim MyAxis as Double ={Axis.XXX, Axis.YYY, Axis.ZZZ}" it is to find Rotation Matrix for DragbyTransform method.
If MovementType = "Fixed" Then
Continue For
ElseIf MovementType = "Alongaxis" Then
Dim NewAxis As NXOpen.Axis = Nothing
For Each Myaxis As NXOpen.Axis In workPart.Axes
Try
If Myaxis.GetStringAttribute("Curve Name") = "MovementReference" Then
NewAxis = Myaxis
End If
Catch ex As NXException
End Try
Next
componentPositioner1.BeginMoveComponent()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
componentNetwork1.NonMovingGroupGrounded = True
componentNetwork1.MoveObjectsState = True
componentNetwork1.RemoveAllConstraints()
componentNetwork1.SetMovingGroup(GroupObjects)
Dim loaded1 As Boolean
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()
componentNetwork1.BeginDrag()
Dim translation1 As Vector3d = New Vector3d(0.1, 0, 0) 'Instead of New Vector3D, This Should Be generated from Newaxis and input value like 25 mm in NewAxis
componentNetwork1.DragByTranslation(translation1)
componentNetwork1.EndDrag()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
componentPositioner1.DeleteNonPersistentConstraints()
componentPositioner1.EndMoveComponent()
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
ElseIf MovementType = "Aboutaxis" Then
Dim NewAxis As NXOpen.Axis = Nothing
For Each Myaxis As NXOpen.Axis In workPart.Axes
Try
If Myaxis.GetStringAttribute("Curve Name") = "MovementReference" Then
NewAxis = Myaxis
End If
Catch ex As NXException
End Try
Next
MsgBox("Got the Axis")
Dim AboutPoints() As String = Split(MovementPivot, " ", 3)
Dim RotPoint() As Double = {AboutPoints(0), AboutPoints(1), AboutPoints(2)}
Dim RotAxis() As Double = {NewAxis.DirectionVector.X, NewAxis.DirectionVector.Y, NewAxis.DirectionVector.Z} 'This I want to get from New Axis
Dim RotAngle As Double = MovementValue
Dim RotMatr4D(15) As Double
Dim RotMatr3D(8) As Double
Dim TransVec(2) As Double
ufs.Mtx4.Rotation(RotPoint, RotAxis, RotAngle, RotMatr4D)
ufs.Mtx4.AskRotation(RotMatr4D, RotMatr3D)
ufs.Mtx4.AskTranslation(RotMatr4D, TransVec)
Dim RotMatr As Matrix3x3 = convertToMatrix3x3(RotMatr3D)
componentPositioner1.BeginMoveComponent()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
componentNetwork1.NonMovingGroupGrounded = True
componentNetwork1.MoveObjectsState = True
componentNetwork1.RemoveAllConstraints()
componentNetwork1.SetMovingGroup(GroupObjects)
Dim loaded1 As Boolean
loaded1 = componentNetwork1.IsReferencedGeometryLoaded()
componentNetwork1.BeginDrag()
Dim translation1 As Vector3d = New Vector3d(TransVec(0), TransVec(1), TransVec(2))
componentNetwork1.DragByTransform(translation1, RotMatr)
componentNetwork1.EndDrag()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
componentPositioner1.DeleteNonPersistentConstraints()
componentPositioner1.EndMoveComponent()
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
End If