I am measuring the cross sectional area as it changes along a part in the X-direction. How do I select faces created by cut feature? Or maybe, select all the faces normal to the front plane, with some x-coordinate?
Currently, I do the following, but it is unreliable (faces lose material data when they are cut) and computationally expensive (selects every face and checks material properties for each cut):
Select all faces
Color all the faces red
For loop (stepping in increments)
Cut the part
Select all the non-red faces 'The faces created by a cut feature do not have a color
Measure the area of all the selected faces
Next
Thanks,
Brandon Massoni
SolidworksApi macros
Perhaps this could give you an alternative idea.
http://help.solidworks.com/2014/English/api/sldworksapi/Get_Faces_Associated_with_Feature_Example_VBNET.htm
I think that is how I would have started to do the things you describe.
'-----------------------------------------------
'Author:
'Brandon Massoni
'Date Published:
'11/19/2014
'
' Preconditions:
' 1. Open a part document.
' 2. Select a feature in the FeatureManager design
' tree.
' 3. Run the macro.
'
' Postconditions:
' 1. Prints the area of the faces created by the feature.
' (e.g. cross sectional area of faces created by a cut
'-----------------------------------------------
Sub Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swFeat As SldWorks.Feature
Dim swFaceFeat As SldWorks.Feature
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swEnt As SldWorks.Entity
Dim faceArr As Variant
Dim oneFace As Variant
Dim status As Boolean
Dim Area As Double
Dim TotalArea As Double
'Initial Setup
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
faceArr = swFeat.GetFaces: If IsEmpty(faceArr) Then Exit Sub
For Each oneFace In faceArr
Set swFace = oneFace
Set swEnt = swFace
Set swFaceFeat = swFace.GetFeature
' Check to see if face is owned by multiple features
If swFaceFeat Is swFeat Then
'status = swEnt.Select4(True, swSelData): Debug.Assert (status)
'Measures area of current face
Area = swFace.GetArea
'Adds up areas from each selected
TotalArea = TotalArea + Area
End If
Next
TotalArea = Round(TotalArea, 5)
MsgBox "Cross Sectional Area of Feature " & TotalArea & " m^2"
End Sub
Thanks Daniel,
That is exactly what I was looking for. I rewrote and attached the SolidWorks demo code for anyone that wants it, since the demo code didn't work for me.