Folder Name Recovery Without Path

Hello

I try to retrieve the folder name (client file) and then the subfolder name (business folder) to automatically display them in my title block.

With the "folder name" property I can display the path of the folder and not its name, I had seen a tutorial to select only the part searched for in this path but I can't get my hands on it anymore. 

I would like to display in my CUSTOMER block..........    CASE ............, both taken from the windows folders.

If possible without using PDM.

Thank you.

Hello

It's possible with a macro or maybe with equations, see these links:

http://www.lynkoa.com/forum/solidworks/comment-recuperer-le-nom-d-un-fichier-avec-une-macro

http://www.lynkoa.com/store/fr/vba-solidworks-nom-fichier.html

 

1 Like

Thank you PL

But I would need to retrieve the folder name and not the file name.

I manage to make a macro but only for a single file, I should be able to retrieve the name of the folder but with a link to the piece. 

I think I found something but I would need help applying it, I managed to copy and paste the code into a macro, I launch the macro but nothing happens. 

https://forum.solidworks.com/thread/65304#345645

Hello

Have you addressed each variable properly in your macro?

 

Explicit  option 

  

 Sub main()  

  

    Dim swApp                      As SldWorks.SldWorks  

    Dim swModel                    As SldWorks.ModelDoc2  

    Dim swPart                      As SldWorks.PartDoc  

    Dim bRet                        As Boolean  

    Dim MyPath                      As String  

    Dim MyFolder                    As String  

  

    Set swApp = Applicatio.SldWorks  

    Set swModel = swApp.ActiveDoc  

    Set swPart = swModel  

  

    MyFolder = CurDir$   

    MyPath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") - 1)  

    MyPath = Right(MyPath, Len(MyPath) - InStrRev(MyPath, "\"))  

  

    Debug.Print "File = " & swModel.GetPathName  

    Debug.Print "Folder = " & MyPath  

    Debug.Print "Current Folder = " & MyFolder  

  

  

End Sub

1 Like

Azrod, I admit I don't understand anything, I copied your code and then pasted it into a new macro (an "n" is missing from the application. SldWorks, but nothing happens, in the local variables window I get: see screenshot.

 


capture_macro1.png

I tried again and I get something else.


capture_macro2.png

Good evening

In my opinion there are probably errors at compilation or execution.

Attached is a macro that works on a drawing and is based on the first associated view. To play with if it doesn't fit exactly.


macro_dossier.txt
1 Like

I still have an error 


capture_macro2.png

Try with:

Dim  swApp       As    SldWorks.Application

2 Likes

I didn't manage to do what I wanted to do, but it's not for lack of help on the forum in any case, thank you.

1 Like

I hadn't seen the second message. The error you make is related to the fact that you have twice Dim SwApp.