Create pack and go with specified custom property as prefix

Hello everyone,
I have been searching for a macro for quite some time that allows me to replace the file name with the value of a custom property when copying data using the Pack and Go function.

By chance, I stumbled across the macro “Create pack and go with specified custom property as prefix” by Cad Sharp.

In a first attempt, I tried to append the content of the Revision property as a prefix.
When I run the macro in debug mode, I can see in the Immediate window that the variable with which the file is to be saved is formed correctly, but the files that are saved still have the same name as the original.

Is there anyone who uses this macro?
I don’t know if it’s allowed to post the code from CadSharp here, so I’ve left it out as a precaution.

Hello Hansjörg,

did you check both example of the API help? It might help you:
Welcome to the SOLIDWORKS Web Help.._gaMTcyMDQyOTk5NS4xNzYyODQyOTU2*_ga_XQJPQWHZHH*czE3NjI4NDI5NTYkbzEkZzAkdDE3NjI4NDI5NTYkajYwJGwwJGgw

and here’s another one:
Welcome to the SOLIDWORKS Web Help .._gaNDA0Mjc1NzU2LjE3NjI4NDMzOTA._ga_XQJPQWHZHHczE3NjI4NDMzODkkbzEkZzEkdDE3NjI4NDM0NTAkajYwJGwwJGgw

You can put a link to that macro here instead of the codes.

The macro can be downloaded from this page:

https://www.cadsharp.com/macros/create-pack-and-go-with-specified-custom-property-as-prefix/

However, you must register to access the page.

I have identified the problem. As soon as the assembly contains a virtual component, the macro no longer works. For virtual components, the original file name must be retained when executing Pack and Go.
The following sequence is used in the macro to determine whether it is a virtual component…

Set swCompModel = swApp.GetOpenDocumentByName(strSetPathNames(i))
    If Not swCompModel Is Nothing Then
        'Get the custom property value
        Set swCustPropMgr = swCompModel.Extension.CustomPropertyManager(Empty)
        swCustPropMgr.Get4 strCustProp, True, Empty, strValOut
    Else    'if virtual component
        strValOut = Empty
    End If

However, the condition does not apply to a virtual component.

I will try to see if I can solve the problem with Component2::IsVirtual, or alternatively via the storage path of the virtual component.

1 Like