Export assembly (with drawings)

The code below was submitted by site user: peter.t.

This journal is intended to clone an assembly of parts with their drawings in preparation for delivery to a customer or third party. The journal expects that there will be no parts open when it is initially run; it will prompt you to open a part. It will then attempt to load and clone the assembly. If there is a drawing of a part in the same directory as the part, it will be cloned along with the assembly. The drawing file name must match the model file name with "_dwg1" appended to it; if the part name is "12345.prt", it will look for a drawing named "12345_dwg1.prt". If you follow a different drawing naming convention, modify the journal code accordingly before running it. Also, the initial directory for the "file open" dialogs can (and should) be customized to your environment.

A big thank-you to peter.t for sharing his code!


'/////////////////////////////////////////////////////////////////
'// //
'// Baugruppen für Datenaustausch exportieren //
'// //
'// //
'// //
'// Erstellt am 08.09.2015 //
'// peter.t //
'// //
'/////////////////////////////////////////////////////////////////

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI

Module clone_tool

Dim theSession As Session = Session.GetSession()

Dim theUFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()

Dim theUISession As UI = ui.GetUI

Public lw As ListingWindow = theSession.ListingWindow

Public pList As New List(Of String)

Sub Main()

' wenn Teil geladen ist, Fehler!
If Not IsNothing(theSession.Parts.Display) Then
theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Es darf kein Teil geladen sein. Abbruch ...")
Exit Sub
End If

' Excel- und NX-Datei abfragen
Dim OFD As New OpenFileDialog

OFD.Title = "Bitte wählen Sie eine Baugruppe"
OFD.Filter = "NX-Dateien (*.prt) |*.prt"
OFD.InitialDirectory = "C:\"

Dim BGfileName As String
Dim BGDirectory As String

If OFD.ShowDialog = DialogResult.OK Then

BGDirectory = Replace(OFD.FileName, System.IO.Path.GetFileName(OFD.FileName), "")
BGfileName = System.IO.Path.GetFileName(OFD.FileName)

Else

Exit Sub

End If

' Baugruppe laden
' wenn Teile der Baugruppe nicht geladen werden können, Fehler
Dim loadStatus As PartLoadStatus
Dim BG As Part = theSession.Parts.OpenBaseDisplay(BGDirectory & BGFileName, loadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Fehler beim Laden der Baugruppe." & vbnewline & "Anzahl der nicht geladenen Teile: " & loadStatus.NumberUnloadedParts & vbnewline & "Überprüfen Sie Ihre Ladeoptionen.")
Exit Sub
End If

Dim displayPart As Part = theSession.Parts.Display

Dim c As ComponentAssembly = displayPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then

pList.Add(c.RootComponent.DisplayName)

getComps(c.RootComponent, 0)

Else

theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Teil ist keine Baugruppe!")
Exit Sub

End If

'Zeichnungsüberprüfung
Dim drwList As New List(Of String)
Dim notFound As String

For x As Integer = 0 To pList.Count - 1

Dim tmpPart As Part

Try
tmpPart = CType(theSession.Parts.FindObject(pList.Item(x)), Part)

Catch ex As Exception

theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Teil " & pList.Item(x) & " ist fehlerhaft oder nicht geladen!")
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
Exit Sub

End Try

Dim drwFileName As String = tmpPart.FullPath.Replace(".prt", "_dwg1.prt")
If IO.File.Exists(drwFileName) = False Then

notFound = notFound + drwFileName
notFound = notFound + vbnewline

Else

drwList.Add(drwFileName)

End If

Next

' MessageBox mit nicht gefundenen Zeichnungen anzeigen
If theUISession.NXMessageBox.Show("Zeichnungsprüfung", NXOpen.NXMessageBox.DialogType.Question, "Folgende Zeichnungen konnten nicht gefunden werden: " & vbnewline & notFound & vbnewline & "Drücken Sie Ja um fortzufahren, Nein um den Vorgang abzubrechen.") = 2 Then
Exit Sub

End If

'Ausgabeverzeichnis auswählen
Dim theDirectory As String

Dim FolderBrowserDialog1 As New FolderBrowserDialog
With FolderBrowserDialog1

.RootFolder = Environment.SpecialFolder.Desktop

.SelectedPath = "set path to initial directory"

.Description = "Bitte wählen Sie ein Ausgabeverzeichnis"

If .ShowDialog = DialogResult.OK Then

theDirectory = .SelectedPath

Else

Exit Sub

End If

End With

Dim cloner As NXOpen.UF.UFClone = theUFS.Clone

Dim opt As NXOpen.UF.UFClone.ExLogOpts
opt.allow_missing_components = False

cloner.Initialise(NXOpen.UF.UFClone.OperationClass.CloneOperation)
cloner.SetDefNaming(UFClone.NamingTechnique.NamingRule)
cloner.SetDefDirectory(theDirectory)
cloner.AddAssembly(BGDirectory & BGFileName, Nothing)

'Zeichnungen anhängen
For y As Integer = 0 To drwList.Count - 1
cloner.AddPart(drwList.Item(y))
Next

' Hier Namensgebung (aktuell: Dateinamen beibehalten)
Dim namerule1 As NXOpen.UF.UFClone.NameRuleDef
namerule1.type = UFClone.NameRuleType.ReplaceString
namerule1.new_string = ""

cloner.SetNameRule(namerule1, Nothing)
'Teilefamilien
cloner.SetFamilyTreatment(UFClone.FamilyTreatment.TreatAsLost)
cloner.SetLogFile(theDirectory & "\" & BGFileName.Replace(".prt", "_export.txt"))
cloner.SetDryrun(False)
cloner.PerformClone(Nothing)
cloner.Terminate()

'alle Teile schließen und Meldung geben
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

theUISession.NXMessageBox.Show("Klonoperation", NXOpen.NXMessageBox.DialogType.Information, "Der Export der Baugruppe war erfolreich!")

End Sub
Sub getComps(ByVal comp As Component, ByVal indent As Integer)

For Each child As Component In comp.GetChildren()

If inList(child.DisplayName, pList) = False Then pList.Add(child.DisplayName)

getComps(child, indent + 1)

Next

End Sub
Public Function inList(ByVal str As String, ByVal l As List(Of String)) As Boolean

For x As Integer = 0 To l.Count - 1

If l.Item(x) = str Then

Return True
Exit For

End If

Next

End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

Comments

Hello all,

I have the folowing errors when testing this code.
What can be the reason for these errors?

1)'theUISession' is not declared. It may be inaccessible due to its protection level.
2)Type 'OpenFileDialog' is not defined.
3)Type 'FolderBrowserDialog'is not defined.
4)'DialogResult'is not declared. It may be inaccessible due to its protection level.

Thanks in advance!

There was a typo and a couple of missing "imports" statements. The code above has been updated; please download it and try again.

Hello,

Thanks for the reply, I just tryed it again but I still get some error codes.
It states that 'theUISession'is not declared?...
I am just copying the above script in an existing Journal which I emptyed.
I'm working in NX9.

Any idea what is going wrong?

Whoops!
I had fixed the import statements but forgot to fix the UI error. It works now (I've tested on NX 9).

Hey thanks for the help!

Already found out the solution by myself, its quite simple but im new in programming.

I have another question:
The program searches for files with "_dwg1" in its name.
Now I am trying to edit this to let it work for my company where we have extensions "_110XX" and "_112XX" instead of "_dwg1".
Here the "XX" stands for the page number of the drawing and can be any number between 0 and 99.

For now I changed the code to search for "_11001.prt" because these are the most common. Is it possible to let the journal search for more extensions as mentioned above?

I hope you can help me with this, the journal is great!

Thanks in advance!

I've modified peter's code a little to search for the drawings that you have indicated. It isn't heavily tested.

'/////////////////////////////////////////////////////////////////
'// //
'// Baugruppen für Datenaustausch exportieren //
'// //
'// //
'// //
'// Erstellt am 08.09.2015 //
'// peter.t //
'// //
'/////////////////////////////////////////////////////////////////

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI

Module Module2

Dim theSession As Session = Session.GetSession()

Dim theUFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()

Dim theUISession As UI = ui.GetUI

Public lw As ListingWindow = theSession.ListingWindow

Public pList As New List(Of String)

Sub Main()

' wenn Teil geladen ist, Fehler!
If Not IsNothing(theSession.Parts.Display) Then
theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Es darf kein Teil geladen sein. Abbruch ...")
Exit Sub
End If

' Excel- und NX-Datei abfragen
Dim OFD As New OpenFileDialog

OFD.Title = "Bitte wählen Sie eine Baugruppe"
OFD.Filter = "NX-Dateien (*.prt) |*.prt"
OFD.InitialDirectory = "C:\"

Dim BGfileName As String
Dim BGDirectory As String

If OFD.ShowDialog = DialogResult.OK Then

BGDirectory = Replace(OFD.FileName, System.IO.Path.GetFileName(OFD.FileName), "")
BGfileName = System.IO.Path.GetFileName(OFD.FileName)

Else

Exit Sub

End If

' Baugruppe laden
' wenn Teile der Baugruppe nicht geladen werden können, Fehler
Dim loadStatus As PartLoadStatus
Dim BG As Part = theSession.Parts.OpenBaseDisplay(BGDirectory & BGfileName, loadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Fehler beim Laden der Baugruppe." & vbNewLine & "Anzahl der nicht geladenen Teile: " & loadStatus.NumberUnloadedParts & vbNewLine & "Überprüfen Sie Ihre Ladeoptionen.")
Exit Sub
End If

Dim displayPart As Part = theSession.Parts.Display

Dim c As ComponentAssembly = displayPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then

pList.Add(c.RootComponent.DisplayName)

getComps(c.RootComponent, 0)

Else

theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Teil ist keine Baugruppe!")
Exit Sub

End If

'Zeichnungsüberprüfung
Dim drwList As New List(Of String)
Dim numNotFound As Integer = 0
Dim notFound As String = ""

For Each temp As String In pList

Dim tmpPart As Part

Try
tmpPart = CType(theSession.Parts.FindObject(temp), Part)

Catch ex As Exception

theUISession.NXMessageBox.Show("Fehler", NXOpen.NXMessageBox.DialogType.Error, "Teil " & temp & " ist fehlerhaft oder nicht geladen!")
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
Exit Sub

End Try

If FindDrawings(tmpPart.FullPath, drwList) = 0 Then
notFound &= tmpPart.Leaf
numNotFound += 1
End If

Next

' MessageBox mit nicht gefundenen Zeichnungen anzeigen
' in this particular case, the suffix for the drawing can take many forms; the english version of this message could be changed to something like:
' "Drawings for the following parts could not be found:"
If numNotFound > 0 Then
If theUISession.NXMessageBox.Show("Zeichnungsprüfung", NXOpen.NXMessageBox.DialogType.Question, "Folgende Zeichnungen konnten nicht gefunden werden: " & vbNewLine & notFound & vbNewLine & "Drücken Sie Ja um fortzufahren, Nein um den Vorgang abzubrechen.") = 2 Then
Exit Sub

End If

End If

'Ausgabeverzeichnis auswählen
Dim theDirectory As String

Dim FolderBrowserDialog1 As New FolderBrowserDialog
With FolderBrowserDialog1

.RootFolder = Environment.SpecialFolder.Desktop

.SelectedPath = "set path to initial directory"

.Description = "Bitte wählen Sie ein Ausgabeverzeichnis"

If .ShowDialog = DialogResult.OK Then

theDirectory = .SelectedPath

Else

Exit Sub

End If

End With

Dim cloner As NXOpen.UF.UFClone = theUFS.Clone

Dim opt As NXOpen.UF.UFClone.ExLogOpts
opt.allow_missing_components = False

cloner.Initialise(NXOpen.UF.UFClone.OperationClass.CloneOperation)
cloner.SetDefNaming(UFClone.NamingTechnique.NamingRule)
cloner.SetDefDirectory(theDirectory)
cloner.AddAssembly(BGDirectory & BGfileName, Nothing)

'Zeichnungen anhängen
For y As Integer = 0 To drwList.Count - 1
cloner.AddPart(drwList.Item(y))
Next

' Hier Namensgebung (aktuell: Dateinamen beibehalten)
Dim namerule1 As NXOpen.UF.UFClone.NameRuleDef
namerule1.type = UFClone.NameRuleType.ReplaceString
namerule1.new_string = ""

cloner.SetNameRule(namerule1, Nothing)
'Teilefamilien
cloner.SetFamilyTreatment(UFClone.FamilyTreatment.TreatAsLost)
cloner.SetLogfile(theDirectory & "\" & BGfileName.Replace(".prt", "_export.txt"))
cloner.SetDryrun(False)
cloner.PerformClone(Nothing)
cloner.Terminate()

'alle Teile schließen und Meldung geben
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

theUISession.NXMessageBox.Show("Klonoperation", NXOpen.NXMessageBox.DialogType.Information, "Der Export der Baugruppe war erfolreich!")

End Sub

Sub getComps(ByVal comp As Component, ByVal indent As Integer)

For Each child As Component In comp.GetChildren()

If Not pList.Contains(child.DisplayName) Then pList.Add(child.DisplayName)

getComps(child, indent + 1)

Next

End Sub

Function FindDrawings(ByVal modelPath As String, ByRef dwgList As List(Of String)) As Integer

'search folder of work part to find drawings
Dim searchFolder As String = IO.Path.GetDirectoryName(modelPath)
Dim baseNumber As String = IO.Path.GetFileNameWithoutExtension(modelPath)
'lw.WriteLine("search folder: " & searchFolder)

Dim dwgs As New List(Of String)

'Dim searchPattern As String = "[-|_]dwg(\.\d*)?"
Dim searchPattern As String = baseNumber & "_11[0|2]\d*$"

Dim prtFiles() As String = IO.Directory.GetFiles(searchFolder, "*.prt")
For Each prt As String In prtFiles
If Regex.IsMatch(IO.Path.GetFileNameWithoutExtension(prt), searchPattern) Then
dwgs.Add(prt)
dwgList.Add(prt)
End If
Next

Return dwgs.Count

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

Thank you very much!
I am now learning to write scripts in VB myself.
I will test and look trough your code tomorrow.
Thank you for your help, I really appriciate it!

Hi,

I am editing your code to use it with a different naming method.
For 1 particualr part I get a journal execution error from which I can't find the couse. It says NXOpen.NXException: Invalid file name at NXopen.UF.UFClone.PerformClone(NamingFailures_naming_failures).

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF
Imports NXOpen.UI

Module Cloon_Tool

Dim theSession As Session = Session.GetSession()

Dim theUFS As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()

Dim theUISession As UI = ui.GetUI

Public lw As ListingWindow = theSession.ListingWindow

Public pList As New List(Of String)

Sub Main()

' when there is a part loaded, error!
If Not IsNothing(theSession.Parts.Display) Then
theUISession.NXMessageBox.Show("Error", NXOpen.NXMessageBox.DialogType.Error, "There is allready a part loaded. Close the part and try again!...")
Exit Sub
End If

' searching Excel- and NX-Data
Dim OFD As New OpenFileDialog

OFD.Title = "Please select an assembly"
OFD.Filter = "NX-Files (*.prt) |*.prt"
OFD.InitialDirectory = "C:\"

Dim BGfileName As String
Dim BGDirectory As String

If OFD.ShowDialog = DialogResult.OK Then

BGDirectory = Replace(OFD.FileName, System.IO.Path.GetFileName(OFD.FileName), "")
BGfileName = System.IO.Path.GetFileName(OFD.FileName)

Else

Exit Sub

End If

' loading assembly
' error when assembly can't be loaded
Dim loadStatus As PartLoadStatus
Dim BG As Part = theSession.Parts.OpenBaseDisplay(BGDirectory & BGfileName, loadStatus)
If loadStatus.NumberUnloadedParts > 0 Then
theUISession.NXMessageBox.Show("Error!", NXOpen.NXMessageBox.DialogType.Error, "Error loding the assembly!" & vbNewLine & "Number of unloaded parts: " & loadStatus.NumberUnloadedParts & vbNewLine & "Check your loading options...")
Exit Sub
End If

Dim displayPart As Part = theSession.Parts.Display

Dim c As ComponentAssembly = displayPart.ComponentAssembly
If Not IsNothing(c.RootComponent) Then

pList.Add(c.RootComponent.DisplayName)

getComps(c.RootComponent, 0)

Else

theUISession.NXMessageBox.Show("Error", NXOpen.NXMessageBox.DialogType.Error, "Part is not an assembly!")
Exit Sub

End If

Dim value As String = String.Join(vbNewLine, pList)
lw.Open()
lw.WriteLine(vbNewLine & vbNewLine & "Parts List:" & vbNewLine & value & vbNewLine & vbNewLine)
'lw4.Close()

'checking drawings
Dim drwList As New List(Of String)
Dim numNotFound As Integer = 0
Dim notFound As String = ""
lw.WriteLine(vbNewLine & vbNewLine & "DRAWINGS ZOEKEN....." & vbNewLine)
For Each temp As String In pList
Dim tmpPart As Part
Try
tmpPart = CType(theSession.Parts.FindObject(temp), Part)
Catch ex As Exception
theUISession.NXMessageBox.Show("Error", NXOpen.NXMessageBox.DialogType.Error, "Part " & temp & " is corrupt or not loaded!")
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
Exit Sub
End Try
If FindDrawings(tmpPart.FullPath, drwList) = 0 Then
notFound &= tmpPart.Leaf & vbNewLine
numNotFound += 1
End If
Next
'Dim drwListValues As String = String.Join(vbNewLine, drwList)
'lw4.WriteLine(vbNewLine & vbNewLine & "Gevonden drawings:" & vbNewLine & drwListValues & vbNewLine & vbNewLine)

' MessageBox mit nicht gefundenen Zeichnungen anzeigen
' in this particular case, the suffix for the drawing can take many forms; the english version of this message could be changed to something like:
' "Drawings for the following parts could not be found:"
'Dim lw2 As ListingWindow = theSession.ListingWindow
'lw2.Open()
If numNotFound > 0 Then
If theUISession.NXMessageBox.Show("Drawing Inspection!", NXOpen.NXMessageBox.DialogType.Question, "Drawings for the following parts could not be found: " & vbNewLine & vbNewLine & notFound & vbNewLine & vbNewLine & "Press ""Yes"" to proceed, press ""No"" to abort...") = 2 Then
Exit Sub
End If
'lw2.WriteLine(notFound)
End If
'lw2.Close()

'Ausgabeverzeichnis auswählen
Dim theDirectory As String

Dim FolderBrowserDialog1 As New FolderBrowserDialog
With FolderBrowserDialog1

.RootFolder = Environment.SpecialFolder.Desktop

.SelectedPath = "Please set path to initial directory..."

.Description = "Please select an output directory..."

If .ShowDialog = DialogResult.OK Then

theDirectory = .SelectedPath

Else

Exit Sub

End If

End With

Dim cloner As NXOpen.UF.UFClone = theUFS.Clone

Dim opt As NXOpen.UF.UFClone.ExLogOpts
opt.allow_missing_components = False

cloner.Initialise(NXOpen.UF.UFClone.OperationClass.CloneOperation)
cloner.SetDefNaming(UFClone.NamingTechnique.NamingRule)
cloner.SetDefDirectory(theDirectory)
cloner.AddAssembly(BGDirectory & BGfileName, Nothing)

'Zeichnungen anhängen
For y As Integer = 0 To drwList.Count - 1
cloner.AddPart(drwList.Item(y))
Next

' Hier Namensgebung (aktuell: Dateinamen beibehalten)
Dim namerule1 As NXOpen.UF.UFClone.NameRuleDef
namerule1.type = UFClone.NameRuleType.ReplaceString
namerule1.new_string = ""

cloner.SetNameRule(namerule1, Nothing)
'Teilefamilien
cloner.SetFamilyTreatment(UFClone.FamilyTreatment.TreatAsLost)
cloner.SetLogfile(theDirectory & "\" & BGfileName.Replace(".prt", "_export.txt"))
cloner.SetDryrun(False)
cloner.PerformClone(Nothing)
cloner.Terminate()

'alle Teile schließen und Meldung geben
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)

theUISession.NXMessageBox.Show("Clone Operation", NXOpen.NXMessageBox.DialogType.Information, "The assembly export is completed!")

End Sub

Sub getComps(ByVal comp As Component, ByVal indent As Integer)
'Dim lw1 As ListingWindow = theSession.ListingWindow
'lw1.Open()
For Each child As Component In comp.GetChildren()

If Not pList.Contains(child.DisplayName) Then pList.Add(child.DisplayName)
'lw1.WriteLine(child.DisplayName & vbNewLine)
getComps(child, indent + 1)

Next
'lw1.Close()
End Sub

Function FindDrawings(ByVal modelPath As String, ByRef dwgList As List(Of String)) As Integer

'search folder of work part to find drawings
Dim searchFolder As String = IO.Path.GetDirectoryName(modelPath)
Dim baseNumber As String = IO.Path.GetFileNameWithoutExtension(modelPath)
lw.WriteLine("ZOEKEN NAAR:" & baseNumber & vbNewLine)

'lw.WriteLine(vbNewLine & vbNewLine & "search folder: " & searchFolder & vbNewLine)
'lw.WriteLine(vbNewLine & vbNewLine & "Drawings Found:" & vbNewLine)

Dim dwgs As New List(Of String)

'Dim searchPattern As String = "[-|_]dwg(\.\d*)?"
'Dim searchPattern1 As String = Regex.Escape(baseNumber) + "_DRW"
'Dim searchPattern2 As String = baseNumber & "_11[0|2]-\d*$"

Dim prtFiles1() As String = IO.Directory.GetFiles(searchFolder, "*.prt")
'Dim lw3 As ListingWindow = theSession.ListingWindow
'lw3.Open()
For Each prt As String In prtFiles1
If Regex.IsMatch(IO.Path.GetFileNameWithoutExtension(prt), "^" & Regex.Escape(baseNumber) + "_DRW$") Then
dwgs.Add(prt)
dwgList.Add(prt)
lw.WriteLine(vbNewLine & "GEVONDEN:" & prt & vbNewLine & vbNewLine)
End If
Next
'lw3.Close

'Dim prtFiles2() As String = IO.Directory.GetFiles(searchFolder, "*.prt")
'For Each prt As String In prtFiles2
' If Regex.IsMatch(IO.Path.GetFileNameWithoutExtension(prt), searchPattern2) Then
' dwgs.Add(prt)
' dwgList.Add(prt)
' End If
'Next

Return dwgs.Count

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

When you print the part paths to the information window, do you notice anything strange or unexpected in the part names?

No, it is always stopping at the same part which is my main assembly drawing: 80T001-0264-0100_1_DRW.prt the program tells me that the clone is made but it is not showing up in the destination folder. I can't find out what is going wrong. Seems to be something in cloner.PerformClone(Nothing) action...

Are you exporting the clone files to a new folder (one that does not contain any of the parts currently being cloned)? It appears that the clones will have the same name as the originals, if they are output to the same folder as the original it may overwrite the originals or error out because the file already exists.

Also, does your code run correctly on other assembly files? If so, it may be that this particular file is corrupt and, for some unknown reason, the clone operation cannot be completed.

Yes I export everything to a new folder. And yes it clones correctly on other assemblys with the same file naming format. So I think the file is corrupt like you mentioned. Thank you for your help!!!

Hello All,

this is my visit to this website to share my work problem.

Problem - my work is to transfer a point attribute to sphere

I have a big file which contains thousands of points for which I create sphere by macro (number of points = number of sphere). Creating sphere w.r.t all points need to transfer attribute which points has to respective created sphere.

You can use the .GetUserAttributes method to find all the attributes on a specific object. Here's the strategy that I'd use in your case:

  • Iterate through the points collection
  • Use .GetUserAttributes on the point object to find the attributes that have been assigned to that particular point.
  • Create a sphere object at the point location.
  • Create attributes on the sphere object based on the point attributes.

Please provide some example on .GetUserAttributes method

can you please update the code with English language since am getting errors while running the code.