Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 783

Need to import any one part out of two from Teamcenter in NX using Journal

$
0
0

Code is working fine for me but now I want to get the input from user that which part they want to import by using elseif condition.
I tried but that code is not working.
attached code will import part on different point location.
requirement is to import any one of the parts out of two and place position.

Imports System
Imports NXOpen
 
Module NXJournal
Sub Main (ByVal args()AsString) 
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: File->Import->Part...' ----------------------------------------------Dim markId4 As NXOpen.Session.UndoMarkId=Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start") 
theSession.SetUndoMarkName(markId4, "Import Part Dialog") 
' ----------------------------------------------'   Dialog Begin Import Part' ----------------------------------------------Dim markId5 As NXOpen.Session.UndoMarkId=Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part") 
theSession.DeleteUndoMark(markId5, Nothing) 
Dim markId6 As NXOpen.Session.UndoMarkId=Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part") 
theSession.DeleteUndoMark(markId6, Nothing) 
theSession.SetUndoMarkName(markId4, "Import Part") 
theSession.DeleteUndoMark(markId4, Nothing) 
theSession.Parts.SetNonmasterSeedPartData("@DB/002891/00") 
Dim markId7 As NXOpen.Session.UndoMarkId=Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Import Part") 
Dim partImporter1 As NXOpen.PartImporter=Nothing
partImporter1 = workPart.ImportManager.CreatePartImporter() 
partImporter1.FileName="@DB/002891/00" 
partImporter1.Scale=1.0 
partImporter1.CreateNamedGroup=True 
partImporter1.ImportViews=False 
partImporter1.ImportCamObjects=False 
partImporter1.LayerOption= NXOpen.PartImporter.LayerOptionType.Work 
partImporter1.DestinationCoordinateSystemSpecification= NXOpen.PartImporter.DestinationCoordinateSystemSpecificationType.Work 
Dim element1 As NXOpen.Matrix3x3=Nothing
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.0Dim nXMatrix1 As NXOpen.NXMatrix=Nothing
nXMatrix1 = workPart.NXMatrices.Create(element1) 
partImporter1.DestinationCoordinateSystem= nXMatrix1
 
Dim unit AsString=InputBox("Unit (M for millimeters, I for inches):", "Enter Unit of Meausrement")Dim sheetSize AsString=InputBox("Enter sheet size (e.g., A0, A4, A, E):", "Sheet Size")Dim sheetWidth AsDoubleDim sheetHeight AsDouble 
If unit.ToUpper()="M"Then' Calculate the width and height in millimeters based on the sheet sizeSelectCase sheetSize.ToUpper()Case"A0"
            sheetWidth =841.0
            sheetHeight =1189.0Case"A1"
            sheetWidth =594.0
            sheetHeight =841.0Case"A2"
            sheetWidth =420.0
            sheetHeight =594.0Case"A3"
            sheetWidth =297.0
            sheetHeight =420.0Case"A4"
            sheetWidth =297.0
            sheetHeight =210.0CaseElse' Handle invalid sheet size
            Console.WriteLine("Invalid sheet size.")ReturnEndSelectElseIf unit.ToUpper()="I"Then' Calculate the width and height in inches based on the sheet sizeSelectCase sheetSize.ToUpper()Case"A"
            sheetWidth =11.0
            sheetHeight =8.5Case"B"
            sheetWidth =11.0
            sheetHeight =17.0Case"C"
            sheetWidth =17.0
            sheetHeight =22.0Case"D"
            sheetWidth =22.0
            sheetHeight =34.0Case"E"
            sheetWidth =34.0
            sheetHeight =44.0Case"F"
            sheetWidth =28.0
            sheetHeight =40.0CaseElse' Handle invalid sheet size
            Console.WriteLine("Invalid sheet size.")ReturnEndSelectElse' Handle invalid unit
    Console.WriteLine("Invalid unit of measurement.")ReturnEndIf 
' Calculate the destination point coordinates based on sheet sizeDim x AsDouble= SheetHeight -10Dim y AsDouble=10Dim z AsDouble=0.0 
' Create the destination point with the calculated coordinatesDim destinationPoint1 As NXOpen.Point3d=New NXOpen.Point3d(x, y, z)
partImporter1.DestinationPoint= destinationPoint1
 
Dim markId8 As NXOpen.Session.UndoMarkId=Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part Commit") 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_UGMGR_decode_part_file_name 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_UGMGR_decode_part_file_name 
Dim nXObject2 As NXOpen.NXObject=Nothing
nXObject2 = partImporter1.Commit() 
theSession.DeleteUndoMark(markId8, Nothing) 
partImporter1.Destroy() 
' ----------------------------------------------'   Menu: File->Import->Part...' ----------------------------------------------Dim markId9 As NXOpen.Session.UndoMarkId=Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start") 
theSession.SetUndoMarkName(markId9, "Import Part Dialog") 
' ----------------------------------------------'   Dialog Begin Import Part' ----------------------------------------------Dim markId10 As NXOpen.Session.UndoMarkId=Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part") 
theSession.DeleteUndoMark(markId10, Nothing) 
Dim markId11 As NXOpen.Session.UndoMarkId=Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part") 
theSession.DeleteUndoMark(markId11, Nothing) 
theSession.SetUndoMarkName(markId9, "Import Part") 
theSession.DeleteUndoMark(markId9, Nothing) 
theSession.Parts.SetNonmasterSeedPartData("@DB/002892/00") 
Dim markId12 As NXOpen.Session.UndoMarkId=Nothing
markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Import Part") 
Dim partImporter2 As NXOpen.PartImporter=Nothing
partImporter2 = workPart.ImportManager.CreatePartImporter() 
partImporter2.FileName="@DB/002892/00" 
partImporter2.Scale=1.0 
partImporter2.CreateNamedGroup=True 
partImporter2.ImportViews=False 
partImporter2.ImportCamObjects=False 
partImporter2.LayerOption= NXOpen.PartImporter.LayerOptionType.Work 
partImporter2.DestinationCoordinateSystemSpecification= NXOpen.PartImporter.DestinationCoordinateSystemSpecificationType.Work 
Dim element2 As NXOpen.Matrix3x3=Nothing
element2.Xx=1.0
element2.Xy=0.0
element2.Xz=0.0
element2.Yx=0.0
element2.Yy=1.0
element2.Yz=0.0
element2.Zx=0.0
element2.Zy=0.0
element2.Zz=1.0Dim nXMatrix2 As NXOpen.NXMatrix=Nothing
nXMatrix2 = workPart.NXMatrices.Create(element2) 
partImporter2.DestinationCoordinateSystem= nXMatrix2
 
' Calculate the destination point coordinates based on sheet sizeDim x1 AsDouble= SheetHeight -10Dim y1 AsDouble= SheetWidth -10Dim z1 AsDouble=0.0 
' Create the destination point with the calculated coordinatesDim destinationPoint2 As NXOpen.Point3d=New NXOpen.Point3d(x1, y1, z1)
partImporter2.DestinationPoint= destinationPoint2
 
Dim markId13 As NXOpen.Session.UndoMarkId=Nothing
markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part Commit") 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_UGMGR_decode_part_file_name 
' User Function call - UF_PART_ask_part_name 
' User Function call - UF_UGMGR_decode_part_file_name 
Dim nXObject3 As NXOpen.NXObject=Nothing
nXObject3 = partImporter2.Commit() 
theSession.DeleteUndoMark(markId13, Nothing) 
partImporter2.Destroy() 
EndSubEndModule

Viewing all articles
Browse latest Browse all 783

Trending Articles