Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Journal to copy to clipboard

Status
Not open for further replies.

hppianoman

Mechanical
Joined
Mar 8, 2012
Messages
7
Location
US
Greetings to all!

I am needing help creating a journal in NX7.5 using VB. I am wanting to select all curves in the Flat-pattern of the model, and copy them to the Clipboard for use at a later time. I have been able select all of the curves just fine, but am having trouble getting them copied to the clipboard; mainly because I'm not understanding the clipboard functions. I'm guessing that pasting the curves back in when I need to will be using the pastebuilder functions, so a little help with that is probably needed as well.

Any suggestions would be appreciated.

Thanks!
 
Not sure why you need to use clipboard copy when you can use edit->move objects within a journal to copy NXObjects. Let me know is this of use and if you need a sample journal.

Frank Swinkels
 
Frank,

For NC automated punching operations, I sometimes need to modify the flat-pattern of the model in order to set up tabbing properly for the machines, and to reduce problems on the shop floor. I haven't been able to modify the flat pattern when it is still associated to the model, so I have been copying the curves of the flat geometry to the clipboard, deleting all model history, and pasting the flat geometry back into the TOP view. This allows me to modify the flat geometry any way that I need to, and save it as an alternate representation in Teamcenter if needed. Currently, I have macros set up to do all of this. I am trying to re-write my macros as VB journals, but am having trouble understanding the copy/paste functionality of the Clipboard in VB. Any help would be appreciated.

Thanks,
Brett
 
I am trying to copy lines and arcs of the flat pattern to the clipboard. I have the following code to select the lines and arcs...

'SELECT ALL ARCS AND LINES IN FLAT PATTERN GEOMETRY IN ORDER TO COPY THEM TO THE CLIPBOARD

Dim length As Integer
Dim journalID As String
Dim i As Integer


Dim markID3 As Session.UndoMarkId
markID3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Copy")

Dim copycutBuilder1 As Gateway.CopyCutBuilder
copycutBuilder1 = workPart.ClipboardOperationsManager.CreateCopyCutBuilder()
copycutBuilder1.CanCopyAsSketch = True
copycutBuilder1.IsCut = False
copycutBuilder1.ToClipboard = True
copycutBuilder1.DestinationFilename = Nothing

length = 0

'Loop to find out the total number of lines and arcs for setting the number for array "objects1"
For Each obj As DisplayableObject In theSession.Parts.Work.Curves
If TypeOf obj Is Arc Then
obj.Highlight()
length = length + 1
obj.RedisplayObject()
ElseIf TypeOf obj Is Line Then
obj.Highlight()
length = length + 1
obj.RedisplayObject()
End If
Next

'PAUSE
theUI.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "Length = " & length)
theUI.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, Message)
theUI.JournalPause()

Dim objects1(length) As NXObject

i = 0

'Loop to select all lines and arcs and put them into array "objects1"
For Each obj As NXObject In theSession.Parts.Work.Curves
If TypeOf obj Is Arc Then
journalID = obj.JournalIdentifier
objects1(i) = CType(workPart.Arcs.FindObject(journalID), Arc)
i = i + 1
ElseIf TypeOf obj Is Line Then
journalID = obj.JournalIdentifier
objects1(i) = CType(workPart.Lines.FindObject(journalID), Line)
i = i + 1
End If
Next


theUI.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "Length = " & length)
theUI.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "i = " & i)
theUI.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "OK?")
theUI.JournalPause()


