×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Perimeter Measurement API Solidworks

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  

RE: Perimeter Measurement API Solidworks

(OP)
Scorch,

  Do you still have a copy of that marco you refernced?
on the past thread.

RE: Perimeter Measurement API Solidworks

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

RE: Perimeter Measurement API Solidworks

(OP)
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

 

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources