Is there an alternative to View.GetOutline() which gives a better outline?

孤者浪人 提交于 2019-12-11 04:29:42

问题


Outline returned by View.GetOutline() method does not quite correspond to the visible drawing - it returns a bit more than the selection outline shown by SolidWorks GUI.

The screenshot below shows the selection outline (light blue dotted rectangle) and diagonal of the outline returned by View.GetOutline() (red line):

Is there a way to get bounding box that corresponds to the actually visible drawing?

Note: Original title of this question was "Is there an alternative to View.GetOutline() which does NOT include Temporary Axes?", however I discovered that View.GetOutline() actually does not include Temporary Axes. The problem was in the View.Position property which defines center bounding box that includes Temporary Axes.
Artem's answer was quite useful so I decided to change the question to correspond to the answer and post a new question for the actual problem.


回答1:


You can get the bounding box from underlying model via IPartDoc::GetBox/IAssemblyDoc::GetBox API and transform this to a view space via IView::ModelToViewTransform as shown in this example.

You will only need the following portion of code form the DrawBBoxDiagonal function if you do not want to draw the diagonal. The values of vStartPt and vEndPt are the end points of bounding box.

Dim vBox As Variant
Dim swViewTransform As SldWorks.MathTransform

Dim swMathPt As SldWorks.MathPoint
Dim vStartPt As Variant
Dim vEndPt As Variant

vBox = GetViewRefModelBBox(view)
Set swViewTransform = GetViewToSheetTransform(draw, view)

Dim swMathUtils As SldWorks.MathUtility
Set swMathUtils = swApp.GetMathUtility

Dim dPt(2) As Double
dPt(0) = vBox(0): dPt(1) = vBox(1): dPt(2) = vBox(2)

Set swMathPt = swMathUtils.CreatePoint(dPt)
Set swMathPt = swMathPt.MultiplyTransform(swViewTransform)
vStartPt = swMathPt.ArrayData

dPt(0) = vBox(3): dPt(1) = vBox(4): dPt(2) = vBox(5)

Set swMathPt = swMathUtils.CreatePoint(dPt)
Set swMathPt = swMathPt.MultiplyTransform(swViewTransform)
vEndPt = swMathPt.ArrayData

I would also recommend to get precise bounding box via IBody2::GetExtremePoint as shown here



来源:https://stackoverflow.com/questions/58606697/is-there-an-alternative-to-view-getoutline-which-gives-a-better-outline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!