AnsweredAssumed Answered

Macro help for connecting specified points with line

Question asked by Matt Schmotzer on Dec 18, 2017
Latest reply on Dec 18, 2017 by Matt Schmotzer

Hello Solidworks Community,

 

Problem Statment:

I am looking for help adjusting the macro below to draw a line from points that I have created in a specifc order. Can you help me modify?

 

Overview:

I have over 150 parts that need to have lines sketched between points. The points are created as reference points in the same order, so the point numbers will be the same, just in a different XYZ location. I use the top centerline to create 8 evenly distributed points on the center line and then simply project the center line points onto each respective surface (seen in Figure 1)

Track 1.jpg

From here I go into 3d sketch and start connecting the points. First I connect the profile (seen in Figure 2)

Track 2.jpg

Once the profile is complete I then connect the cross bracing members. (Seen in Figure 3)

Track 3.jpg

Figure 3 is the desired result I am looking for from the Macro. Once I have the lines I can simply create weldments for the final product as seen in Figure 4. Please note that I have not trimmed any of the members and this is just to give you an idea of what I am trying to create.

Track 4.jpg

 

Since only the XYZ position of the point changes but not the point number I would like a macro to connect each point with a line but I want to be able to tell the macro which points to connect. For example if we look at Figure 1 & 2, I would like the following points connected...

Point 17 to Point 16

Point 33 to Point 41

Point 41 to Point 25

 

Point 18 to Point 15

Point 34 to Point 42

Point 42 to Point 26

 

...etc....

 

That is what I am looking to do. I was able to find this previously written macro on the forum for it only connects point 1 to 2 then 3 to 4 then 4 to 5. In addition its only connecting sketch points when I am trying to connect reference points. Will I need to convert entities from reference points to points in a sketch? See the macro below...

 

Prior Art:

' ******************************************************************************

' Macro that connects points within a 3dsketch by lines in a new 3Dsketch -By Bert De Spiegelaere

' ******************************************************************************

Dim swApp As Object

Dim swModel As Object

Dim skSegment As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Dim sketchPointArray As Variant

Dim pointCount As Integer

 

 

Sub main()

 

Set swApp = Application.SldWorks

 

Set swModel = swApp.ActiveDoc

 

'Get 3dsketch with points via SelectByID2

boolstatus = swModel.Extension.SelectByID2("3DSketch with points", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

swModel.EditSketch

Set the3DSketch = swModel.GetActiveSketch2

swModel.SketchManager.InsertSketch True

 

'Get SketchPoints from within '3DSketch with points' .

sketchPointArray = the3DSketch.GetSketchPoints2

 

pointCount = UBound(sketchPointArray) + 1

 

'create new 3DSketch to connect the points

swModel.SketchManager.Insert3DSketch True

 

' For each SketchPoint in the "3DSketch with points"

 

For i = 0 To (pointCount - 1)

 

' Here I pair up the sketchpoints

If (i Mod 2) = 0 Then

 

' For each 2 Get the coordinates

'Coords of point 1

x1Value = sketchPointArray(i).X

 

y1Value = sketchPointArray(i).Y

 

z1Value = sketchPointArray(i).Z

'Coords of point 2

x2Value = sketchPointArray(i + 1).X

 

y2Value = sketchPointArray(i + 1).Y

 

z2Value = sketchPointArray(i + 1).Z

 

'And create a line between them

 

Set skSegment = swModel.SketchManager.CreateLine(x1Value, y1Value, z1Value, x2Value, y2Value, z2Value)

'between coords we got from point 1 and the coords we got from point 2

 

End If

 

Next i

 

'Close lin 3DSketch

swModel.SketchManager.InsertSketch True

 

End Sub

 

' ******************************************************************************

' ******************************************************************************

 

Summary:

Maybe there is a way to alter the above code to directly tell the macro which points to connect? I feel like this is a simple problem but I am a terrible programmer. I tried just hard inputting the point into the "i" or "i+1" field however I am using reference points and not sketch points. Once I convert the reference points into a sketch I have no Idea what order the points are in.

 

Thank you so much for the help.

Outcomes