Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX9 - Journal to import to CSYS (wherever it is placed) 1

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
When I record a journal to import a part file, it will only bring the file in at the same point it did when I recorded it. Even though I recorded it to come in to the csys. Can someone help me with how to import a part file so it comes to zero zero of the csys in modeling no matter where the csys is placed?
 
Replies continue below

Recommended for you

Let me correct myself here.... I want to bring the part file in at the 0,0,0 of the current WCS position. Not at a csys.

Here is the code I recorded...

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

' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")
Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()
partImporter1.FileName = "R:\hms_tools\NX9\Tooling\part\ZERO DOWEL\ZERO_DOWEL.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = False
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")

Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)

partImporter1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
 
Ah, I think I found it. I found a similar code out there and it worked for me. I made the following change in my code and it seemed to work.... almost..... It turns out that this brings the part file in at 0,0,0 to the WCS, but if the WCS is rotated, the plane the file comes in does not move with the WCS. If anyone can help with making the file import on the XY plane of the WCS, I think I would have what I need.




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

' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")
Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()
partImporter1.FileName = "R:\hms_tools\NX9\Tooling\part\ZERO DOWEL\ZERO_DOWEL.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = False
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As Point3d = workPart.WCS.Origin
partImporter1.DestinationPoint = destinationPoint1

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")

Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)

partImporter1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
 
Your code above creates an orientation matrix that is aligned with the absolute coordinate system. You can access the orientation of the WCS and use that instead.

Change this code:
Code:
partImporter1.DestinationCoordinateSystem = nXMatrix1

to this:
Code:
partImporter1.DestinationCoordinateSystem = workPart.WCS.CoordinateSystem.Orientation

After making this change, you can eliminate all of the (now useless) "element1" code.

www.nxjournaling.com
 
Awesome Cowski

This seems to have done the trick. Thank you very much.[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor