I tried these:
1. Getting ICurve::LineParams - didn't work
2. Selecting the two adjacent edges and checking for perpendicularity using IMeasure::IsPerpendicular - didn't work because it returned false, even though the measure tool when used in the GUI returns true (odd...)
3. Converted the edge to a sketch segment in a 3D sketch and then tested if that sketch segment was a line (versus a spline) - this did work. So here's the code for that.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swEdge As SldWorks.Edge
Dim swCurve As SldWorks.Curve
Dim swSketch As SldWorks.Sketch
Dim swSketchSegment As SldWorks.SketchSegment
Dim swFeat As SldWorks.Feature
Dim vSketchSegs As Variant
Dim i As Integer
Dim strName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swEdge = swSelMgr.GetSelectedObject6(1, -1)
Set swCurve = swEdge.GetCurve
If swCurve.isline = False Then
Set swSketch = swModel.SketchManager.ActiveSketch
Set swFeat = swSketch
strName = swFeat.Name
vSketchSegs = swSketch.GetSketchSegments
If IsEmpty(vSketchSegs) = False Then
Set swSketchSegment = vSketchSegs(0)
If swSketchSegment.GetType = swSketchLINE Then
swModel.Extension.SelectByID2 strName, "SKETCH", 0, 0, 0, False, 0, Nothing, 0
swApp.SendMsgToUser "Edge is linear."
Thanks for your reply Keith. I should have mentioned that I'm using a macro feature to build the bounding box so sketch creation is out from what I understand. Correct me if I'm wrong. The idea of using a macro feature being that the bbox would automatically update on model updates without the CAD operator having to run the macro again.
That's pretty cool! How did you discover this?
Because line is a minimal segment between two points I would do the following to identify whether this b-curve or line curve is line:
1) Calculate the distance between end points (vertices of the edge) - this is the length of the line.
2) Calculate the actual length of the curve: Curve::GetLength3.
3) Compare #1 and #2. If the comparison satisfies the tolerance the curve is line.
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
Thanks Artem. Simple and good enough. I like it!