Hello,
i'm trying to determine the dimension of part ( length and diameter) in SolidWorks using VB.net. but, i don't find the right algorithm.
can you help me please? i'm waiting and thank you.
Hello,
i'm trying to determine the dimension of part ( length and diameter) in SolidWorks using VB.net. but, i don't find the right algorithm.
can you help me please? i'm waiting and thank you.
It depends on the part.
You could loop through the dimensions to look for what you want.
2018 SOLIDWORKS API Help - Iterate Through Dimensions in Model Example (VBA)
or if the dimensions are the maximum ones, you could use bounding box
2018 SOLIDWORKS API Help - Get Part Bounding Box Example (VBA)
hello and thank you for your answers,
i tried this algorithm :
Dim SelectionManager As Object
Dim SketchSegment As Object
Dim Length As Double
SelectionManager = Part.SelectionManager()
Part.SelectByID("part-1@assembly@Révolution1@Esquisse1", "EXTSKETCHSEGMENT", 0, 0, 0)
SketchSegment = SelectionManager.GetSelectedObject2(1)
Length = SketchSegment.GetLength() " result = not defined bloc in this line "
MsgBox(Length)
but i don't get a reslut
Not sure what are you trying to accomplish with this.
If you're trying to get the length of all the lines in the sketch "Esquisse1", use this:
'Open a part and select a sketch
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim vSketchSegs As Variant
Dim vSketchSeg As Variant
Dim swSketchSeg As SldWorks.SketchSegment
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'boolstatus = Part.Extension.SelectByID2("Esquisse1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketch = swFeat.GetSpecificFeature2
vSketchSegs = swSketch.GetSketchSegments
For Each vSketchSeg In vSketchSegs
Set swSketchSeg = vSketchSeg
If swSketchSeg.GetType <> swSketchSegments_e.swSketchTEXT Then
MsgBox swSketchSeg.GetLength
End If
Next
End Sub
if you're trying to get the length of 1 selected line in the sketch "Esquisse1", use:
'Open a sketch and select a line
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelectionManager As SldWorks.SelectionMgr
Dim SketchSegment As SldWorks.SketchSegment
Dim length As Double
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
'boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Set SelectionManager = Part.SelectionManager
Set SketchSegment = SelectionManager.GetSelectedObject6(1, -1)
Length = SketchSegment.GetLength
MsgBox (Length)
End Sub
Not sure what are you trying to accomplish with this.
If you're trying to get the length of all the lines in the sketch "Esquisse1", use this:
'Open a part and select a sketch
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim vSketchSegs As Variant
Dim vSketchSeg As Variant
Dim swSketchSeg As SldWorks.SketchSegment
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
'boolstatus = Part.Extension.SelectByID2("Esquisse1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketch = swFeat.GetSpecificFeature2
vSketchSegs = swSketch.GetSketchSegments
For Each vSketchSeg In vSketchSegs
Set swSketchSeg = vSketchSeg
If swSketchSeg.GetType <> swSketchSegments_e.swSketchTEXT Then
MsgBox swSketchSeg.GetLength
End If
Next
End Sub
if you're trying to get the length of 1 selected line in the sketch "Esquisse1", use:
'Open a sketch and select a line
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelectionManager As SldWorks.SelectionMgr
Dim SketchSegment As SldWorks.SketchSegment
Dim length As Double
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
'boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Set SelectionManager = Part.SelectionManager
Set SketchSegment = SelectionManager.GetSelectedObject6(1, -1)
Length = SketchSegment.GetLength
MsgBox (Length)
End Sub