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 - Import Two Part Files?

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
I have the below code to import a part file "Water_jet.prt" automatically. Is there a simple way to change this so it will import both "Water_jet.prt" and "Paintcode.prt" at the same time?

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\Notes\Water_jet.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
 
Replies continue below

Recommended for you

Take the part import code and turn it into a subroutine, call the subroutine with whatever parts are necessary in Sub Main. Below is a quickly put together, untested version:

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module71

    Dim theSession As Session = Session.GetSession()

    Sub Main(ByVal args() As String)

        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, "Import Part")

        ImportPart("R:\hms_tools\NX9\Tooling\part\Notes\Water_jet.prt")
        ImportPart("R:\hms_tools\NX9\Tooling\part\Notes\Paintcode.prt")

    End Sub

    Sub ImportPart(ByVal partPath As String)

        Dim partImporter1 As PartImporter
        partImporter1 = Workpart.ImportManager.CreatePartImporter()
        partImporter1.FileName = partPath

        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()


    End Sub

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor