Indeed, it works by creating a plan.
It works perfectly for me. The name of the sketch is of the configuration do not have the point.
The code:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim SkPicture As Object
Dim System As Scripting.FileSystemObject 'File System
Dim Folder As Folder 'Directory'
Dim File As File ' File (Part of the Files Collection)
Dim Nom_Dossier As String ' Directory Name
Dim Nom_Fichier As String ' File Name
Dim Nom_EsquisseAV As String ' Front Sketch Name
Sun Nom_EsquisseAP As String ' Sketch Name After
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.OpenDoc6("C:\Users\rmorel\Desktop\Part1.SLDPRT", 1, 0, "", longstatus, longwarnings)
'Reading the directory
Nom_Dossier = "C:\Users\rmorel\Desktop\Test"
System Set = CreateObject("Scripting.FileSystemObject")
Set Folder = System.GetFolder(Nom_Dossier)
'Control each file in the directory
k = 2
For Each File In Folder.Files
Create Sketch Image and Update Dimensions
Nom_Fichier = Nom_Dossier & "\" & Fichier.Name
Nom_EsquisseAP = Left(Fichier.Name, Len(Fichier.Name) - 4)
boolstatus = Part.Extension.SelectByID2("Plan to 4mm", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Set SkPicture = Part.SketchManager.InsertSketchPicture(Nom_Fichier)
SkPicture.SetSize 50 / 1000, 60 / 1000, False
SkPicture.SetOrigin -25/1000, -20/1000
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, 1, 0, Nom_EsquisseAP)
boolstatus = Part.Extension.SelectByID2(Nom_EsquisseAP, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.EditSuppress2
boolstatus = Part.Extension.SelectByID2("AM_P01_HO", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.AddConfiguration2("AM_" & Nom_EsquisseAP, "", "", False, False, False, True, 256)
Part.ClearSelection2 True
Next File
End Sub