标题: SolidWorks二次开发 获取模型最大外形 [打印本页] 作者: ESD_ProDevelop 时间: 2014-8-27 21:29 标题: SolidWorks二次开发 获取模型最大外形 IModelDoc2 * pMdl;
iSwApp->get_IActiveDoc2(&pMdl);
if (pMdl == NULL)
return S_FALSE;
//获取Part
CComPtr<IPartDoc> pPart;
pMdl->QueryInterface(IID_IPartDoc, (LPVOID*)&pPart);
if (pPart == NULL)
return S_FALSE;
//获取PartBox
VARIANT dPoint;
pPart->GetPartBox(FALSE, &dPoint);
...
详见: https://user.qzone.qq.com/910361522/blog/1404632014作者: mlghmj 时间: 2014-10-3 06:57
不知外形测量的准确性如何作者: judyyai 时间: 2014-10-23 23:05
看字面的意思 是只模型最大尺寸嗎作者: mlghmj 时间: 2015-6-5 20:57
Dim swApp As Object
Dim part As Object
Dim body1 As SldWorks.Body2
Dim swFace As SldWorks.Face2
Dim selmgr As Object
Dim x, y, z As Variant
Dim seltype As Long
Dim vTessTriangles As Variant
Const MaxDouble As Double = 1.79769313486231E+308
Const MinDouble As Double = -1.79769313486231E+308
Function GetMax(Val1, Val2, Val3, Val4 As Double) As Double
GetMax = Val1
If Val2 > GetMax Then
GetMax = Val2
End If
If Val3 > GetMax Then
GetMax = Val3
End If
If Val4 > GetMax Then
GetMax = Val4
End If
End Function
Function GetMin(Val1, Val2, Val3, Val4 As Double) As Double
GetMin = Val1
If Val2 < GetMin Then
GetMin = Val2
End If
If Val3 < GetMin Then
GetMin = Val3
End If
If Val4 < GetMin Then
GetMin = Val4
End If
End Function
Sub main()
Dim X_max As Double
Dim X_min As Double
Dim Y_max As Double
Dim Y_min As Double
Dim Z_max As Double
Dim Z_min As Double
Dim i As Long
Set swApp = Application.SldWorks
Set part = swApp.ActiveDoc()
Set selmgr = part.SelectionManager
seltype = selmgr.GetSelectedObjectType2(1)
If seltype = swSelSOLIDBODIES Then
Set body1 = selmgr.GetSelectedObject3(1)
Set swFace = body1.GetFirstFace
While Not swFace Is Nothing
vTessTriangles = swFace.GetTessTriangles(True)
For i = 0 To UBound(vTessTriangles) / (1 * 9) - 1
X_max = GetMax((vTessTriangles(9 * i + 0)), (vTessTriangles(9 * i + 3)), (vTessTriangles(9 * i + 6)), X_max)
X_min = GetMin((vTessTriangles(9 * i + 0)), (vTessTriangles(9 * i + 3)), (vTessTriangles(9 * i + 6)), X_min)
Y_max = GetMax((vTessTriangles(9 * i + 1)), (vTessTriangles(9 * i + 4)), (vTessTriangles(9 * i + 7)), Y_max)
Y_min = GetMin((vTessTriangles(9 * i + 1)), (vTessTriangles(9 * i + 4)), (vTessTriangles(9 * i + 7)), Y_min)
Z_max = GetMax((vTessTriangles(9 * i + 2)), (vTessTriangles(9 * i + 5)), (vTessTriangles(9 * i + 8)), Z_max)
Z_min = GetMin((vTessTriangles(9 * i + 2)), (vTessTriangles(9 * i + 5)), (vTessTriangles(9 * i + 8)), Z_min)
Next i
Set swFace = swFace.GetNextFace
Wend
x = Round((X_max - X_min) * 1000, 2)
y = Round((Y_max - Y_min) * 1000, 2)
z = Round((Z_max - Z_min) * 1000, 2)
MsgBox ("坯料尺寸:" & x & " X " & y & " X " & z)
Else
MsgBox ("请选择实体")
End If
End Sub