Macro - Apply Property Forms (.asmprp, .drwprp, .prtprp)

Hello!

I'm working on a macro in order to, among other things, apply my new property forms to old files that still use the old ones.

I'd like to know if you would know how to go and get the .asmprp, .drwprp and .prtprp files and apply them to an asm, drw or prt with  a macro.

Thank you in advance if you have a lead.

Have a nice day

Without checking, I found this:

sub main()
application.sldworks.activedoc.extension.custompropertybuildertemplate(false) = "whatever.prtprp"
end sub

https://help.solidworks.com/2020/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IModelDocExtension~CustomPropertyBuilderTemplate.html?verRedirect=1

 

Spring:

https://www.cadforum.net/viewtopic.php?t=26

 

Hello

Thank you 2. To Damien for the idea and Sdadenis for the solution.

Attached is my macro with file type test.

Have a nice day.


appliquer_formulaires_de_proprietes.swp

Thank you, for the leads!

I've come up with something that seems to work. It's certainly neither perfect nor optimized, I'm just starting out...

Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

• Controls whether a document is opened in SolidWorks
If swModel Is Nothing Then
MsgBox "You need an open document to use this function!", vbInformation, "New MasqueMarking "

' Checks whether the open document is a document
ElseIf Application.SldWorks.ActiveDoc.GetType = swDocPART Then
' Check if the correct marking mask is already applied
If Not Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_PRT.prtprp" Then
Apply the correct marking mask
Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_PRT.prtprp"
End If
        
' Controls whether the open document is an assembly
ElseIf Application.SldWorks.ActiveDoc.GetType = swDocASSEMBLY Then
' Check if the correct marking mask is already applied
If Not Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_ASM.asmprp" Then
Apply the correct marking mask
Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_ASM.asmprp"
End If

' Controls whether the open document is a drawing
ElseIf Application.SldWorks.ActiveDoc.GetType = swDocDRAWING Then
' Check if the correct marking mask is already applied
If Not Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_DRW.drwprp" Then
Apply the correct marking mask
Application.SldWorks.ActiveDoc.Extension.CustomPropertyBuilderTemplate(False) = "Masque_marquage_DRW.drwprp"
End If
   
End If

End Sub

 

For a 1st dev it seems pretty good to me and rather well optimized, since you took into account the error handling.

It should indeed be functional, more than to be tested over time.