It's progressing well,
-Resize ok,
-Loop ok,
-The name almost ok:
If I don't leave the point to the end, Nom_EsquisseAP is not taken into account, it only works if there is the point...
I'm looking into the xD derived configurations
My 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 instance As ISketchPicture
Dim Width As Double
Dim Height As Double
Dim AspectRatioLocked As Boolean
Dim value As Boolean
Dim X Ace Double
Dim Y As Double
Dim System As Object ' File System
Dim Folder As Object ' Directory
Dim Files As Object 'Collection of files from the directory
Dim File As Object ' 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
Dim Nom_EsquisseAP As String ' Sketch Name After
Dim k As Integer
Sub main()
Set swApp = _
Application.SldWorks
Set Part = swApp.OpenDoc6("C:\Users\ad36aaen\Documents\Usage\Design SdC\1300\Basic Structures\Structures\Hardware\Hardware.SLDPRT", 1, 0, "", longstatus, longwarnings)
swApp.ActivateDoc2 "Hardware.SLDPRT", False, longstatus
Set Part = swApp.ActiveDoc
k = 1
'Reading the directory
Nom_Dossier = "C:\Users\ad36aaen\Documents\Usage\Design SdC\1300\Basic Structures\Structures\Hardware\Hardware Photos\P01\HO\Test"
System Set = CreateObject("Scripting.FileSystemObject")
Set Folder = System.GetFolder(Nom_Dossier)
Set Files = Folder.Files
'Loop
For Each File In Files
'Create names
Nom_Fichier = Nom_Dossier & "\" & Fichier.Name
Nom_EsquisseAV = "Sketch" & k
Nom_EsquisseAP = Left(Fichier.Name, Len(Fichier.Name) - 3)
'Selection Plan
boolstatus = Part.Extension.SelectByID2("Plan to 4mm", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
'Create Sketch Image
Part.SketchManager.InsertSketch True
Set SkPicture = Part.SketchManager.InsertSketchPicture(Nom_Fichier)
'Resize
SkPicture.SetSize 50 / 1000, 60 / 1000, False
SkPicture.SetOrigin -25/1000, -20/1000
Part.ClearSelection2 True
Select Sketch + Change Name
boolstatus = Part.Extension.SelectByID2(Nom_EsquisseAV, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, 1, 0, Nom_EsquisseAP)
Delete sketch state => will lighten when we are at the 1000th sketch
boolstatus = Part.Extension.SelectByID2(Nom_EsquisseAP, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.EditSuppress2
Part.ClearSelection2 True
k = k + 1
Next File
End Sub