Edit an exploded view
Edit an exploded view
(OP)
Hi
I have an exploded view with a component exploded in a rotated position
but I forgot the rotating hinge and the rotating angle and now
I want to explode another component with the same rotation
As like I have selected them both in the original explosion
Please any help or trick ?
Thanks in advanced





RE: Edit an exploded view
USING NX8.5
RE: Edit an exploded view
www.nxjournaling.com
RE: Edit an exploded view
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.BaseWork) 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 = "report component explosion" Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Dim explosionTag As Tag = Tag.Null Dim explosion As Assemblies.Explosion theUfSession.Assem.AskViewExplosion(theSession.Parts.Display.ModelingViews.WorkView.Tag, explosionTag) lw.WriteLine("current work view: " & theSession.Parts.Display.ModelingViews.WorkView.Name) If explosionTag = Tag.Null Then lw.WriteLine(" no explosion associated with the current work view") Return Else explosion = Utilities.NXObjectManager.Get(explosionTag) lw.WriteLine(" explosion: " & explosion.Name) End If lw.WriteLine("") Dim explodedComp As Assemblies.Component = Nothing If SelectComponent("Select a component", explodedComp) = Selection.Response.Cancel Then Return End If lw.WriteLine("component: " & explodedComp.DisplayName) Dim explosionStatus As UFAssem.ExplStatus Dim explosionTransform(3, 3) As Double theUfSession.Assem.AskCompExplosion(explosionTag, explodedComp.Tag, explosionStatus, explosionTransform) lw.WriteLine(" explosion status: " & explosionStatus.ToString) 'lw.WriteLine(explosionTransform(0, 0) & ", " & explosionTransform(0, 1) & ", " & explosionTransform(0, 2) & ", " & explosionTransform(0, 3)) 'lw.WriteLine(explosionTransform(1, 0) & ", " & explosionTransform(1, 1) & ", " & explosionTransform(1, 2) & ", " & explosionTransform(1, 3)) 'lw.WriteLine(explosionTransform(2, 0) & ", " & explosionTransform(2, 1) & ", " & explosionTransform(2, 2) & ", " & explosionTransform(2, 3)) 'lw.WriteLine(explosionTransform(3, 0) & ", " & explosionTransform(3, 1) & ", " & explosionTransform(3, 2) & ", " & explosionTransform(3, 3)) Dim rotAngleX As Double Dim rotAngleY As Double Dim rotAngleZ As Double ExplodedCompRot(explosionTransform, rotAngleX, rotAngleY, rotAngleZ) lw.WriteLine(" rotation about X axis: " & rotAngleX.ToString) lw.WriteLine(" rotation about Y axis: " & rotAngleY.ToString) lw.WriteLine(" rotation about Z axis: " & rotAngleZ.ToString) lw.Close() End Sub Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select a component" 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_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 OrElse resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Sub ExplodedCompRot(ByVal transformMatrix(,) As Double, ByRef RX1 As Double, ByRef RY1 As Double, ByRef RZ1 As Double) 'extract euler angles from rotation matrix: 'https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2012/07/euler-angles.pdf Dim RotMat As Matrix3x3 RotMat.Xx = transformMatrix(0, 0) RotMat.Xy = transformMatrix(0, 1) RotMat.Xz = transformMatrix(0, 2) RotMat.Yx = transformMatrix(1, 0) RotMat.Yy = transformMatrix(1, 1) RotMat.Yz = transformMatrix(1, 2) RotMat.Zx = transformMatrix(2, 0) RotMat.Zy = transformMatrix(2, 1) RotMat.Zz = transformMatrix(2, 2) Dim c1, c2, s1 As Double RX1 = Math.Atan2(RotMat.Yz, RotMat.Zz) c2 = Math.Sqrt(RotMat.Xx ^ 2 + RotMat.Xy ^ 2) RY1 = Math.Atan2(-RotMat.Xz, c2) s1 = Math.Sin(RX1) c1 = Math.Cos(RX1) RZ1 = Math.Atan2(s1 * RotMat.Zx - c1 * RotMat.Yx, c1 * RotMat.Yy - s1 * RotMat.Zy) 'convert angles from radians to degrees RX1 *= -(180 / Math.PI) RY1 *= -(180 / Math.PI) RZ1 *= -(180 / Math.PI) End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Modulewww.nxjournaling.com
RE: Edit an exploded view
Hi Cowski
Thank you very much for your response
I tested your journal on an exploded view as follows
I rotated a comopnent about the Z axis 30 deg and then I moved the CSYS to some place
and then I run your journal and I got this output
current work view: xploded1
explosion: Explosion 1
component: v04_pivot_small_4
explosion status: Exploded
rotation about X axis: 0
rotation about Y axis: 0
rotation about Z axis: -30
The angle is OK but I have not the origin where the actual rotation done
Thanks
RE: Edit an exploded view
www.nxjournaling.com
RE: Edit an exploded view
Ah its OK
Thank you very much
RE: Edit an exploded view
If you add a new instance of the chosen component at the absolute origin of the assembly file then use the 'move component' command (dynamic motion) and apply the reported rotation about the dynamic X axis, then apply the reported rotation about the dynamic Y axis, and finally apply the reported rotation about the dynamic Z axis and the resulting orientation of the newly added component will match that of the exploded component.
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module2 Sub Main() Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() If IsNothing(theSession.Parts.BaseWork) 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 = "report component explosion" Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Dim explosionTag As Tag = Tag.Null Dim explosion As Assemblies.Explosion theUfSession.Assem.AskViewExplosion(theSession.Parts.Display.ModelingViews.WorkView.Tag, explosionTag) lw.WriteLine("current work view: " & theSession.Parts.Display.ModelingViews.WorkView.Name) If explosionTag = Tag.Null Then lw.WriteLine(" no explosion associated with the current work view") Return Else explosion = Utilities.NXObjectManager.Get(explosionTag) lw.WriteLine(" explosion: " & explosion.Name) End If lw.WriteLine("") Dim explodedComp As Assemblies.Component = Nothing If SelectComponent("Select a component", explodedComp) = Selection.Response.Cancel Then Return End If lw.WriteLine("component: " & explodedComp.DisplayName) Dim explosionStatus As UFAssem.ExplStatus Dim explosionTransform(3, 3) As Double 'component transform w.r.t. component part ACS theUfSession.Assem.AskCompExplosion(explosionTag, explodedComp.Tag, explosionStatus, explosionTransform) lw.WriteLine(" explosion status: " & explosionStatus.ToString) 'lw.WriteLine(explosionTransform(0, 0) & ", " & explosionTransform(0, 1) & ", " & explosionTransform(0, 2) & ", " & explosionTransform(0, 3)) 'lw.WriteLine(explosionTransform(1, 0) & ", " & explosionTransform(1, 1) & ", " & explosionTransform(1, 2) & ", " & explosionTransform(1, 3)) 'lw.WriteLine(explosionTransform(2, 0) & ", " & explosionTransform(2, 1) & ", " & explosionTransform(2, 2) & ", " & explosionTransform(2, 3)) 'lw.WriteLine(explosionTransform(3, 0) & ", " & explosionTransform(3, 1) & ", " & explosionTransform(3, 2) & ", " & explosionTransform(3, 3)) Dim rotAngleX As Double Dim rotAngleY As Double Dim rotAngleZ As Double ExplodedCompRot(explosionTransform, rotAngleX, rotAngleY, rotAngleZ) lw.WriteLine(" rotation about component X axis: " & rotAngleX.ToString) lw.WriteLine(" rotation about component Y axis: " & rotAngleY.ToString) lw.WriteLine(" rotation about component Z axis: " & rotAngleZ.ToString) lw.WriteLine("") Dim explodedCompPosition(3, 3) As Double 'total absolute transform of the component in the given explosion. theUfSession.Assem.AskCompPosition(explosionTag, explodedComp.Tag, explodedCompPosition) Dim compRotAngleX As Double Dim compRotAngleY As Double Dim compRotAngleZ As Double ExplodedCompRot(explodedCompPosition, compRotAngleX, compRotAngleY, compRotAngleZ) lw.WriteLine(" rotation about absolute X axis: " & compRotAngleX.ToString) lw.WriteLine(" rotation about absolute Y axis: " & compRotAngleY.ToString) lw.WriteLine(" rotation about absolute Z axis: " & compRotAngleZ.ToString) lw.Close() End Sub Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select a component" 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_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 OrElse resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Sub ExplodedCompRot(ByVal transformMatrix(,) As Double, ByRef RX1 As Double, ByRef RY1 As Double, ByRef RZ1 As Double) 'extract euler angles from rotation matrix: 'https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2012/07/euler-angles.pdf Dim RotMat As Matrix3x3 RotMat.Xx = transformMatrix(0, 0) RotMat.Xy = transformMatrix(0, 1) RotMat.Xz = transformMatrix(0, 2) RotMat.Yx = transformMatrix(1, 0) RotMat.Yy = transformMatrix(1, 1) RotMat.Yz = transformMatrix(1, 2) RotMat.Zx = transformMatrix(2, 0) RotMat.Zy = transformMatrix(2, 1) RotMat.Zz = transformMatrix(2, 2) Dim c1, c2, s1 As Double RX1 = Math.Atan2(RotMat.Yz, RotMat.Zz) c2 = Math.Sqrt(RotMat.Xx ^ 2 + RotMat.Xy ^ 2) RY1 = Math.Atan2(-RotMat.Xz, c2) s1 = Math.Sin(RX1) c1 = Math.Cos(RX1) RZ1 = Math.Atan2(s1 * RotMat.Zx - c1 * RotMat.Yx, c1 * RotMat.Yy - s1 * RotMat.Zy) 'convert angles from radians to degrees RX1 *= -(180 / Math.PI) RY1 *= -(180 / Math.PI) RZ1 *= -(180 / Math.PI) End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Modulewww.nxjournaling.com
RE: Edit an exploded view
You do much for me
RE: Edit an exploded view