Checking type of face/surface in SW

Apr 01, 2006 8 Replies

Hi,



I am a novice user of SolidWorks and frequently encounter situations where i need to know the type a face / surface in the given model. Is there a quick way / hack / trick to know whether the given face is planar or spline. Similarly, detecting spherical / toroidal / conical faces. I am not much interested in knowing the surface defining properties [like normal vector for a planar face, or center of spherical face], but mainly in type of surface.



Thanks in advance for the reply.



-aditya



An easy way to see if it is planar or not is to select it and if the sketch icon lights up, it's planar.

As for the other types, you can use either c> Hi,

In general SW does not classify faces in a way that can be easily checked by a user. So for example if you have imported an IGES file there is no easy way to determine what type of face is being selected. However, if the face was created in the feature tree there are ways to determine face type by implication. For example the analytical faces/surfaces you mention would likely be made by revolving an arc, circle or line about an axis. Therefore the feature would be a revolve and the sketch would contain an arc, circle or line. This can also be determined through the API. However, it is also possible to create these features without a revolve. For example a sweep can also create analytical faces.

See the API help for IsSphere, IsRevolved, IsParametric, IsPlane, IsSwept, IsTorus, IsCone, IsCylinder etc. There is an example macro called "Get Parameters of a Toroidal Surface Example (VB)" that you could use to start with.

Option Explicit

'---------------------------------------------- ' Taken from API help and modified to identify face type '

' Precondition:

' 1) Part, assembly, or drawing document is open.

' 2) Face of toroidal surface is selected.

'

' Postcondition: None

'

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFace As SldWorks.face2

Dim swSurf As SldWorks.surface

Dim vTorus As Variant

Dim i As Long

Dim bRet As Boolean

Dim lRet As Long

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

If (swSelMgr.GetSelectedObjectType(1) = swSelFACES) Or (swSelMgr.GetSelectedObjectType(1) = swSelREFSURFACES) Then

Set swFace = swSelMgr.GetSelectedObject5(1)

Set swSurf = swFace.GetSurface

If swSurf.IsTorus Then lRet = swApp.SendMsgToUser2("Torus", swMbInformation, swMbOk)

ElseIf swSurf.IsCylinder Then lRet = swApp.SendMsgToUser2("Cylinder", swMbInformation, swMbOk)

ElseIf swSurf.IsCone Then lRet = swApp.SendMsgToUser2("Cone", swMbInformation, swMbOk)

ElseIf swSurf.IsPlane Then lRet = swApp.SendMsgToUser2("Plane", swMbInformation, swMbOk)

ElseIf swSurf.IsRevolved Then lRet = swApp.SendMsgToUser2("Revolve", swMbInformation, swMbOk)

ElseIf swSurf.IsParametric Then lRet = swApp.SendMsgToUser2("Parametric", swMbInformation, swMbOk)

ElseIf swSurf.IsSphere Then lRet = swApp.SendMsgToUser2("Sphere", swMbInformation, swMbOk)

Else lRet = swApp.SendMsgToUser2("Unknown", swMbInformation, swMbOk)

End If Else

lRet = swApp.SendMsgToUser2("Select Face", swMbInformation, swMbOk)

End If

End Sub

Thanks for the replies. I will definitely try using your suggestions. I understand going the API way is a sound method, but in case if someone has some more tricks to determine the facetypes, please let me know.

regards, aditya

I added a check in case a face is not selected and a couple more checks.

Option Explicit

'----------------------------------------------

'

' Precondition:

' 1) Part, assembly, or drawing document is open.

' 2) Face of toroidal surface is selected.

'

' Postcondition: None

'

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFace As SldWorks.face2

Dim swSurf As SldWorks.surface

Dim vTorus As Variant

Dim i As Long

Dim bRet As Boolean

Dim lRet As Long

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

If (swSelMgr.GetSelectedObjectType(1) = swSelFACES) Or (swSelMgr.GetSelectedObjectType(1) = swSelREFSURFACES) Then

