AnsweredAssumed Answered

Getting the location of display dimension lines in a drawing

Question asked by John Kangas on Oct 16, 2013
Latest reply on Oct 16, 2013 by John Kangas

I'm working on some drawing automation, and I need to reference the location of display dimension witness lines and dimension arrows. I've been using ModelDocExtension::AlignDimensions to do the bulk of the sorting of dimensions on drawings, but this method isn't consistent enough for automation. For example, I'm still having trouble with dimension text being placed on top of witness lines, or centered between witness lines that are too close together for the text to fit between, not to mention the hijinks that arclength or radius dimensions get into.


DisplayDimension text location is easy; but I think I might have hit the wall looking for the reference lines. It looks like Dimension::referencepoints might provide some clues, but I think I'm doing something wrong when I try to get each of the reference points. For example, there will be n points returned, and when I attempt to return referencepoints(n), the arraydata all return 0.

Or, am I overlooking a better way to return these values? For the moment, I'm stuck doing this in VBA, but if I need to do this in .net or C++, I'll find a way.


Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDrawing As SldWorks.DrawingDoc Dim swView As SldWorks.view Dim swDispDim As SldWorks.DisplayDimension Dim swDim As SldWorks.dimension Dim swPoint As SldWorks.MathPoint Dim swMath As SldWorks.MathUtility Dim refpoints As Variant Dim i As Integer Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDrawing = swModel Set swView = swDrawing.GetFirstView Set swMath = swApp.GetMathUtility Debug.Print String(255, vbNewLine) Do While Not swView Is Nothing     If swView.GetVisible Then     Set swDispDim = swView.GetFirstDisplayDimension5         Do While Not swDispDim Is Nothing             Set swDim = swDispDim.GetDimension2(0)             Debug.Print "Dimension name: " & swDim.GetNameForSelection             Debug.Print "Reference points count: " & swDim.GetReferencePointsCount             For i = 0 To swDim.GetReferencePointsCount - 1                 Set swPoint = swMath.CreatePoint(swDim.referencepoints(i)) ' this doesn't produce any errors, but isn't the right way                 Debug.Print swPoint.ArrayData(0) & "   " & swPoint.ArrayData(1) & "   " & swPoint.ArrayData(2) ' these all return as 0             Next i             Set swPoint = swMath.CreatePoint(swDim.referencepoints)             Debug.Print swPoint.ArrayData(0) & "   " & swPoint.ArrayData(1) & "   " & swPoint.ArrayData(2) ' this returns nonzero values             Set swDispDim = swDispDim.GetNext5             Debug.Print vbNewLine         Loop     End If     Set swView = swView.GetNextView Loop End Sub