Perimeter Measurement API Solidworks
Perimeter Measurement API Solidworks
(OP)
thread559-120327: API Question Was closed.
I am looking to do the same thing.
I would like to find a way to get the perimeter from a model in it's formed state. I currently have a good start and need two things.
1. Get a hole number.
2. Get number of bends
3. Get it to count multiple edges.
In the last forum a link to a quote software is now dead does anyone know of something like this?
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face
Dim swEdge As SldWorks.Edge
Dim swCurve As SldWorks.Curve
Dim varCurveParams As Variant
Dim varEdgeArray As Variant
Dim Length As Double
Dim bRet As Boolean
Dim i As Long
Dim j As Long
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFace = swSelMgr.GetSelectedObject3(1)
varEdgeArray = swFace.GetEdges
For i = 0 To UBound(varEdgeArray)
Set swEdge = varEdgeArray(i)
Set swCurve = swEdge.GetCurve
Set swCurve = swEdge.GetCurve
varCurveParams = swEdge.GetCurveParams2
Length = Length + swCurve.GetLength(varCurveParams(6), varCurveParams(7))
Next i
MsgBox "Length = " + Str(Length / 0.0254) + " in"
End Sub
Please help
Steve
I am looking to do the same thing.
I would like to find a way to get the perimeter from a model in it's formed state. I currently have a good start and need two things.
1. Get a hole number.
2. Get number of bends
3. Get it to count multiple edges.
In the last forum a link to a quote software is now dead does anyone know of something like this?
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face
Dim swEdge As SldWorks.Edge
Dim swCurve As SldWorks.Curve
Dim varCurveParams As Variant
Dim varEdgeArray As Variant
Dim Length As Double
Dim bRet As Boolean
Dim i As Long
Dim j As Long
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFace = swSelMgr.GetSelectedObject3(1)
varEdgeArray = swFace.GetEdges
For i = 0 To UBound(varEdgeArray)
Set swEdge = varEdgeArray(i)
Set swCurve = swEdge.GetCurve
Set swCurve = swEdge.GetCurve
varCurveParams = swEdge.GetCurveParams2
Length = Length + swCurve.GetLength(varCurveParams(6), varCurveParams(7))
Next i
MsgBox "Length = " + Str(Length / 0.0254) + " in"
End Sub
Please help
Steve






RE: Perimeter Measurement API Solidworks
Do you still have a copy of that marco you refernced?
on the past thread.
RE: Perimeter Measurement API Solidworks
If so please take a look at the following macro:
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
Dim totalLength As Double
Sub main()
Set swApp = Application.SldWorks
Set swPart = swApp.ActiveDoc
Dim vBodies As Variant
Dim swBody As SldWorks.Body2
Dim vEdges As Variant
Dim swEdge As SldWorks.Edge
Dim swCurve As SldWorks.Curve
Dim vCurveParams As Variant
vBodies = swPart.GetBodies2(swBodyType_e.swAllBodies, False)
Dim i As Integer
Dim j As Integer
For i = 0 To UBound(vBodies)
Set swBody = vBodies(i)
vEdges = swBody.GetEdges
For j = 0 To UBound(vEdges)
Set swEdge = vEdges(j)
Set swCurve = swEdge.GetCurve
vCurveParams = swEdge.GetCurveParams2
totalLength = totalLength + swCurve.GetLength3(vCurveParams(6), vCurveParams(7))
Next
Next
MsgBox "Length = " + Str(totalLength / 0.0254) + " in"
End Sub
Artem Taturevich
CSWP
RE: Perimeter Measurement API Solidworks
This is a big help.
I am still working on
1. Get number of internal features
2. Get number of bends.
extra would be to get a ruff flat size without unfolding.
Thanks again I will have to figure this out.
RE: Perimeter Measurement API Solidworks
Dim vfacecount As Long
facecount = swBody.GetFaceCount
Function GetFaceCount() As Long
Member of SldWorks.Body2
Gets the face count for this body
this is driving me crazy
RE: Perimeter Measurement API Solidworks
>1. Get number of internal features
In order to retrieve the number of features in the document use FeatureManager::GetFeatureCount method.
I'm not sure what do you mean by 'internal features'
> 2. Get number of bends.
Are you talking about the Sheet Metal bends?
>I also have a simple request how can I add this to the code?
>Dim vfacecount As Long
>facecount = swBody.GetFaceCount
You have declared different variable names. Use
...
Dim facecount As Long
facecount = swBody.GetFaceCount
...
Put these two lines in your code where you would like to count faces
Artem Taturevich
CSWP