Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

"flipping" an object to another layer

Status
Not open for further replies.

pittbuck

Computer
May 1, 2017
31
0
0
US
Hello fellow NX journal people,

My goal is to take an object that is oriented according to a coordinate system on one layer (layer 151) and make a copy of the object. This copied object will need to be orientated to the absolute coordinate system (for milling purposes). Below are the goals for this journal and I hope that I can get some direction as to what journals to explore.

-specify the "from" csys as the coordinate system on layer 151
-specify the "to" csys as the absolute coordinate system
-copy the object from 180 to 195

I hope that this is adequate enough detail for what I'm looking to do. Below is the journal that is created when I record myself doing the transform function and am curious what needs adjusting so that it works on any file that I have. THANKS!!

Code:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Edit->Move Object...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_MoveObject As Features.MoveObject = Nothing


If Not workPart.Preferences.Modeling.GetHistoryMode Then
    Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim moveObjectBuilder1 As Features.MoveObjectBuilder
moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(nullFeatures_MoveObject)

Dim unit1 As Unit
unit1 = moveObjectBuilder1.TransformMotion.RadialOriginDistance.Units

Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression3 As Expression
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression4 As Expression
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression5 As Expression
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression6 As Expression
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression7 As Expression
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression8 As Expression
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression9 As Expression
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression10 As Expression
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression11 As Expression
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression12 As Expression
expression12 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression13 As Expression
expression13 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression14 As Expression
expression14 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression15 As Expression
expression15 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression16 As Expression
expression16 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression17 As Expression
expression17 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression18 As Expression
expression18 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression19 As Expression
expression19 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression20 As Expression
expression20 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression21 As Expression
expression21 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression22 As Expression
expression22 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression23 As Expression
expression23 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression24 As Expression
expression24 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression25 As Expression
expression25 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression26 As Expression
expression26 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression27 As Expression
expression27 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression28 As Expression
expression28 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.AxisOption = GeometricUtilities.OrientXpressBuilder.Axis.Passive

moveObjectBuilder1.TransformMotion.DistanceAngle.OrientXpress.PlaneOption = GeometricUtilities.OrientXpressBuilder.Plane.Passive

moveObjectBuilder1.TransformMotion.OrientXpress.AxisOption = GeometricUtilities.OrientXpressBuilder.Axis.Passive

moveObjectBuilder1.TransformMotion.OrientXpress.PlaneOption = GeometricUtilities.OrientXpressBuilder.Plane.Passive

Dim manipulatororigin1 As Point3d
manipulatororigin1 = moveObjectBuilder1.TransformMotion.ManipulatorOrigin

Dim manipulatormatrix1 As Matrix3x3
manipulatormatrix1 = moveObjectBuilder1.TransformMotion.ManipulatorMatrix

moveObjectBuilder1.TransformMotion.Option = GeometricUtilities.ModlMotion.Options.CsysToCsys

moveObjectBuilder1.MoveObjectResult = Features.MoveObjectBuilder.MoveObjectResultOptions.CopyOriginal

moveObjectBuilder1.LayerOption = Features.MoveObjectBuilder.LayerOptionType.AsSpecified

moveObjectBuilder1.Layer = 195

moveObjectBuilder1.TransformMotion.DistanceValue.RightHandSide = "1"

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "5"

theSession.SetUndoMarkName(markId1, "Move Object Dialog")

Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector1 As Vector3d = New Vector3d(-0.0, -0.0, -1.0)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToVector = direction1

Dim body1 As Body = CType(workPart.Bodies.FindObject("SWEEP(18)"), Body)

Dim added1 As Boolean
added1 = moveObjectBuilder1.ObjectToMoveObject.Add(body1)

Dim scaleAboutPoint1 As Point3d = New Point3d(15.4966957625701, -5.20143723512192, 0.0)
Dim viewCenter1 As Point3d = New Point3d(-15.4966957625701, 5.2014372351219, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint1, viewCenter1)

