Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perimeter Measurement API Solidworks

Status
Not open for further replies.

3dcadconsultant

Mechanical
Jun 3, 2009
5
thread559-120327 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
 
Replies continue below

Recommended for you

Scorch,

Do you still have a copy of that marco you refernced?
on the past thread.
 
If I correctly understand you would like to get the total length of all the edges in the model without preselecting faces.

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
 
Thank you, Thank you, Thank you Artem

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.

 
 http://files.engineering.com/getfile.aspx?folder=cb5da29d-c750-4e0f-a5c3-3c7461e69c55&file=basic_part.pdf
I also have a simple request how can I add this to the code?

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

 

>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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor