Hello
I'm looking for a solution to create welded construction groups in a VBA API from a 3D sketch already generated in VBA.
My previously generated 3D sketch is called NdM3D and contains a variable number of segments (between 5 and 50) all named "line 1" to "line i". I managed to limit the number of lines of my code a little by fiddling, but I still have 7 lines of code per segment, between declarations and functions. So I'm trying to turn this function into a loop that spans all the segments in my sketch. I got the Ubounds variable from the number of segments, it works. But no matter how much I try several syntaxes, I can't create a loop that creates the array of groups for the soldered construction. The orientation being quite random, each segment must be in a distinct group. I am finally looking to have the group.array table that contains "i" groups each composed of a single segment.
My current code:
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim boolstatus As Boolean
Dim FeatMgr As FeatureManager
Sun SelMgr As SelectionMgr
Dim mySketch As SldWorks.Sketch
Dim swWeldFeat As SldWorks.Feature
Dim swWeldFeatData As SldWorks.StructuralMemberFeatureData
Dim skSegCount As Long
Dim vSkSegments As Variant
Dim skSegment As SldWorks.SketchSegment
Option Explicit
Public Sub Main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set FeatMgr = Part.FeatureManager
Set SelMgr = Part.SelectionManager
Dim myFeature2 As Object
Set myFeature2 = Part.FeatureByName("3D NdM")
Set mySketch = myFeature2.GetSpecificFeature2()
vSkSegments = mySketch.GetSketchSegments()
skSegCount = UBound(vSkSegments)
Debug.Print" number of segments in the sketch = " & skSegCount
Dim myFeature As Object
Set myFeature = Part.FeatureManager.InsertWeldmentFeature()
Dim GroupArray() as Object
ReDim GroupArray(0 to 100) as object
' For i = 1 TB UBound(vSkSegments)
' From here, this is the part that works for 2 successive segments, which I want to extend to the i segments in the loop
Dim Group1, Group2 As StructuralMemberGroup
Set Group1 = FeatMgr.CreateStructuralMemberGroup
Set Group2 = FeatMgr.CreateStructuralMemberGroup
Dim segments1(0) As Object
Dim segments2(0) As Object
boolstatus = Part.Extension.SelectByID2("Line1@NdM 3D", "EXTSKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Set segments1(0) = SelMgr.GetSelectedObject6(1, 0)
Group1.Segments = (segments1)
Set GroupArray(0) = Group1
boolstatus = Part.Extension.SelectByID2("Line2@NdM 3D", "EXTSKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
Set segments2(0) = SelMgr.GetSelectedObject6(1, 0)
Group2.Segments = (segments2)
Set GroupArray(1) = Group2
' Next I
Set myFeature = Part.FeatureManager.InsertStructuralWeldment4("D:\SW Library\Profile Library\Test\profile1\mon_profile.sldlfp", 1, False, (GroupArray))
Part.ClearSelection2 True
End Sub
Be careful, the syntax will surely sting the eyes of insiders, it is a compilation of several copy-pastes of examples that seemed to me to correspond to my research.
Any idea?
Thank you.