Journal Create and Import a Part
Journal Create and Import a Part
(OP)
I am working on a journal that takes the current workpart, and creates a blank template with an identical name but adds a "_Rev" to the name.
I have not found a way to simply create it inside the assembly but thanks to the help of FrankSwinks, there is apparently a way to create a component as a loaded and a saved part in an assembly.
Referencing http://www.eng-tips.com/viewthread.cfm?qid=335028
Here is my code but yet again I am having a reoccurring issue with the .Commit() command wherever I seem to attempt to use it.
I need help either correcting my code or creating a new to import the newly made component aforementioned. Many thanks in advanced.
I have not found a way to simply create it inside the assembly but thanks to the help of FrankSwinks, there is apparently a way to create a component as a loaded and a saved part in an assembly.
Referencing http://www.eng-tips.com/viewthread.cfm?qid=335028
Here is my code but yet again I am having a reoccurring issue with the .Commit() command wherever I seem to attempt to use it.
I need help either correcting my code or creating a new to import the newly made component aforementioned. Many thanks in advanced.
CODE --> vb
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Module NXJournal
Sub Main
Dim theUI As UI = UI.GetUI()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim partname As String
Dim workpart As Part = theSession.Parts.work
Dim disp_partname As String
Dim displayPart As Part = theSession.Parts.Display
Dim comp As String
Dim Revcomp As String
Dim insert as String
Dim partLoadStatus2 As NXOpen.PartLoadStatus = Nothing
partname = path.GetFileNameWithoutExtension(workPart.FullPath)
comp = partname
insert = "_Rev"
'Revcomp = comp .insert(5, insert)
Dim dIndex = comp.IndexOf("_")
Revcomp=comp.insert(dIndex, insert)
'To find folder name and such
Dim folderName As String = Path.GetDirectoryName(workpart.FullPath)
Dim fullpathname1 As String = "C:\Program Files\UGS\NX 7.5\UGII\html_files/model_template_inch.prt"
Dim fullpathname2 As String = folderName & "\" & Revcomp & ".prt"
File.Copy(fullpathname1, fullpathname2)
Dim partLoadStatus3 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(displaypart, False, True, partLoadStatus3)
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
partLoadStatus3.Dispose()
'The Following is directly from recording a journal importing a part besifes the Filename
'I still have the same reoccuring problem with the .Commit() command down by NXObject
Dim importer1 As Importer
importer1 = workPart.ImportManager.CreatePartImporter()
Dim partImporter1 As PartImporter = CType(importer1, PartImporter)
partImporter1.FileName = fullpathname2
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = True
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
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
End Module 




RE: Journal Create and Import a Part
comp = partname
insert = "_Rev"
'Revcomp = comp .insert(5, insert)
Dim dIndex = comp.IndexOf("_")
Revcomp=comp.insert(dIndex, insert)
to simply read
comp = partnmae
Revcomp = comp & "_Rev"
and the journal runs fine in that it inserts the previously saved copy of the template part into the current display part. Is this what you want? If so why not simply import the template part? What is the need of creating a named copy of the template part. It just seems to me that I must be missing something?
Frank Swinkels
RE: Journal Create and Import a Part
Here is the point where I thought I could use that code to create the new component, and then import it to be able to work on it from there. If I am reading this correctly does the journal work for you? Because I get an error in the line below, and if I comment it out, nothing happens.
CODE --> vb
RE: Journal Create and Import a Part
Frank Swinkels
RE: Journal Create and Import a Part
"A read-only part is modified.
You will not be able to save the changes to it.
JobNum__Rev_example.prt"
Any ideas why I am getting this Read-only Part message?