在Solidworks 的草图绘制环境下如何获得鼠标点击后的点坐标 问题描述: 建立好零件图后,用VBA写一个在 Solidworks草图环境下,点鼠标 左键后获得此点坐标的具体数字!
发现很难办到,我写了部分代码如下: sub main() Dim swApp, Part, SelMgr As Object Dim retalAs Variant Dim xyzvalue As String Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager boolstatus = Part.Extension.SelectByID("前视基准面", "PLANE", 0, 0, 0, False, 0, Nothing) Part.ShowNamedView2 "*上下二等角轴测", 8 part.InsertSketch2 True If (Part.GetActiveSketch Is Nothing) Then swApp.SendMsgToUser "请建立一个活动文档" Exit Sub End If
If (SelMgr.GetSelectedObjectCount2 <> 0) Then
retal = SelMgr.GetSelectionPointInSketchSpace2(0, 0)
xyzvalue = "x=" & retal(0) * 1000 & "mm" & Chr(10) & "y=" & retal(1) * 1000 & "mm" & Chr(10) & "z=" & retal(2) * 1000 & "mm"
swApp.SendMsgToUser xyzvalue
End If end sub
大致思路是这样的,但是却做不到; 本来是设计运行程序后,等到点鼠标左键然后就 把此点的坐标展示出来,但是感觉好象没有办法做到只有当点击左键时候,才显示 此点的坐标; 上面我写的那个东西,还没有等我点就直接显示为 0,0,0了! 所以我想问大家如果能做到呢?我看大前面一贴也是关于getpiont的,但是发现太不一样了!
下面是描述: SelectionMgr::GetSelectionPointInSketchSpace2
Description
This method gets the selection point projected on to the active sketch and returned in sketch space. The selection point is projected on to the currently active sketch, resulting in a Z value, which is always 0.00.
Syntax (OLE Automation)
Retval = SelectionMgr.GetSelectionPointInSketchSpace2 ( Index, Mark)
Input: (long) Index Index position within the current list of selected items where AtIndex ranges from 1 to SelectionMgr::GetSelectedObjectCount2 (see Remarks) Input: (long) Mark -1 = All selections regardless of marks
0 = only the selections without marks
Any other value = Value that was used to mark and select an object Output: (VARIANT) Retval VARIANT of type SafeArray of 3 doubles (x,y,z)
其实还有几个API,但是发现,那些都是获得空间模型的点的,找了很久才发现这个API才是获得草图的点的;
希望各位老师指导;
|