Dim scaleAboutPoint2 As Point3d = New Point3d(12.3973566100561, -4.16114978809754, 0.0)
Dim viewCenter2 As Point3d = New Point3d(-12.3973566100561, 4.16114978809752, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint2, viewCenter2)

Dim scaleAboutPoint3 As Point3d = New Point3d(9.91788528804488, -3.32891983047803, 0.0)
Dim viewCenter3 As Point3d = New Point3d(-9.91788528804486, 3.32891983047801, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint3, viewCenter3)

Dim scaleAboutPoint4 As Point3d = New Point3d(7.9343082304359, -2.66313586438243, 0.0)
Dim viewCenter4 As Point3d = New Point3d(-7.93430823043587, 2.6631358643824, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint4, viewCenter4)

Dim scaleAboutPoint5 As Point3d = New Point3d(6.34744658434873, -2.13050869150595, 0.0)
Dim viewCenter5 As Point3d = New Point3d(-6.34744658434871, 2.13050869150592, 0.0)
workPart.ModelingViews.WorkView.ZoomAboutPoint(1.25, scaleAboutPoint5, viewCenter5)

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(workPart.FindObject("HANDLE R-155092"), CartesianCoordinateSystem)

Dim xform1 As Xform
xform1 = workPart.Xforms.CreateXform(cartesianCoordinateSystem1, SmartObject.UpdateOption.WithinModeling)

Dim cartesianCoordinateSystem2 As CartesianCoordinateSystem
cartesianCoordinateSystem2 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.FromCsys = cartesianCoordinateSystem2

Dim xform2 As Xform
xform2 = workPart.Xforms.CreateXform(SmartObject.UpdateOption.WithinModeling, 1.0)

Dim cartesianCoordinateSystem3 As CartesianCoordinateSystem
cartesianCoordinateSystem3 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToCsys = cartesianCoordinateSystem3

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Move Object")

Dim nXObject1 As NXObject
nXObject1 = moveObjectBuilder1.Commit()

Dim objects1() As NXObject
objects1 = moveObjectBuilder1.GetCommittedObjects()

theSession.DeleteUndoMark(markId2, Nothing)

theSession.SetUndoMarkName(markId1, "Move Object")

moveObjectBuilder1.Destroy()

workPart.Expressions.Delete(expression3)

workPart.Expressions.Delete(expression4)

workPart.Expressions.Delete(expression10)

workPart.Expressions.Delete(expression11)

workPart.Expressions.Delete(expression12)

workPart.Expressions.Delete(expression19)

workPart.Expressions.Delete(expression20)

workPart.Expressions.Delete(expression1)

workPart.Expressions.Delete(expression2)

workPart.Expressions.Delete(expression5)

workPart.Expressions.Delete(expression6)

workPart.Expressions.Delete(expression9)

workPart.Expressions.Delete(expression15)

workPart.Expressions.Delete(expression18)

workPart.Expressions.Delete(expression23)

workPart.Expressions.Delete(expression24)

workPart.Expressions.Delete(expression25)

workPart.Expressions.Delete(expression7)

workPart.Expressions.Delete(expression8)

workPart.Expressions.Delete(expression13)

workPart.Expressions.Delete(expression14)

workPart.Expressions.Delete(expression16)

workPart.Expressions.Delete(expression17)

workPart.Expressions.Delete(expression21)

workPart.Expressions.Delete(expression22)

workPart.Expressions.Delete(expression28)

workPart.Expressions.Delete(expression26)

workPart.Expressions.Delete(expression27)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
 
Replies continue below

Recommended for you

Tomas,

Just wanting to reduce the number of tasks that need to be done manually to help streamline. This particular task isn't a high priority, but would be nice to be able to do. This would be added on to another journal that I already use several times a day.

And yes. The FROM coordinate system would be a csys that is on layer 151 (by itself) and the TO coordinate system would be the absolute csys.

Thanks,
Zach
 
Status
Not open for further replies.
Back
Top