I'm getting a weird result for DimensionLineDirection of an ordinate dimension.
For the basic dimension, the dimension line direction tells me the direction (in model coordinates?) of the dimension.
If I look at the model, this dimension is aligned with the Z-axis. This agrees with my understanding.
However, for the ordinate dimension, I get the following.
Basic Dimension:
[0,0,1]
Ordinate Dimension:
[1,0,0]
Actual direction in model coordinates:
[0,0,1]
My first guess was that the ordinate dimension's DimensionLineDirection is using the (Visible) extension line rather than the (Invisible) vector along which the dimension is measuring. However, if this were the case, it wouldn't be reported in the x-direction. If it was in drawing-coordinates, that line would be along the Y axis, if it were in model coordinates, that line would be along the Y axis still.
Does anyone have a guess?
Thanks,
John Alexander
SolidworksApi macros
Just a shot in the dark: Is this referenced document in the drawing view a part or an assembly? If it's an assembly, shouldn't you be considering the component's transform as well?
It is a drawing of a part.
I'm actually not transforming the DimensionLineDirection, my assumption has been that it is expressed with respect to the part document's coordinate system and so I've just been building my analysis around that coordinate system. So far this works fine for basic dimensions. However, when I dimension the exact same span with an Ordinate versus a Basic dimension, the direction is different.
Some more data points. I tried grabbing the ReferencePoints properties out of these dimensions.
2012 SOLIDWORKS API Help - ReferencePoints Property (IDimension)
My assumption follows that the value of the dimension (0.025 in this case) would equal the DimensionLineDirection.Dot(RefP1-RefP0). That is, the vector between the Reference Points projected onto the DimensionLineDirection should equal the value of the dimension.
For basic dimensions, this seems to be the case. For ordinate dimensions, I have no idea what is going on. the ReferencePoint coordinates aren't even remotely similar.
The first set of numbers is the ordinate dimension, the second set is from the basic dimension. These are the same pair of dimensions as described in the original post.
<p><span style="color: #0000ff; font-weight: bold;"> public</span> <span style="color: #a52a2a;">static</span> <span style="color: #ff0000; font-weight: bold;">bool</span> <span style="color: #191970; font-weight: bold;">DimensionIsAlignedWithHoleInstance</span>(<span style="color: #004085;">Tuple</span><<span style="color: #004085;">DisplayDimension</span>, <span style="color: #004085;">View</span>> positionalDimension, <span style="color: #004085;">HoleInstance</span> holeInstance, <span style="color: #ff0000; font-weight: bold;">int</span> direction){</p><p> <span style="color: #004085;">Dimension</span> dimension = positionalDimension.Item1.<span style="color: #191970; font-weight: bold;">GetDimension2</span>(<span style="color: #00008b;">0</span>);</p><p> </p><p> <span style="color: #ff0000;">object</span>[] oReferencePoints = (<span style="color: #ff0000;">object</span>[])dimension.ReferencePoints;</p><p> </p><p> <span style="color: #004085;">MathPoint</span> point0 = (<span style="color: #004085;">MathPoint</span>)(oReferencePoints[<span style="color: #00008b;">0</span>]);</p><p> <span style="color: #004085;">MathPoint</span> point1 = (<span style="color: #004085;">MathPoint</span>)(oReferencePoints[<span style="color: #00008b;">1</span>]);</p><p> <span style="color: #004085;">MathVector</span> difference = (<span style="color: #004085;">MathVector</span>)(point1.<span style="color: #191970; font-weight: bold;">Subtract</span>((<span style="color: #ff0000;">object</span>)point0));</p><p> <span style="color: #004085;">MathVector</span> dimensionDirection = (<span style="color: #004085;">MathVector</span>)dimension.DimensionLineDirection;</p><p> </p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">"P0: "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point0.ArrayData)[<span style="color: #00008b;">0</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point0.ArrayData)[<span style="color: #00008b;">1</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point0.ArrayData)[<span style="color: #00008b;">2</span>]);</p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">"P1: "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point1.ArrayData)[<span style="color: #00008b;">0</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point1.ArrayData)[<span style="color: #00008b;">1</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])point1.ArrayData)[<span style="color: #00008b;">2</span>]);</p><p> </p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">"Difference: "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])difference.ArrayData)[<span style="color: #00008b;">0</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])difference.ArrayData)[<span style="color: #00008b;">1</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])difference.ArrayData)[<span style="color: #00008b;">2</span>]);</p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">"Direction: "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])dimensionDirection.ArrayData)[<span style="color: #00008b;">0</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])dimensionDirection.ArrayData)[<span style="color: #00008b;">1</span>] + <span style="color: #0000ff;">", "</span> + ((<span style="color: #ff0000; font-weight: bold;">double</span>[])dimensionDirection.ArrayData)[<span style="color: #00008b;">2</span>]);</p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">"Value: "</span> + (<span style="color: #ff0000; font-weight: bold;">double</span>)difference.<span style="color: #191970; font-weight: bold;">Dot</span>((<span style="color: #ff0000;">object</span>)dimensionDirection));</p><p> <span style="color: #004085;">Console</span>.<span style="color: #191970; font-weight: bold;">WriteLine</span>(<span style="color: #0000ff;">""</span>);</p><p> }</p>Okay, I think I've figured it out.
The ordinate dimension reports its DimensionLineDirection with respect to the drawing coordinate system. The Basic dimension reports with respect to the model document. I just transform the direction vector whenever the DisplayDimension is an ordinate.
<p><span style="color: #0000ff; font-weight: bold;">public</span> <span style="color: #a52a2a;">static</span> <span style="color: #ff0000; font-weight: bold;">bool</span> <span style="color: #191970; font-weight: bold;">DimensionIsAlignedWithHoleInstance</span>(<span style="color: #004085;">Tuple</span><<span style="color: #004085;">DisplayDimension</span>, <span style="color: #004085;">View</span>> positionalDimension, <span style="color: #004085;">HoleInstance</span> holeInstance, <span style="color: #ff0000; font-weight: bold;">int</span> direction){</p><p> <span style="color: #004085;">Annotation</span> donk =(<span style="color: #004085;">Annotation</span>)positionalDimension.Item1.<span style="color: #191970; font-weight: bold;">GetAnnotation</span>();</p><p> donk.<span style="color: #191970; font-weight: bold;">Select3</span>(<span style="color: #008b8b; font-weight: bold;">false</span>, <span style="font-weight: bold;">null</span>);</p><p> </p><p> <span style="color: #004085;">Dimension</span> dimension = positionalDimension.Item1.<span style="color: #191970; font-weight: bold;">GetDimension2</span>(<span style="color: #00008b;">0</span>);</p><p> <span style="color: #004085;">MathVector</span> dimensionDirection = (<span style="color: #004085;">MathVector</span>)dimension.DimensionLineDirection;</p><p> <span style="color: #ff0000; font-weight: bold;">int</span> duder = positionalDimension.Item1.Type2;</p><p> <span style="color: #0000ff; font-weight: bold;">if</span>((positionalDimension.Item1.Type2 == (<span style="color: #ff0000; font-weight: bold;">int</span>)<span style="color: #004085; font-weight: bold;">swDimensionType_e</span>.<span style="font-style: italic;">swHorOrdinateDimension</span>) | (positionalDimension.Item1.Type2 == (<span style="color: #ff0000; font-weight: bold;">int</span>)<span style="color: #004085; font-weight: bold;">swDimensionType_e</span>.<span style="font-style: italic;">swOrdinateDimension</span>) | (positionalDimension.Item1.Type2 == (<span style="color: #ff0000; font-weight: bold;">int</span>)<span style="color: #004085; font-weight: bold;">swDimensionType_e</span>.<span style="font-style: italic;">swVertOrdinateDimension</span>)){</p><p> dimensionDirection = (<span style="color: #004085;">MathVector</span>)((<span style="color: #004085;">MathVector</span>)dimensionDirection.<span style="color: #191970; font-weight: bold;">MultiplyTransform</span>(positionalDimension.Item2.ModelToViewTransform.<span style="color: #191970; font-weight: bold;">Inverse</span>())).<span style="color: #191970; font-weight: bold;">Normalise</span>();</p><p> }</p><p> </p><p> <span style="color: #ff0000; font-weight: bold;">double</span> dot = <span style="color: #ff0000; font-weight: bold;">double</span>.<span style="font-style: italic;">PositiveInfinity</span>;</p><p> <span style="color: #0000ff; font-weight: bold;">if</span>(direction == <span style="color: #00008b;">0</span>){</p><p> dot = dimensionDirection.<span style="color: #191970; font-weight: bold;">Dot</span>(holeInstance.<span style="font-style: italic;">collinearDirectionX0</span>);</p><p> }<span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #0000ff; font-weight: bold;">if</span>(direction == <span style="color: #00008b;">1</span>){</p><p> dot = dimensionDirection.<span style="color: #191970; font-weight: bold;">Dot</span>(holeInstance.<span style="font-style: italic;">collinearDirectionX1</span>);</p><p> }</p><p> </p><p> <span style="color: #000080;">return</span> <span style="color: #004085;">DimensionalConstraintSolver</span>.<span style="color: #191970; font-weight: bold;">IsEpsilonEqual</span>(dot, <span style="color: #00008b;">0</span>);</p><p> }</p>Let's see:
The design has X Up
The sketch has Z Top
The only place where you have problems is when you send the 3D file to a third-party CAM system
I see epsilon hehe. Only in vector math does epsilon matter. Lol
Do you have this figured out ?
I think so, I wrote what I think is going on in my last post but I didn't want to mark it correct because it seems so weird.