Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SDETERS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help NX Journal CSYS of Object

Status
Not open for further replies.

nxexplorer

Mechanical
Jun 23, 2010
84
Hello All,
I need help in journal for creating wcs and save it.
The journal will do format=> wcs==>orient=>CSYS of Object>select edge of cylinder, then save the wcs.
This is done in the work part of the assembly.

I need help, any suggest, and help is very much appreciated.

Recorded Journal(Codes):
' NX 1957

Imports System
Imports NXOpen

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

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

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Format->WCS->Orient...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane1 As NXOpen.Plane = Nothing
plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

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

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

Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane2 As NXOpen.Plane = Nothing
plane2 = workPart.Planes.CreatePlane(origin2, normal2, NXOpen.SmartObject.UpdateOption.WithinModeling)

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

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

Dim origin3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal3 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane3 As NXOpen.Plane = Nothing
plane3 = workPart.Planes.CreatePlane(origin3, normal3, NXOpen.SmartObject.UpdateOption.WithinModeling)

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

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

Dim origin4 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal4 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane4 As NXOpen.Plane = Nothing
plane4 = workPart.Planes.CreatePlane(origin4, normal4, NXOpen.SmartObject.UpdateOption.WithinModeling)

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

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

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim expression9 As NXOpen.Expression = Nothing
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

Dim expression10 As NXOpen.Expression = Nothing
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

Dim expression11 As NXOpen.Expression = Nothing
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

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

Dim expression13 As NXOpen.Expression = Nothing
expression13 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

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

Dim expression15 As NXOpen.Expression = Nothing
expression15 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

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

Dim expression17 As NXOpen.Expression = Nothing
expression17 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

expression9.SetFormula("0")

expression10.SetFormula("0")

expression11.SetFormula("0")

expression12.SetFormula("0")

expression14.SetFormula("0")

expression16.SetFormula("0")

expression13.SetFormula("0")

expression15.SetFormula("0")

expression17.SetFormula("0")

expression12.RightHandSide = "0"

expression14.RightHandSide = "0"

expression16.RightHandSide = "0"

expression13.RightHandSide = "0"

expression15.RightHandSide = "0"

expression17.RightHandSide = "0"

expression9.SetFormula("0")

expression10.SetFormula("0")

expression11.SetFormula("0")

expression12.SetFormula("0")

expression14.SetFormula("0")

expression16.SetFormula("0")

expression13.SetFormula("0")

expression15.SetFormula("0")

expression17.SetFormula("0")

theSession.SetUndoMarkName(markId1, "CSYS Dialog")

Dim cylinder1 As NXOpen.Features.Cylinder = CType(workPart.Features.FindObject("CYLINDER(0)"), NXOpen.Features.Cylinder)

Dim edge1 As NXOpen.Edge = CType(cylinder1.FindObject("EDGE * 1 * 3 {(262.999261610441,-144.9773743316356,50)(285.499261610441,-131.986993274869,50)(262.999261610441,-118.9966122181024,50) CYLINDER(0)}"), NXOpen.Edge)

Dim xform1 As NXOpen.Xform = Nothing
xform1 = workPart.Xforms.CreateXform(edge1, NXOpen.SmartObject.UpdateOption.AfterModeling)

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CSYS")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CSYS")

Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing
cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.AfterModeling)

xform1.RemoveParameters()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "CSYS")

workPart.Expressions.Delete(expression12)

workPart.Expressions.Delete(expression14)

workPart.Expressions.Delete(expression16)

workPart.Expressions.Delete(expression13)

workPart.Expressions.Delete(expression15)

workPart.Expressions.Delete(expression17)

workPart.Expressions.Delete(expression9)

workPart.Expressions.Delete(expression10)

workPart.Expressions.Delete(expression11)

Try
' Expression is still in use.
workPart.Expressions.Delete(expression2)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression4)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression6)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression8)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression1)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane1.DestroyPlane()

Try
' Expression is still in use.
workPart.Expressions.Delete(expression3)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane2.DestroyPlane()

Try
' Expression is still in use.
workPart.Expressions.Delete(expression5)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane3.DestroyPlane()

Try
' Expression is still in use.
workPart.Expressions.Delete(expression7)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane4.DestroyPlane()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.AddToDeleteList(cartesianCoordinateSystem1)

Dim objects1(0) As NXOpen.TaggedObject
Dim cartesianCoordinateSystem2 As NXOpen.CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1"), NXOpen.CartesianCoordinateSystem)

objects1(0) = cartesianCoordinateSystem2
Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddObjectsToDeleteList(objects1)

Dim origin5 As NXOpen.Point3d = New NXOpen.Point3d(270.49926161044101, -131.98699327486901, 49.999999999999986)
Dim matrix1 As NXOpen.Matrix3x3 = Nothing
matrix1.Xx = 1.0
matrix1.Xy = 0.0
matrix1.Xz = 0.0
matrix1.Yx = 0.0
matrix1.Yy = -1.0
matrix1.Yz = 0.0
matrix1.Zx = 0.0
matrix1.Zy = 0.0
matrix1.Zz = -1.0
displayPart.WCS.SetOriginAndMatrix(origin5, matrix1)

Dim id1 As NXOpen.Session.UndoMarkId = Nothing
id1 = theSession.NewestVisibleUndoMark

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(id1)

theSession.CleanUpFacetedFacesAndEdges()

' ----------------------------------------------
' Menu: Format->WCS->Save
' ----------------------------------------------
Dim cartesianCoordinateSystem3 As NXOpen.CartesianCoordinateSystem = Nothing
cartesianCoordinateSystem3 = displayPart.WCS.Save()

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

End Sub
End Module

'=================================
Best Regards
Maryadi

 
Replies continue below

Recommended for you

Thank You Cowski,
This is for me to simply make a saved wcs with one-click's mouse as the preparation for creating the bounding block from a cylinder.

Thank you for the links you have shared me. I will try to learn.

Regards,
Maryadi

 
Hi Cowski,
So far it hasn't been as I expected,I'm still trying to keep going. Now that the idea comes to mind, that the step of saving wcs will be put together into a bounding block journal. But that's later if I've managed to make it.
Thank you for your attention.

Best Regards,
Maryadi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor