Thank you for reply!
I try to create a part within assembly with displaying the thumbnail of template.
So, what I try to do is the following in sequence.
1.Save the template file in the folder "Content Center Files" in advance.
2.Place the template file from the folder "Content Center Files" with command "Place Component".
3.Copy the file to the folder in Workspace with serial number.
4.Replace the template file with the copy.
The problem has occurred at step 3.
When name of new file is same as the unsaved part created with name by command "Create In-Place Component" or "Copy Component",
the unsaved part isn't exist in the folder, so New file is overwritten by the unsaved part as shown in screencast.
So, I should check the new file name with the unsaved parts name, but I don't know how to do.
How should I do?
The code is as below,and screencast is posted.
Sub PlaceTemplate()
Call ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
Do
ThisApplication.UserInterfaceManager.DoEvents
Loop Until ThisApplication.CommandManager.ActiveCommand <> "AssemblyPlaceComponentCmd"
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveEditDocument
Dim oTopDoc As AssemblyDocument
Set oTopDoc = ThisApplication.ActiveDocument
Dim oEditOccu As ComponentOccurrence
Set oEditOccu = oTopDoc.ComponentDefinition.ActiveOccurrence
Dim oOcc As ComponentOccurrence
Dim oOccName As String
Dim oNewDocNum As String
oNewDocNum = oAsmDoc.ComponentDefinition.Occurrences.Count
'Within sub assembly or top assembly
If Not (oAsmDoc Is oTopDoc) Then
Set oOcc = oEditOccu.SubOccurrences.Item(oNewDocNum)
Else
Set oOcc = oAsmDoc.ComponentDefinition.Occurrences.Item(oNewDocNum)
End If
oOccName = oOcc.Definition.Document.FullFileName
'Specify the folder
Dim oWSPath As String
oWSPath = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath + "\PART\"
'Specify the file name
Dim oNewOccName As String
oNewOccName = oWSPath + "TEST" + Format(Date, "yymmdd") + "_PART"
'Confirm the existence of the file
If Dir(oWSPath, vbDirectory) = "" Then
MkDir (oWSPath)
End If
Dim fCount As Integer
Dim oNewPart As String
For fCount = 1 To 999
oNewPart = oNewOccName + CStr(fCount) + ".ipt"
If Dir(oNewPart) = "" Then
Call ThisApplication.FileManager.CopyFile(oOccName, oNewPart)
'Replace component
Call oOcc.Replace(oNewPart, True)
Exit For
End If
Next
End Sub
Thank you.