AnsweredAssumed Answered

How to use a scroll bar to control angle in angle mate?

Question asked by Chiao Yang Chang on Mar 31, 2018
Latest reply on May 23, 2018 by Chiao Yang Chang

I want to use scroll bar to control angle between Link1 & Link2.

But there's an error in .EditMate4 funtion.

I'm not sure what's wrong with the code.

 

Link_problem.PNG

=================================================================

Option Explicit
Const pi = 3.1416159

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAssembly As SldWorks.AssemblyDoc
Dim mate As SldWorks.Mate2

Dim boolstatus As Boolean
Dim longstatus As Long

 

Private Sub hsb_Change()   ' hsb means scroll bar

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swAssembly = swModel

 

' Mate
swModel.ClearSelection2 True
boolstatus = swModelDocExt.SelectByID2("Angle1", "MATE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-1 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-2 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 0)

Set mate = swAssembly.EditMate4(swMateType_e.swMateANGLE, swMateAlign_e.swMateAlignALIGNED, False, 0, 0.001, 0.002, 0, 0.001, hsb.Value, 5, 0, False, False, 0, False, longstatus)

swModel.ClearSelection2 True
swModel.EditRebuild3

 

' Redraw
swModel.GraphicsRedraw2

End Sub

 

Private Sub UserForm_Activate()
hsb.Max = 5
hsb.Min = 0
hsb.SmallChange = 1

End Sub

Outcomes