Over a period of time, I have created a complex VBA script that creates quite complex geometry quickly (it saves something like 45 minutes per design), but I can't get one part to work how I want it to.
Without posting the complete vba script here, all I need it to do is model a centerline along the Z axis in a 3D sketch. I can get it to work in the X and Y axis (in both positive and negative directions), but not in Z.
Even recording a macro where I'm able to create a centerline in the Z axis, fails to re-create it when run.
The recorded macro code is as follows: -
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Part.SketchManager.Insert3DSketch True
Dim skSegment As Object
Set skSegment = Part.SketchManager.CreateCenterLine(0#, 0#, 0#, 0.113622, 0#, 0#)
Part.SetPickMode
Part.ClearSelection2 True
Dim mySketch As Object
Set mySketch = Part.GetActiveSketch2()
boolstatus = mySketch.SetWorkingPlaneOrientation(0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0)
Set skSegment = Part.SketchManager.CreateCenterLine(0#, 0#, 0.137771, 0#, 0#, 0.237771)
Part.SetPickMode
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
End Sub
This is not a 'deal breaker' as i have an untidy workaround, but i would like to understand why it doesn't work
Currently running Solidworks Premium 2018 SP5.0
Thanks in advance for your help.
Cheers Steve
You're right. CreateCenterLine doesn't seem to consider the Z coordinates.
Instead you can use CreateLine, then set the line to construction line.