How to use SelectByRay api solidworks

Hello

 

I'm trying to make a linear repetition in VBA and after several tries I don't understand the function. The function is always done on the Z axis and it doesn't matter what values I enter.

boolstatus = Part.Extension.SelectByRay(1, 1, 1, 1, 1, 1, 1, 1, 1, False, 1, 0)

Can you help me

thank you in advance

 

Hello

I don't quite understand the question because the SelectByRay function is for selecting and not for repeating. See SelectByRay for more information.

To repeat a component see: FeatureLinearPattern4 - example

To repeat a segment on a sketch see: CreateLinearSketchStepAndRepeat - example

1 Like

Hello

I can't select the x-axis for the 1st direction and the y-axis for the second.

my pieces being all different I would like to fix this selection on these 2 axes

Thank you

 

 

First, the axes must be reference axes, not the directions of the solidworks coordinate system.

Then as noted in the FeatureLinearPattern4 help: The X-axis "Mark" must be 2 and the Y-axis "Mark" must be 4

The example below repeats the part Part1 in the assembly Assem1 which has 2 reference axes Axis1 and Axis2. To be adapted according to your needs.

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim swFeat As SldWorks.Feature
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeatData As SldWorks.LocalLinearPatternFeatureData

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.ClearSelection2 True
boolstatus = swModel.Extension.SelectByID2("Part1-1@Assem1", "COMPONENT", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2("Axis1", "AXIS", 0, 0, 0, True, 2, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2("Axis2", "AXIS", 0, 0, 0, True, 4, Nothing, 0)

Set swFeatMgr = swModel.FeatureManager
Set swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmLocalLPattern)
swFeatData.D1ReverseDirection = False
swFeatData.D1Spacing = 0.05
swFeatData.D1TotalInstances = 3
swFeatData.D2PatternSeedOnly = False
swFeatData.D2ReverseDirection = False
swFeatData.D2Spacing = 0.05
swFeatData.D2TotalInstances = 2
swFeatData.SynchronizeFlexibleComponents = False
Set swFeat = swFeatMgr.CreateFeature(swFeatData)
End Sub

 

I'm still stuck on my job

ModelDoc.ClearSelection2 True ' Clear Selection
boolstatus = Part.Extension.SelectByID2("Boss.-Extru.3", "SOLIDBODY", 0, 0, 0, True, 256, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Axe1", "AXIS", 0, 0, 0, False, 2, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Axe2", "AXIS", 0, 0, 0, True, 4, Nothing, 0)

Dim swLinearPattern As Feature
Set swLinearPattern = Part.FeatureManager.FeatureLinearPattern5(3, 0.3, 5, 0.25, True, False, "Axe1", "Axe2", False, False, False, False, False, False, True, True, False, False, 0, 0, False, False)

She sends me nothing.

thank you for your help

Hello

Try with the following lines instead of yours:

Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Boss.-Extru.3", "SOLIDBODY", 0, 0, 0, False, 256, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Axe1", "AXIS", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Axe2", "AXIS", 0, 0, 0, True, 2, Nothing, 0)
Dim swLinearPattern As Feature
Set swLinearPattern = Part.FeatureManager.FeatureLinearPattern5(3, 0.3, 5, 0.25, True, False, "Axe1", "Axe2", False, False, False, False, False, False, True, True, False, False, 0, 0, False, False)

Kind regards

1 Like

For a piece it is:

Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim swFeat As SldWorks.Feature
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeatData As SldWorks.LinearPatternFeatureData

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
swModel.ClearSelection2 True
boolstatus = swModel.Extension.SelectByID2("Axis1", "AXIS", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2("Axis2", "AXIS", 0, 0, 0, True, 2, Nothing, 0)
boolstatus = swModel.Extension.SelectByID2("Boss.-Extru.3", "SOLIDBODY", 0, 0, 0, True, 256, Nothing, 0)

Set swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmLPattern)
swFeatData.D1EndCondition = 0
swFeatData.D1ReverseDirection = False
swFeatData.D1Spacing = 0.3
swFeatData.D1TotalInstances = 3
swFeatData.D2EndCondition = 0
swFeatData.D2PatternSeedOnly = False
swFeatData.D2ReverseDirection = False
swFeatData.D2Spacing = 0.25
swFeatData.D2TotalInstances = 5
swFeatData.GeometryPattern = False
swFeatData.VarySketch = False
Set swFeat = swFeatMgr.CreateFeature(swFeatData)
End Sub

 

Thank you very much for your help

 

It works perfectly

@pulco41

I don't think that's the best answer 

@+

??????

I got a notification that you had given me the best answer. Thank you.

But there is a bug on the forum that, in some cases, changes the best answer and gives it to the creator of the question. Please rectify if you can.