Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal Create and Import a Part

Status
Not open for further replies.

DHuskic

Computer
Dec 18, 2012
114
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 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:
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
 
Replies continue below

Recommended for you

I changed the lines

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
 
Well back to the other thread I referenced, my overall goal is to execute a journal with my component as my workpart, and for a new component to be created on the same level as the workpart, with "_Rev" in the name, and for the new component to wavelink all of the true(reference set setting) bodies of the workpart. I could not properly excute the create component code I came to through the help of the threads and you had given me the journal code to create the component as a loaded and saved part but if I attempted to work on that new component it was giving me a read file error.
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:
NXObject1 = partImporter1.Commit()
 
Firstly import is as the name says is to import the data from one part into the current work part. As I see it this is not what you are looking for. From the earlier code I gather that you can create the filename_rev and that it is created as a component of your current work part. If now you want to work on that new component part you need to set that part as the work part.

Frank Swinkels
 
I agree but when I want to work on the new component part it, after I complete my first action on the new component part I receive a message that states the following:

"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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor