Hi,
I have a sample code to copy component(file from Drive) to clipboard
but present code is working only on one component at once,
can anyone make it to multiple components at once
' NX 10.0.2.6
' Journal created by gashaik on Fri Aug 19 11:29:31 2016 India Standard Time
'
Option Strict Off
Imports System
Imports System.IO
'Imports NXOpen.UI
Imports NXOpen
Imports NXOpen.Assemblies
Imports System.Windows.Forms
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()
Dim components1(0) As NXOpen.Assemblies.Component
components1(0) = CType(theUI.SelectionManager.GetSelectedObject(0), NXOpen.Assemblies.Component)
Dim c_part As Part = Nothing
c_part = components1(0).Prototype
Dim directory As String = Path.GetDirectoryName(c_part.FullPath)
Dim pth as string= c_part.FullPath
Dim f() As String = {pth}
Dim d As New DataObject(DataFormats.FileDrop, f)
Clipboard.Clear()
Clipboard.SetDataObject(d, True)
MessageBox.Show("File Copied to Clipboard From : " & pth)
'System.Diagnostics.Process.Start("explorer.exe", "/select," & pth)
End Sub
End Module
re: copy component part file to clipboard
Try the following:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpenUI
Module Module2
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim numsel As Integer = theUI.SelectionManager.GetNumSelectedObjects()
Dim theComps As New List(Of Assemblies.Component)
For i As Integer = 0 To numsel - 1
Dim selObj As TaggedObject = theUI.SelectionManager.GetSelectedTaggedObject(i)
If TypeOf (selObj) Is Assemblies.Component Then
theComps.Add(selObj)
End If
Next
If theComps.Count = 0 Then
'no components found among the preselected objects
Return
End If
Dim fileNames As New List(Of String)
For Each tempComp As Assemblies.Component In theComps
Dim compPath As String = tempComp.Prototype.OwningPart.FullPath
If Not fileNames.Contains(compPath) Then
fileNames.Add(compPath)
End If
Next
If fileNames.Count = 0 Then
Return
End If
Dim d As New DataObject(DataFormats.FileDrop, fileNames.ToArray)
Clipboard.SetDataObject(d, True)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module