Jump to content

Get surface area and export to excel or csv


jayjay

Recommended Posts

Hi, Im trying to do an analysis on a boat hull which requires a series of cross sectional areas to be plotted on a bell curve.

 

Im trying to write a macro so I can adjust the lines to create a new curve.

 

I found this macro https://forum.solidworks.com/message/95775 to select the faces with the an area less than a certain value and it ran well on my model. I just need to tweak it to export the value to excel or csv for each face.

 

This is my attempt which fails completely as I dont really know what Im doing.

 

Any help would be appreciated.

 

 

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim vBods As Variant
Dim myBod As SldWorks.Body2
Dim myFace As SldWorks.Face2
Dim i As Long
Dim myFacearea As Variant
Dim myEnt As SldWorks.Entity
Dim MinArea As Double
Dim myCount As Long
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swPart = swDoc

MinArea = CDbl(InputBox("Enter min area in square millimeters", "Min Area", 1))

swDoc.ClearSelection2 True
myCount = 0

vBods = swPart.GetBodies2(swAllBodies, False)
For i = 0 To UBound(vBods)
Set myBod = vBods(i)
Set myFace = myBod.GetFirstFace
While Not myFace Is Nothing
If (myFace.GetArea * 1000000) < MinArea Then
myFace.Select True

myFacearea = (myFace.GetArea * 1000000)

myCount = myCount + 1
End If
Set myFace = myFace.GetNextFace
Wend
Next i


MsgBox "Selected " & myCount & " faces with area less than " & MinArea & "mm^2."
End Sub

Function ExportCSVFile( _
  ByVal myFacearea As Object, _
  ByVal area As String _
) As Boolean

End Function

Edited by SLW210
Link to comment
Share on other sites

Sorry my bad. I posted a link to give credit for the original code - I thought I did do this, but I didn't use the link tool - The # tool isn't available on the edit post page so I can't put the code into a scroll box.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...