ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
KKKrishna Khatri-Chetri29/02/2016

New to macro building so trying to start small while I get my head around it all!

I would like to create an offset line within a sketch from a selected face and link the dimension to a variable.

setup:

Open all new parts using a standard part and assembly template to set up the common global variables I want to use
Global variables created by template - "rebate"
Sketch on the target surface open with one face selected

Run macro:

Macro uses the edges of the pre-selected face to act as the input edges for an inward offset
The offset is applied and then dimension changed to the global variables "rebate"
The selected face and edges are deselected
End

I have had a bit of a play around with codes I have found but can't work out how to link the created offset dimension to a global variables. Any one help me understand how to select the created dimension offset command and linking my variable.

Thanks
Krishna

Dim swApp As Object

Dim Part As Object

Dim ModDoc As ModelDoc2

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set ModDoc = swApp.ActiveDoc

Dim SelMgr As SelectionMgr

Dim EdgeCount As Integer

Dim Edges() As Edge

Dim SelFace  As Face2

Dim SelData As SelectData

Dim SelectedCount As Integer

If ModDoc Is Nothing Then

Else

     Set SelMgr = ModDoc.SelectionManager

     If SelMgr.GetSelectedObjectCount2(-1) = 1 Then

          Select Case SelMgr.GetSelectedObjectType3(1, -1)

                    Case swSelectType_e.swSelFACES

                         Set SelFace = SelMgr.GetSelectedObject6(1, -1)

                         If SelFace Is Nothing Then

                         Else

                              EdgeCount = SelFace.GetEdgeCount

                              Edges = SelFace.GetEdges

                              Set SelData = SelMgr.CreateSelectData

                              ModDoc.ClearSelection2 (True) ' This Clears the selected Face

                              SelectedCount = SelMgr.AddSelectionListObjects(Edges, SelData)

                              swApp.SendMsgToUser2 "There Were " & SelectedCount & " Edges Selected", _

                          swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk

                          Set Part = swApp.ActiveDoc

                          boolstatus = Part.SketchOffsetEntities2(-0.00001, False, False)

                          '' connect "rebate" to the offset above

                        Part.ClearSelection2 True

            

                         End If

          End Select

End If

End If

End Sub