dimension

How do you accurately place the dimensions in a sketch

using the api.

SolidworksApi macros
Answers 1
SM
SM 2016-02-01 Best Answer

Easier way to use swView.Outline to get the outline coordinates, then offset the dimension from the outline.

the below code describe the above

        

        'Get outline coordinate of drawing view 18 in an array called Varr1

        boolstatus = Part.Extension.SelectByID2("Drawing View18", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

        SwView = Part.SelectionManager.GetSelectedObject6(1, -1)

        Varr1 = SwView.GetOutline

        'Position the dimension RD3@Drawing View18 x=5mm offset from right outline y=middle of view

        boolstatus = Part.Extension.SelectByID2("RD3@Drawing View18", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

        myDisplayDim = Part.SelectionManager.GetSelectedObject6(1, -1)

        swAnn = myDisplayDim.GetAnnotation()

        boolstatus = swAnn.SetPosition(Varr1(2)+5/1000, (Varr1(1) + Varr(3))  / 2, 0)

Another more accurate way to transform coordinate from model to drawing view and then position the dimension accordingly.