determine how a dimension is configured

Programming and macros
colt
Posts: 56
Joined: Tue Mar 30, 2021 5:43 pm
Answers: 0
x 14
x 22

determine how a dimension is configured

Unread post by colt »

I have a part with multiple derived configurations. I sometimes make the mistake of editing dims inside the derived config thinking I am in the parent. I want to make a macro that will check that all dimensions in my derived config are linked to the parent config. So far I am able to check if the dim has been configed, but I have to check to see if it is linked to parent manually.

-Thanks

linked.PNG
linked.PNG (7.45 KiB) Viewed 647 times
configSpecific.PNG
configSpecific.PNG (8.04 KiB) Viewed 647 times

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swSkRelMgr As SldWorks.SketchRelationManager
Dim swSketch As SldWorks.Sketch
Dim swDispDim As SldWorks.DisplayDimension
Dim coreDim As SldWorks.Dimension
Dim swAnn As SldWorks.Annotation
Dim vSkRelArr  As Variant
Dim vSkRel As Variant
Dim dimName As String
Dim result As Boolean

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSketchMgr = swModel.SketchManager
Set swSketch = swSketchMgr.ActiveSketch
Set swSkRelMgr = swSketch.RelationManager
vSkRelArr = swSkRelMgr.GetRelations(0)

'setup by editing sketch inside derived config
'attempt to find dimensions in active sketch that are configuration specific and not linked to parent config
swModel.ClearSelection2 (True)
For Each vSkRel In vSkRelArr
    Set swSkRel = vSkRel
    t = swSkRel.GetRelationType
    If (t = swConstraintType_e.swConstraintType_DISTANCE) Or (t = swConstraintType_e.swConstraintType_DIAMETER) Or (t = swConstraintType_e.swConstraintType_ANGLE) Or (t = swConstraintType_e.swConstraintType_RADIUS) Then
        Set swDispDim = swSkRel.GetDisplayDimension
        Set coreDim = swDispDim.GetDimension2(0)
        If coreDim.IsAppliedToAllConfigurations = False Then 'highlight all dims that are configured for manual checking
            Set swAnn = swDispDim.GetAnnotation
            swAnn.Select (True)
            'how to check to see if dim is linked to parent configuration.
        End If
    End If
Next
End Sub
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

Re: determine how a dimension is configured

Unread post by Austin Schukar »

I may be mistaken, but couldn't you use coreDim.GetValue3(swInConfigurationOpts_e.swLinkedToParent, Config_name) to check?
Austin
colt
Posts: 56
Joined: Tue Mar 30, 2021 5:43 pm
Answers: 0
x 14
x 22

Re: determine how a dimension is configured

Unread post by colt »

Maybe I used it wrong, but getValue3 function returned an empty value for me instead of the expected array. Tried setting "Config_name" to empty as well as the name of my derived config. I did get a result when I used swInConfigurationOpts_e.swThisConfiguration.

Instead I was able to test the value of the dim against the parent config. This will guarantee the derived config matches at least. Still cant detect an error waiting to happen though...

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSketchMgr As SldWorks.SketchManager
Dim swSkRelMgr As SldWorks.SketchRelationManager
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim swParentConfig As SldWorks.Configuration
Dim swSketch As SldWorks.Sketch
Dim swDispDim As SldWorks.DisplayDimension
Dim coreDim As SldWorks.Dimension
Dim swAnn As SldWorks.Annotation
Dim vSpecConfigNameArr As Variant
Dim vSkRelArr  As Variant
Dim vSkRel As Variant
Dim vDimValArr As Variant
Dim vDimVal As Variant
Dim dimName As String
Dim result As Boolean
Dim dimA As Double
Dim dimB As Double

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSketchMgr = swModel.SketchManager
Set swSketch = swSketchMgr.ActiveSketch
Set swSkRelMgr = swSketch.RelationManager
vSkRelArr = swSkRelMgr.GetRelations(0)
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Set swParentConfig = swConfig.GetParent

'setup by editing sketch inside derived config
'attempt to find dimensions in active sketch that are configuration specific and not linked to parent config
swModel.ClearSelection2 (True)
vConfigNameArr = swModel.GetConfigurationNames
For Each vSkRel In vSkRelArr
    Set swSkRel = vSkRel
    t = swSkRel.GetRelationType
    If (t = swConstraintType_e.swConstraintType_DISTANCE) Or (t = swConstraintType_e.swConstraintType_DIAMETER) Or (t = swConstraintType_e.swConstraintType_ANGLE) Or (t = swConstraintType_e.swConstraintType_RADIUS) Then
        Set swDispDim = swSkRel.GetDisplayDimension
        Set coreDim = swDispDim.GetDimension2(0)
        If coreDim.IsAppliedToAllConfigurations = False Then 'candidate for more detailed test
            dimA = coreDim.GetValue2(swConfig.Name)
            dimB = coreDim.GetValue2(swParentConfig.Name)
            If Not dimA = dimB Then
                Set swAnn = swDispDim.GetAnnotation
                swAnn.Select (True)  'dims dont match, so highlight
            End If
        End If
    End If
Next
End Sub
Post Reply