Improve Macro Save X_T in a subfolder?

Following my old question, I would like to improve my macro to save my X_T in a subfolder of the room location?

We would have a part or assembly file in a folder and in this folder a subfolder called "FILES X_T" or our macro would save my exported file.

How do you make these changes?

 

Current program:

 

Sub Sauvegarde_X_T()

 

   
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Locatie As String
Dim Locatie_aangepast As String
Dim OpenDoc As Object
Dim Extensie_nieuw As String
Dim Extensie_oud As String
Dim retval As String
Dim Naam As String
Dim Naam_aangepast As String

 

Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set OpenDoc = swApp.ActiveDoc()

Extensie_oud = ". SLDASM"
Extensie_nieuw = ". X_T"
Locatie = OpenDoc.GetPathName
Locatie_aangepast = Left(Locatie, Len(Locatie) - 7)
retval = Dir$(Locatie_aangepast & Extensie_oud)
Naam = Dir$(Locatie)
Naam_aangepast = Left(Naam, Len(Naam) - 7)
Titel = OpenDoc.GetTitle
Titel = Left(Titel, (Len(Titel)))


' If retval = Naam Then
'nRetval = swApp.SendMsgToUser2(Naam_aangepast & " DXF created !!!", swMbWarning, swMbOk)
' End If
    
    
Set Part = swApp.ActiveDoc
longstatus = Part.SaveAs3(Naam_aangepast & Extensie_nieuw, 0, 0)

End Sub


save_x_t.swp

Try to replace

longstatus = Part.SaveAs3(Naam_aangepast & Extensie_nieuw, 0, 0)

By this:

FilePath = Left(PathName, InStrRev(PathName, "\"))
FileName = Right(PathName, Len(PathName) - InStrRev(PathName, "\"))
longstatus = Part.SaveAs3(FilePath & "\Fichier_XT\" & Extensie_nieuw, 0, 0)

----------------------

By the way, take the opportunity to delete:

  ' If retval = Naam Then
        'nRetval = swApp.SendMsgToUser2(Naam_aangepast & " DXF created !!! ", swMbWarning, swMbOk)
   ' End If

 

2 Likes

ok I'll test :) Thank you, I'll keep you posted.

CAREFUL:

I have made an oversight!

Dim FilePath As String, FileName As String

FilePath = Left(Locatie, InStrRev(Locatie, "\"))
MsgBox FilePath & "Fichiers_XT" & Naam_aangepast & Extensie_nieuw
longstatus = Part.SaveAs3(FilePath & "Fichiers_XT\" & Naam_aangepast & Extensie_nieuw, 0, 0)

1 Like

ok I'll watch tonight or tomorrow anyway ...

I just tried, it's perfect except for the name of my folder that I named: "X_T FILES"

This gives:

 

Sub Sauvegarde_X_T()


Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Locatie As String
Dim Locatie_aangepast As String
Dim OpenDoc As Object
Dim Extensie_nieuw As String
Dim Extensie_oud As String
Dim retval As String
Dim Naam As String
Dim Naam_aangepast As String

 

Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set OpenDoc = swApp.ActiveDoc()

Extensie_oud = ". SLDASM"
Extensie_nieuw = ". X_T"
Locatie = OpenDoc.GetPathName
Locatie_aangepast = Left(Locatie, Len(Locatie) - 7)
retval = Dir$(Locatie_aangepast & Extensie_oud)
Naam = Dir$(Locatie)
Naam_aangepast = Left(Naam, Len(Naam) - 7)
Titel = OpenDoc.GetTitle
Titel = Left(Titel, (Len(Titel)))


    
Set Part = swApp.ActiveDoc

Dim FilePath As String, FileName As String

FilePath = Left(Locatie, InStrRev(Locatie, "\"))
MsgBox FilePath & "X_T FILES" & Naam_aangepast & Extensie_nieuw
longstatus = Part.SaveAs3(FilePath & "FILES X_T\" & Naam_aangepast & Extensie_nieuw, 0, 0)

End Sub


save_x_t_-_fichiers_x_t.zip

Come on, if I want that when the "X_T FILES" folder doesn't exist, that it can create it to insert the exported file in it, how should we program that?

Creating folders or subfolders is good in auto it's better

the only problem in my opinion is that in your parts files if you end up with X under folders

Parasolid, iges, sat etc.....

The manipulation will be less easy I think to know if you have converted this or that file

You will be forced to open these said subfolders to know whether or not they are there and correspond to your part or assembly

Automatism is good but can be dangerous in my opinion to check  them so in the end a waste of time

@+;-))

I already work like this with my pdf and dxf for my plans and it suits me very well. Anyway it's like BatchConverter except by looking at the date and if it was created, there's no real way to see if it's ok.

So if anyone has a proposal?

1 Like

On the other hand I think that nothing prevents you from saving the various versions in the parts files

and to make a copy of these in a separate folder (good for fab or other) in different ways  

extensions one file per extension and per purpose

@+ ;-))

A new question?

Well, the goal is to do that in auto with a macro.

I don't really see the problem...

I already work like this for 2D plans. I've never had a problem, anyway I check what I'm doing very regularly.

After all, everyone has their own working method. I'm mine:)

So if anyone has a proposal?

1 Like