'COPY LINES AND ARCS OF FLAT PATTERN GEOMETRY TO CLIPBOARD
[highlight #EF2929]copycutBuilder1.SetObjects(objects1)[/highlight]
Dim nxObject1 As NXObject
nxObject1 = copycutBuilder1.Commit()

copycutBuilder1.Commit()

copycutBuilder1.Destroy()


theSession.DeleteUndoMark(markID3, Nothing)



However, when the program gets to the line highlighted in red [copycutBuilder1.SetObjsects(objects1)], I get a journal execution error message stating:
"NXOpen.NXException:Incorrect object for this operation"

I'm not sure what I'm doing wrong. Can anyone please help?

Thanks!
 
Have you considered wave linking instead?
That's a common practice when CAM users need to modify the CAD geometry,

Mark Rief
Product Manager
Siemens PLM
 
Try this:

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

Module NXJournal
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim copycutBuilder1 As Gateway.CopyCutBuilder
        copycutBuilder1 = workPart.ClipboardOperationsManager.CreateCopyCutBuilder()
        copycutBuilder1.CanCopyAsSketch = True
        copycutBuilder1.IsCut = False
        copycutBuilder1.ToClipboard = True
        copycutBuilder1.DestinationFilename = Nothing

        Dim flatPatternEnts() As NXObject

        For Each myFeature As Feature In workPart.Features.GetFeatures()
            If myFeature.FeatureType = "FLAT_PATTERN" Then
                Dim myFlatPattern As FlatPattern = myFeature
                lw.WriteLine("flat pattern found, feature number: " & myFeature.GetFeatureName)
                flatPatternEnts = myFlatPattern.GetCurves
                lw.WriteLine("Entity Count: " & flatPatternEnts.Length)
            End If
        Next
        lw.Close()

        If flatPatternEnts.Length > 0 Then
            copycutBuilder1.SetObjects(flatPatternEnts)
            Dim nxObject1 As NXObject
            nxObject1 = copycutBuilder1.Commit()
        End If

        copycutBuilder1.Destroy()

    End Sub
End Module

www.nxjournaling.com
 
Cowski,

Thanks again for your help! That code worked great. Your code was selecting all curves, so I added a loop in front of your code to remove the lines on layer 102, because I didn't need them. I also commented out the listing window lines. That was fine for testing, but I didn't want that window popping up every time I ran the program. The code now looks like this:

Code:
'SELECT ALL ARCS AND LINES IN FLAT PATTERN GEOMETRY IN ORDER TO COPY THEM TO THE CLIPBOARD

        Dim markID3 As Session.UndoMarkId
        markID3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Copy")

        'Loop to remove bend tangency lines on layer 102"
        For Each obj As DisplayableObject In theSession.Parts.Work.Curves
            If TypeOf obj Is Line Then
                If obj.Layer = 102 Then
                    obj.Blank()
                End If
            End If
        Next

        'Dim lw As ListingWindow = theSession.ListingWindow
        'lw.Open()

        Dim copycutBuilder1 As Gateway.CopyCutBuilder
        copycutBuilder1 = workPart.ClipboardOperationsManager.CreateCopyCutBuilder()
        copycutBuilder1.CanCopyAsSketch = True
        copycutBuilder1.IsCut = False
        copycutBuilder1.ToClipboard = True
        copycutBuilder1.DestinationFilename = Nothing

        Dim flatPatternEntities() As NXObject

        For Each myFeature As Feature In workPart.Features.GetFeatures()
            If myFeature.FeatureType = "FLAT_PATTERN" Then
                Dim myFlatPattern As FlatPattern = myFeature
                'lw.WriteLine("flat pattern found, feature number: " & myFeature.GetFeatureName)
                flatPatternEntities = myFlatPattern.GetCurves
                'lw.WriteLine("Entity Count: " & flatPatternEntities.Length)
            End If
        Next
        'lw.Close()

        If flatPatternEntities.Length > 0 Then
            copycutBuilder1.SetObjects(flatPatternEntities)
            Dim nxObject1 As NXObject
            nxObject1 = copycutBuilder1.Commit()
        End If

        copycutBuilder1.Destroy()

This section of code is part of a larger program. When I added the pastebuilder later on in the program, everything worked just like it was supposed to. Thanks again for your help!
 
hppianoman,
Would you be willing to post the pastebuilder program, if you may? I would be very interested in that code.

Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top