Set swFace = swSelMgr.GetSelectedObject5(1)

Set swSurf = swFace.GetSurface

If swSurf.IsTorus Then lRet = swApp.SendMsgToUser2("Torus", swMbInformation, swMbOk)

ElseIf swSurf.IsCylinder Then lRet = swApp.SendMsgToUser2("Cylinder", swMbInformation, swMbOk)

ElseIf swSurf.IsCone Then lRet = swApp.SendMsgToUser2("Cone", swMbInformation, swMbOk)

ElseIf swSurf.IsPlane Then lRet = swApp.SendMsgToUser2("Plane", swMbInformation, swMbOk)

ElseIf swSurf.IsRevolved Then lRet = swApp.SendMsgToUser2("Revolve", swMbInformation, swMbOk)

ElseIf swSurf.IsParametric Then lRet = swApp.SendMsgToUser2("Parametric", swMbInformation, swMbOk)

ElseIf swSurf.IsSphere Then lRet = swApp.SendMsgToUser2("Sphere", swMbInformation, swMbOk)

ElseIf swSurf.IsSwept Then lRet = swApp.SendMsgToUser2("Sweep", swMbInformation, swMbOk)

ElseIf swSurf.IsBlending Then lRet = swApp.SendMsgToUser2("Blending Face", swMbInformation, swMbOk)

Else lRet = swApp.SendMsgToUser2("Unknown", swMbInformation, swMbOk)

End If Else

lRet = swApp.SendMsgToUser2("Select Face", swMbInformation, swMbOk)

End If

End Sub

Just curious, but why do you need to know this?

I was playing with the macro a bit. One thing I noticed is that the face type or should I say underlying surface type does not depend on the feature type as much as what the surface really is. SW seems to try to simplify down to analytical surfaces as much as possible. So if you simply put a fillet on the edges of a cube you will get cylindrical and spherical surfaces for the fillet. If draft is added prior to filleting you still get cylindrical and spherical. If you put the fillets in the sketch you get conical and toroidal and I haven't yet checked what happens when the sketch is swept in a way to produce draft.

Did it another way that reveals another surface type. BSurf is added and swept is not available.

Option Explicit

'---------------------------------------------- ' SurfID ' Date By Comment ' 4/2/06 pbk Initial Coding ' ' Precondition: ' 1) Part, assembly, or drawing document is open. ' 2) Face is selected. ' ' Postcondition: None ' Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Sub main()

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFace As SldWorks.face2

Dim swSurf As SldWorks.surface

Dim vTorus As Variant

Dim i As Long

Dim bRet As Boolean

Dim lRet As Long

Dim nID As Long

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

If (swSelMgr.GetSelectedObjectType(1) = swSelFACES) Or (swSelMgr.GetSelectedObjectType(1) = swSelREFSURFACES) Then

Set swFace = swSelMgr.GetSelectedObject5(1)

Set swSurf = swFace.GetSurface

nID = swSurf.Identity

Select Case nID

Case 4001 Announce ("Plane")

Case 4002 Announce ("Cylinder")

Case 4003 Announce ("Cone")

Case 4004 Announce ("Sphere")

Case 4005 Announce ("Torus")

Case 4006 Announce ("BSurf")

Case 4007 Announce ("Blend")

Case 4008 Announce ("Offset")

Case 4009 Announce ("Extrusion")

Case 40010 Announce ("SRev")

Case Else Announce ("Unknown")

End Select

Else

Announce ("Select Face")

End If

End Sub

Sub Announce(Text As String)

Dim lRet As Long

lRet = swApp.SendMsgToUser2(Text, swMbInformation, swMbOk) End Sub

THANX a bundle for the macro. I tried using the Macro [which was a new thing for me] and things are looking perfect ! I'll try writing some macros myself for other things that I am looking for. thanks again, aditya

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required