Make a macro to resize sketch images

My name: KT211.bmp

If I take KT211(.bmp)

My Nom_EsquisseAP is equal to KT211 (cf MsgBox)

But therein lies the problem, the name of sketch does not change

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)

 

On the other hand, if I leave the KT211 point, then it works, the sketch name is indeed modified.

 

The modifications are just the double set part and the "files" that you replace directly with folder.files (instead of folder.files?) to avoid creating a set of files that is only used once. I haven't seen another one xD

Can you send me the part file as well as the folder containing some images?

So that I can test

So that's not going to be possible xD. I am a nuclear engineer.

 

For your information everything is in deleted state in my room, so if there are no rooms it's the same.

Quickly create a folder with 3 images in it and it will work the same way.

1 Like

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

 

Here, I found a bug by the way.

It's related to my variable k to move on to the other sketch that I lifted because it was no longer useful.

The BUG

- Creates a sketch

- Renamed the

- Create a new sketch => it will be called sketch2

 

- Creates a sketch

- Renamed the

- Creates a configuration

- Create a new sketch => it will be called sketch1

 

To put it simply, the configuration allows for an update, so for a sketched code you will have to take into account whether you are creating configurations or not.

For my part, without I needed an increment k and to call the "sketches" & k

With configuration I just have to call the "sketch1"

 

Xd

Azrod

Hello

That's a big thing. Good luck to whoever makes it:)

I imagine that not all photos have the same dimensions?

 

\o/  \o/  \o/  \o/  \o/  \o/ \o/  \o/  \o/  \o/  \o/  \o/  \o  / \o/ \o/     \o/ \o  

Resolute

1 Like

How and by what means???

1 Like

You can find all the code in the discussions...

If it's to discuss a detail, don't hesitate to ask your question. Try to be a little more precise than how you did it xD.

 

As a reminder:

- Insert a sketch image

- Changing the dimension of the sketch image after inserting it

- Dimensioning according to the type of material

- Sketch Name = Material Name

- Create a configuration

- Configuration Name = Hardware Name

- Loop on all materials in a file