Kumaresh_07
Automotive
- Jul 21, 2019
- 14
Hi all,
Is there any way to copy a component from single csys to multiple csys?
please refer below mentioned journal code.If you guys run below journal ,you can move component from one csys to another csys.
I want to modify below journal as like below steps.
While run the journal,
Step 1)user going to select csys of component(From csys).
Step 2)user going to select destination csys's (Here user can select mutiple Csys's)
Result : the component placed in all csys's ,which i selected in step 2.
Thanks in Advance,
Kumaresh.
Is there any way to copy a component from single csys to multiple csys?
please refer below mentioned journal code.If you guys run below journal ,you can move component from one csys to another csys.
I want to modify below journal as like below steps.
While run the journal,
Step 1)user going to select csys of component(From csys).
Step 2)user going to select destination csys's (Here user can select mutiple Csys's)
Result : the component placed in all csys's ,which i selected in step 2.
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()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "reposition component"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim fromCsys As CoordinateSystem
Dim toCsys As CoordinateSystem
If SelectCsys("Select 'From' coordinate system", fromCsys) = Selection.Response.Cancel Then
Return
End If
If SelectCsys("Select 'To' coordinate system", toCsys) = Selection.Response.Cancel Then
Return
End If
'calculate Csys to Csys transformation matrix
Dim fromOrigin() As Double = {fromCsys.Origin.X, fromCsys.Origin.Y, fromCsys.Origin.Z}
Dim fromXAxis() As Double = {fromCsys.Orientation.Element.Xx, fromCsys.Orientation.Element.Xy, fromCsys.Orientation.Element.Xz}
Dim fromYAxis() As Double = {fromCsys.Orientation.Element.Yx, fromCsys.Orientation.Element.Yy, fromCsys.Orientation.Element.Yz}
Dim toOrigin() As Double = {toCsys.Origin.X, toCsys.Origin.Y, toCsys.Origin.Z}
Dim toXAxis() As Double = {toCsys.Orientation.Element.Xx, toCsys.Orientation.Element.Xy, toCsys.Orientation.Element.Xz}
Dim toYAxis() As Double = {toCsys.Orientation.Element.Yx, toCsys.Orientation.Element.Yy, toCsys.Orientation.Element.Yz}
Dim mtx4Transform(15) As Double
theUfSession.Mtx4.CsysToCsys(fromOrigin, fromXAxis, fromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform)
'extract the rotation matrix and the tranlsation vector
Dim rotMatrix(8) As Double
theUfSession.Mtx4.AskRotation(mtx4Transform, rotMatrix)
Dim transVec(2) As Double
theUfSession.Mtx4.AskTranslation(mtx4Transform, transVec)
'convert array of doubles to vector 3d
Dim translateVector As Vector3d = New Vector3d(transVec(0), transVec(1), transVec(2))
'convert array of doubles to Matrix3x3
Dim rotationMatrix As Matrix3x3 = convertToMatrix3x3(rotMatrix)
'determine component to move based on the chosen "from" csys
Dim comp As Assemblies.Component = fromCsys.OwningComponent
Dim componentPositioner1 As Positioning.ComponentPositioner = theSession.Parts.Work.ComponentAssembly.Positioner
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
Dim markId2 As Session.UndoMarkId = Nothing
If comp IsNot Nothing Then
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Move Component")
Dim movableObjects() As NXObject = {comp}
componentNetwork1.SetMovingGroup(movableObjects)
componentNetwork1.BeginDrag()
'reposition component from the rotation matrix and translation vector
componentNetwork1.DragByTransform(translateVector, rotationMatrix)
componentNetwork1.EndDrag()
componentNetwork1.ResetDisplay()
componentNetwork1.ApplyToModel()
componentNetwork1.Solve()
End If
theSession.UpdateManager.AddToDeleteList(componentNetwork1)
theSession.UpdateManager.DoUpdate(markId2)
lw.Close()
End Sub
Function SelectCsys(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a Coordinate system"
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_coordinate_system_type
.Subtype = UFConstants.UF_all_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 OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function convertToMatrix3x3(ByVal mtx As Double()) As Matrix3x3
Dim mx As Matrix3x3
With mx
.Xx = mtx(0)
.Xy = mtx(1)
.Xz = mtx(2)
.Yx = mtx(3)
.Yy = mtx(4)
.Yz = mtx(5)
.Zx = mtx(6)
.Zy = mtx(7)
.Zz = mtx(8)
End With
Return mx
End Function
End Module
Thanks in Advance,
Kumaresh.