×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Copying Solids To A New Layer; Journal

Copying Solids To A New Layer; Journal

Copying Solids To A New Layer; Journal

(OP)
Hello. I'm trying to move a solid from layer 180 to 195, but flip it such that when I click CTRL-ALT-HOME, I can see the bottom of the solid. Presently, I am doing "Move Object" and I am using "CSYS to CSYS" as the motion. The "from CSYS" is a Datum CSYS on layer 42. The "to CSYS" is the absolute coordinate system. And, as obvious as it may sound, I also it set such that the result is a copied original specified to Layer 195.

Using the "record journal" tool, I get the following:

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 = "0.8"

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "0.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.316576442411312, -0.693544753222139, -0.647128295926117)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

Dim nullPoint As Point = Nothing

Dim axis1 As Axis
axis1 = workPart.Axes.CreateAxis(nullPoint, direction1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector2 As Vector3d = New Vector3d(-0.0, -0.0, -1.0)
Dim direction2 As Direction
direction2 = workPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToVector = direction2

Dim body1 As Body = CType(workPart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(117)"), Body)

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

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1 1"), 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 

I've done a little bit of journaling before, so I did manage to get the basic stuff changed. The issue just becomes where to go after this (note, this will be added on to another journal I have at a later date):

CODE -->

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic  
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module NXJournal

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUFSession As UFSession = UFSession.GetUFSession

'get list of solid bodies on given layer

Dim layerFlip As Integer = 180
Dim bodiesOnFlipLayer As New List(Of Body)

For Each temp As Body In workPart.Bodies  
	If temp.IsSolidBody Then  
      	If temp.Layer = layerFlip Then  
		 End If        
	End If
Next

' ----------------------------------------------
'   Menu: Edit->Move Object...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId  
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Move solids on layer " & layerFlip.ToString)  

Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

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 = "0.8"

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "0.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.316576442411312, -0.693544753222139, -0.647128295926117)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

Dim nullPoint As Point = Nothing

Dim axis1 As Axis
axis1 = workPart.Axes.CreateAxis(nullPoint, direction1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector2 As Vector3d = New Vector3d(-0.0, -0.0, -1.0)
Dim direction2 As Direction
direction2 = workPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToVector = direction2

Dim body1 As Body = CType(workPart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(117)"), Body)

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

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1 1"), 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 

The first highlighted portion is where I get a little lost in what the input needs to be. I'm assuming that I need to assign the CSYS on layer 42 at some point before this (maybe?). The second highlighted point, I'm assuming is where the "bodiesOnFlipLayer" would go. A little bit of guidance on how to clean this up would be much appreciated. Thank you.

RE: Copying Solids To A New Layer; Journal

When you iterate through the bodies and find one on the specified layer, you need to add it to the list:

CODE

Dim layerFlip As Integer = 180
Dim bodiesOnFlipLayer As New List(Of Body)

For Each temp As Body In workPart.Bodies  
    If temp.IsSolidBody Then  
      	If temp.Layer = layerFlip Then
            bodiesOnFlipLayer.Add(temp)
        End If        
    End If
Next 

Later in the code, you can add this list of bodies to the move object builder rather than the single body that was originally recorded:

CODE

Dim body1 As Body = CType(workPart.Bodies.FindObject("UNPARAMETERIZED_FEATURE(117)"), Body)

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

Similarly, you will need a way to find the datum csys that you want to use for the move operation. If there is some sort of way to identify it (only one on layer 42, or it has a specific attribute, etc), the journal can pick it up automatically. Alternatively, you can allow the user to select a csys.

Finally, there is a bunch of code that the journal recorder generates that isn't useful to what you want to do in this case. Near the end of the code, you will see it deletes a bunch of expressions that it created earlier. This is a good indication that these expressions are not needed. Comment out the lines that create and later delete the expressions and test the code to see if it still runs correctly. If it does, you can remove that code. Test other variables as well. When the journal recorder creates a variable and never uses it again, there is a good chance it isn't needed (for your specific task).

www.nxjournaling.com

RE: Copying Solids To A New Layer; Journal

(OP)
Cowski,

Thanks for that. The code is a lot simpler now. The part that I am trying to figure out now is identifying the "from CSYS" as the CSYS on layer42 (it is the only CSYS on that layer) and identifying the "to CSYS" as the ABSOLUTE CSYS. My thoughts are that it first needs to be identified in a separate thing of code, similar to how I identified the object on layer 180, then have this newly identified "object" referenced where it says "SmartObject.UpdateOption.WithinModeling" in the current code.

CODE -->

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic  
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module NXJournal

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUFSession As UFSession = UFSession.GetUFSession

Sub Main

'get list of solid bodies on given layer

Dim layerFlip as NXObject()
Dim myFlipObjects as DisplayableObject()
Dim l as Integer = 0

layerFlip = workPart.Layers.GetAllObjectsOnLayer(180)

for each someObject as NXObject in layerFlip
    if someObject.GetType.ToString = "NXOpen.Body" then
        redim preserve myFlipObjects(l)
        myFlipObjects(l) = someObject
        l += 1
    end if
next

' ----------------------------------------------
'   Menu: Edit->Move Object...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId  
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Move solids on layer " & layerFlip.ToString)  

Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

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

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

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 = "0.8"

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "0.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.316576442411312, -0.693544753222139, -0.647128295926117)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

Dim nullPoint As Point = Nothing

Dim axis1 As Axis
axis1 = workPart.Axes.CreateAxis(nullPoint, direction1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector2 As Vector3d = New Vector3d(-0.0, -0.0, -1.0)
Dim direction2 As Direction
direction2 = workPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToVector = direction2

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

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1 1"), 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()


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

End Sub
End Module 

RE: Copying Solids To A New Layer; Journal

(OP)
Cowski,

Nevermind. It seems like the code presently works as needed on other files. Honestly didn't expect it to work that well. Thanks for the help.

RE: Copying Solids To A New Layer; Journal

(OP)
Happy New Year!

So I've got this code and am wanting to adjust such that I can select the necessary "direction" to align the copied body correctly. This code works less than 50% of the time and while it does copy the body to layer 195, the code doesn't always "flip" the body. I'll put the code that I'm presently using below. Thanks in advance for the help.

CODE -->

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic  
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module NXJournal

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUFSession As UFSession = UFSession.GetUFSession

Sub Main

'get list of solid bodies on given layer

Dim layerFlip as NXObject()
Dim myFlipObjects as DisplayableObject()
Dim l as Integer = 0

layerFlip = workPart.Layers.GetAllObjectsOnLayer(180)

for each someObject as NXObject in layerFlip
    if someObject.GetType.ToString = "NXOpen.Body" then
        redim preserve myFlipObjects(l)
        myFlipObjects(l) = someObject
        l += 1
    end if
next

' ----------------------------------------------
'   Menu: Edit->Move Object...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId  
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Move solids on layer " & layerFlip.ToString)  

Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

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

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

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 = "0.8"

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "0.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.316576442411312, -0.693544753222139, -0.647128295926117)
Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(origin1, vector1, SmartObject.UpdateOption.WithinModeling)

Dim nullPoint As Point = Nothing

Dim axis1 As Axis
axis1 = workPart.Axes.CreateAxis(nullPoint, direction1, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

Dim origin2 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim vector2 As Vector3d = New Vector3d(-0.0, -0.0, -1.0)
Dim direction2 As Direction
direction2 = workPart.Directions.CreateDirection(origin2, vector2, SmartObject.UpdateOption.WithinModeling)

moveObjectBuilder1.TransformMotion.ToVector = direction2

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

Dim cartesianCoordinateSystem1 As CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1 1"), 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()

'--------------------------------------------------------
'Change Color of Flipped Overlay to Gold (53) and opaque
'--------------------------------------------------------

dim layerNumber as Integer = 195
dim k as Integer = 0


Dim goldObjects as NXObject()
Dim myGoldBodies as DisplayableObject()

Dim displayModification2 As DisplayModification
displayModification2 = theSession.DisplayManager.NewDisplayModification()

goldObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)

for each someObject as NXObject in goldObjects
	'The Following Line is Key. "NXOpen.____" will determine whether points, bodies, lines, or whatever are selected.
    if someObject.GetType.ToString = "NXOpen.Body" then
        redim preserve myGoldBodies(k)
        myGoldBodies(k) = someObject
        k += 1
    end if
next

if k>0
	With displayModification2
    		.NewColor = 53
    		.NewTranslucency = 0        'only applies to faces; you can set this for points, but it will have no effect
    		.Apply(myGoldBodies)
    		.Dispose
	End With
end if

displayModification2.Dispose()

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

End Sub
End Module 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Engineering Report - Top 10 Defect Types in Production
This 22-page report from Instrumental identifies the most common production defect types discovered in 2020, showcases trends from 2019 to 2020, and provides insights on how to prevent potential downtime in 2021. Unlike other methods, Instrumental drives correlations between a variety of data sources to help engineers find and fix root causes. Download Now
White Paper - Addressing Tooling and Casting Requirements at the Design Stage
Several of the tooling and casting requirements of a part can be addressed at the design stage. If these requirements are not addressed at the design stage, lot of time is spent in design iteration when the design reaches the die caster. These design issues lead to increase in time and cost of production leading to delay in time to market and reduced profits for the organization. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close