Macro Help

Hello

 

I'm looking for a way to recover my room's location properties

 

Example: My document is saved in a "Case X" folder, in a "Client Y" folder

 

I would like the name of the client file and the name of the case to appear on my block.

 

Docn I want to retrieve the registration path and only show the name of the client and the case, because often I forget to indicate it and I realize it once the printing is finished.

 

Lucas had directed me to a macro.

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
 
Sub main()
 
 
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
 
 
swModel.AddCustomInfo2 "File Path", swCustomInfoText, Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))
 
 
End Sub
The macro doesn't have any errors, but I'm not sure how to do it afterwards.
So that this information ends up on my cartridge.
For your information, I go through a personal property form.
 
Thank you! =)
Hi, actually the macro should add a custom property called "File Path" that you can then use in your title block or in an annotation.
1 Like

Why does the personal property "File path" give me the name of the client file and the name of the business file?

 

How to divide them? I would have liked to have had the name of the client in one box, and of the case in another.

 

It's possible?

Well I did a test on an annotation.

 

I end up with the full path as if I had put the folder name property.

Can you put an example of a path by specifying the name of the client and the deal?
1 Like

Here is the screenshot

 

I would like to put "Client X" in the client box and "Affaire Y" in the construction site or Ref box.

 

 


macro.png

Then you have to add the following part before the End Sub:

 

filepath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\")) 
end = Len(filepath) - 1
pos_cli = InStrRev(filepath, "\", end)
client = Mid(filepath, pos_cli + 1, end - pos_cli)
pos_aff = InStrRev(filepath, "\", pos_cli - 1)
case = Mid(filepath, pos_aff + 1, pos_cli - 1 - pos_aff)

swModel.AddCustomInfo2 "Client", swCustomInfoText, client

swModel.AddCustomInfo2 "Deal", swCustomInfoText case
 

1 Like

There's probably a simpler solution, but at least it works!

The macro will add 2 more custom properties that you can use in your title block:

"Client" for the client's name

"Deal" for the deal number

 

1 Like

As long as it works, I'm fine with it!

 

it seems like a macro to me, but I have an error on the client= Mid line (FilePath, po_cli+1, end-pos_cli)

Indeed you have a mistake because you didn't copy and paste well!

It 's _cli and not po_cli 

1 Like

Edit: duplicate removal

1 Like

No, I just retyped badly on Lynkoa

 

I put correctly: client = Mid(FilePath, pos_cli + 1, end - pos_cli)


macros.png

Strange, what is the error?

1 Like

Runtime Error 5

 

Invalid argument or procedure call

Are you drying Lucas? :p ^^

1 Like
Sorry I didn't have time to test it more deeply, I'm looking at it tonight.
1 Like

No worries Lucas, it's nice of you!

 

I do this as a common thread, so it's not extremely urgent;)

In any case, your macro looks very good. You manage!

I really need to train myself on this....

 

Have a good end of the day!

1 Like

Sorry I don't understand, at home it works!

I'll put you in PJ the file that works at home so that you can test...

Thank you for the compliments and have a good end of the day to you too.


path.swp

I don't understand either...

 

At home or at the office, always the same mistake.

 

I'm under 2014.

 

A little photo novel? if you have the time of course!

Do you know how to use debugging for macros? Otherwise I can take control of your computer remotely?