It's my first time with the CustomPropertyManager and I'm just wondering is this right?
I am inserting an envelope in an assembly and then making it virtual before I go in and change the custom properties.
My complete code is below, but here's the relevant bit
Debug.Print "Custom Properties"
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("Default")
Dim Names As Variant
Dim Types As Variant
Dim Values As Variant
Dim ResolvedValues As Variant
Dim i As Integer
With swCustPropMgr
ls = .GetAll2(Names, Types, Values, ResolvedValues)
Debug.Print "GetAll2 Status > Returned:"; ls
Debug.Print " #", "Type", "ResolvedValue", "Value", "Name"
Debug.Print String\$(80, "-")
For i = 0 To ls - 1
Debug.Print i + 1, Types(i), ResolvedValues(i), Values(i), Names(i)
Next
End With
Why are all my resolved values = 2 ?
from the help file
Dim instance As ICustomPropertyManager
Dim PropNames As System.Object
Dim PropTypes As System.Object
Dim PropValues As System.Object
Dim Resolved As System.Object
Dim value As System.Integer
value = instance.GetAll2(PropNames, PropTypes, PropValues, Resolved)
As a brief aside I wasn't certain how to go about doing this and tried various methods.
I found that ActivateDoc3 reported an error if the file wasn't saved. I didn't find this in the documenation.
2016 SOLIDWORKS API Help - swActivateDocError_e Enumeration
ActivateDoc3 Status > Errors: 8
Anyway error or not, it still worked just the same, here's my code
Thanks for looking
SolidworksApi macrosOption Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swAssem As SldWorks.AssemblyDoc
Dim EnvelopeComponent As SldWorks.Component2
Dim swDimension As SldWorks.Dimension
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim ls As Long, lw As Long
Dim bs As Boolean
Sub main()
Set swApp = Application.SldWorks
With swApp
Set swModel = .NewDocument(DefaultAssTemplate, 0, 0, 0)
bs = .RunCommand(swCommands_Save, "")
Set EnvelopeComponent = swModel.InsertEnvelope(EnvelopeName, "", 0, 0, 0)
swModel.ViewZoomtofit2
bs = EnvelopeComponent.MakeVirtual2(False)
bs = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_SaveReferenced _
, errors:=ls, warnings:=lw)
Debug.Print _
".Save3 Status > error:"; ls, "warning:"; lw
Set swModel = .ActivateDoc3(EnvelopeComponent.GetPathName _
, UseUserPreferences:=False _
, Option:=swRebuildOnActivation_e.swRebuildActiveDoc _
, errors:=ls)
Debug.Print _
"ActivateDoc3 Status > Errors:"; ls
End With
Debug.Print "Custom Properties"
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("Default")
Dim Names As Variant
Dim Types As Variant
Dim Values As Variant
Dim ResolvedValues As Variant
Dim i As Integer
With swCustPropMgr
ls = .GetAll2(Names, Types, Values, ResolvedValues)
Debug.Print "GetAll2 Status > Returned:"; ls
Debug.Print " #", "Type", "ResolvedValue", "Value", "Name"
Debug.Print String\$(80, "-")
For i = 0 To ls - 1
Debug.Print i + 1, Types(i), ResolvedValues(i), Values(i), Names(i)
Next
End With
End Sub
Private Function EnvelopeName() As String
EnvelopeName = swApp.GetCurrentMacroPathFolder & "\" & "Default Table Top.SLDPRT"
End Function
Private Function DefaultAssTemplate() As String
DefaultAssTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateAssembly)
End Function