Cancel
Showing results for 
Search instead for 
Did you mean: 

How to Rotate an Object by a Certain Degree Using One of Object's Edge

Creator
Creator

Assume I have an object and and one of its edges is 10 degree off from absolute z-axis and I want to rotate it by -10 degree. Assume the point for the rotation is end point of the edge.

 

I tried to record the rotating code but the long code is confusing.

2 REPLIES

Re: How to Rotate an Object by a Certain Degree Using One of Object's Edge

Valued Contributor
Valued Contributor

Are you using move object option by setting angle as preferance to move that 10 degree?

 

Regards,
Abhi

Re: How to Rotate an Object by a Certain Degree Using One of Object's Edge

Honored Contributor
Honored Contributor

I started a new part, created a block, then recorded a journal while rotating the block 10° about one of its edges. The resulting code, after eliminating the unneccessary bits, is shown below. Note: the "associative" and "move parents" options were turned off during the move.

 

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

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

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Move Object")

Dim nullFeatures_MoveObject As Features.MoveObject = Nothing

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

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

moveObjectBuilder1.TransformMotion.Angle.RightHandSide = "10"

moveObjectBuilder1.MoveParents = False

Dim body1 As Body = CType(workPart.Bodies.FindObject("BLOCK(1)"), Body)

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

Dim block1 As Features.Block = CType(workPart.Features.FindObject("BLOCK(1)"), Features.Block)

Dim edge1 As Edge = CType(block1.FindObject("EDGE * 2 * 5 {(0,0,0)(4,0,0)(8,0,0) BLOCK(1)}"), Edge)

Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(edge1, Sense.Forward, 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

axis1.Point = nullPoint

axis1.Evaluate()

moveObjectBuilder1.TransformMotion.AngularAxis = axis1

Dim nXObject1 As NXObject
nXObject1 = moveObjectBuilder1.Commit()

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

moveObjectBuilder1.Destroy()


End Sub
End Module

If this were my project, the next step would be to eliminate the .FindObject calls. This could be accomplished by allowing the user to select the body and edge or creating an algorithm to find the desired body and edge.