Journal to copy to clipboard
Journal to copy to clipboard
(OP)
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!
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!





RE: Journal to copy to clipboard
Frank Swinkels
RE: Journal to copy to clipboard
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
RE: Journal to copy to clipboard
'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
copycutBuilder1.SetObjects(objects1)
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!
RE: Journal to copy to clipboard
That's a common practice when CAM users need to modify the CAD geometry,
Mark Rief
Product Manager
Siemens PLM
RE: Journal to copy to clipboard
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 Modulewww.nxjournaling.com
RE: Journal to copy to clipboard
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!
RE: Journal to copy to clipboard
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
RE: Journal to copy to clipboard
hppianoman kindly allowed me to post the code on the nxjournaling website. You can find his full journal code listing here.
Thanks again to hppianoman for sharing!
www.nxjournaling.com