We have the circular pattern with 6 holes , i tried to sip 2 and 5th hole using VB macro.
please help
We have the circular pattern with 6 holes , i tried to sip 2 and 5th hole using VB macro.
please help
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Cut-Extrude10", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByRay(0, 6.12592249031991E-02, 1.83651885746757E-02, 1, 0, 0, 8.55364947313662E-04, 1, True, 1, 0)
boolstatus = Part.Extension.SelectByID2("Cut-Extrude10", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)
Part.ActivateSelectedFeature
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Cut-Extrude10", "BODYFEATURE", 0, 0, 0, False, 4, Nothing, 0)
boolstatus = Part.Extension.SelectByRay(0, 6.12592249031991E-02, 1.83651885746757E-02, 1, 0, 0, 8.55364947313662E-04, 1, True, 1, 0)
Dim swFeat As Object
Dim swFeatMgr As Object
Set swFeatMgr = Part.FeatureManager
Dim swFeatData As Object
Set swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmCirPattern)
swFeatData.Direction2 = False
swFeatData.EqualSpacing = True
swFeatData.GeometryPattern = True
swFeatData.ReverseDirection = False
swFeatData.Spacing = 6.2831853071796
swFeatData.TotalInstances = 6
swFeatData.VarySketch = False
Set swFeat = swFeatMgr.CreateFeature(swFeatData)
Part.ClearSelection2 True
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Dim swLocCircPatt As SldWorks.LocalCircularPatternFeatureData
Set swLocCircPatt = swFeat.GetDefinition
swLocCircPatt.AccessSelections swModel, Nothing
Dim skippedItems(1) As Long
skippedItems(0) = 1: skippedItems(1) = 3
swLocCircPatt.SkippedItemArray = skippedItems
swFeat.ModifyDefinition swLocCircPatt, swModel, Nothing
End Sub
Prakash R. wrote:
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Per this line, you need to select the pattern feature.
It will not working i used in solidworks 2019
Part model enclosed here (Part3), i required to skip the any one hole
Please help me
Try these codes.
Option Explicit Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Dim boolstatus As Boolean Dim swFeatData As SldWorks.CircularPatternFeatureData Dim swFeat As SldWorks.Feature Dim skippedItems(1) As Long Sub main() Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID2("Cut-Extrude10", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0) boolstatus = Part.Extension.SelectByRay(0, 6.12592249031991E-02, 1.83651885746757E-02, 1, 0, 0, 8.55364947313662E-04, 1, True, 1, 0) Set swFeatData = Part.FeatureManager.CreateDefinition(swFmCirPattern) swFeatData.Direction2 = False swFeatData.EqualSpacing = True swFeatData.GeometryPattern = True swFeatData.ReverseDirection = False swFeatData.Spacing = 6.2831853071796 swFeatData.TotalInstances = 6 swFeatData.VarySketch = False Set swFeat = Part.FeatureManager.CreateFeature(swFeatData) Part.ClearSelection2 True boolstatus = Part.Extension.SelectByID2(swFeat.Name, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) Set swFeat = Part.SelectionManager.GetSelectedObject6(1, -1) Set swFeatData = swFeat.GetDefinition swFeatData.AccessSelections Part, Nothing skippedItems(0) = 1: skippedItems(1) = 3 swFeatData.SkippedItemArray = skippedItems swFeat.ModifyDefinition swFeatData, Part, Nothing End Sub
And for future, always refer to this post before posting in API section: How to ask a good question in the API forum
it was working only 2 holes only skip if i required more than 2 , where we will change the code
Please help me
Prakash R. wrote:
it was working only 2 holes only skip if i required more than 2 , where we will change the code
Please help me
Change this line to desired amount. 1 in this line indicate 2 items 0 and 1. So bump this value by required items to skip -1.
Dim skippedItems(n) As Long
Now add the instance number to skip in this line
skippedItems(0) = 1: skippedItems(1) = 3: skippedItems(2) = 5
Share you macro codes to see where you're facing issue.
Also the codes by Artem here https://forum.solidworks.com/message/311898#comment-311898 should work fine, have you tried those?