Macro request

Library for macros
BarryH
Posts: 4
Joined: Tue Nov 08, 2022 8:38 am
Answers: 1
x 1

Macro request

Unread post by BarryH »

Can anybody help with a small macro? I am currently working on a project which involves laser cut plates with holes in, some are hole wizard holes such as dowel holes and threaded holes, others are cut extrudes. We laser cut these holes smaller then drill them out to full size manually. I use the move face command to temporarily make the holes smaller by 0.5mm. ( I do this so that I can get the dxf file for cutting, then I delete or supress it). It would be great If I had a macro which did the following- I pre select the features from the feature tree and hit the macro button, which moves the faces of all the holes by 0.5mm, then closes the move face command.
I have tried recording a macro but cannot get it to work properly.
Thanks
by BarryH » Sun Sep 15, 2024 3:22 am
Thank you Deepak, that works perfectly.
Go to full post
User avatar
gupta9665
Posts: 388
Joined: Thu Mar 11, 2021 10:20 am
Answers: 20
Location: India
x 409
x 428

Re: Macro request

Unread post by gupta9665 »

Select the desired features, and run the following codes. Please try on sample files first. Also not much error handling is added.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim selCount As Long
Dim i As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelectionManager = swModel.SelectionManager
selCount = swSelectionManager.GetSelectedObjectCount2(-1)

If Not selCount = 0 Then

For i = 1 To selCount
swModel.SelectionManager.SetSelectedObjectMark i, 1, 0
Next

Set swFeat = swModel.FeatureManager.InsertMoveFace(0, False, 0, 0.0005)

End If

swModel.ClearSelection2 True

End Sub
Deepak Gupta
SOLIDWORKS Consultant/Blogger
BarryH
Posts: 4
Joined: Tue Nov 08, 2022 8:38 am
Answers: 1
x 1

Re: Macro request

Unread post by BarryH »

Thank you Deepak, that works perfectly.
Post Reply