ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MFMichael Ferraro29/05/2015

Hello All,

I am looking to write a macro to check if my assembly has 2 custom properties. I dont care what the value is, I just want to see if it has that custom property or not. The rest of the macro fills the property out however if the property doesn't exist it obviously cant fill it out If the assembly does not have one or both of them then I want to add each of the custom properties.

I am looking to make the loop and then just duplicate the loop for the other custom property. I dont need anything that is fancy that will do both at the same time. The two custom properties are called "Published As" and "Revision".

I am confusing myself a little bit as to where I should do this in the code/loop.

~~~~~~~~~~~~~~~

Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim swExt As SldWorks.ModelDocExtension
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim PublishedAs As String
Dim PropertyValue As String
Dim ResolvedPropertyValue As String
Dim ReturnValue As Integer
Dim CustomInfoName As Variant
Dim CustomInfoNameArray As Variant

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swExt = swModel.Extension
Set swCustPropMgr = swExt.CustomPropertyManager("")

CustomInfoNameArray = swModel.GetCustomInfoNames2("")
For Each CustomInfoName In CustomInfoNameArray
    If CustomInfoName <> "Published As" Then
    End If
Next

End Sub

~~~~~~~~~~~~~~~~

So if I put the add command inside the if statement wouldn't that not work? it needs to run through all the properties first and see if one is called "Published As" and if none are then create the property.

Thanks,

Pencil