AnsweredAssumed Answered

How to add a linear pattern for a derived pattern?

Question asked by Peter Brinkhuis on Nov 5, 2020
Latest reply on Nov 13, 2020 by Peter Brinkhuis

I have an assembly with a derived pattern. 


Now I would like to create a linear pattern and use this derived pattern feature as the source. 


This seems to be harder via the API than via the UI. I've been looking at the docs and I've tried multiple combinations of marks.

2017 SOLIDWORKS API Help - FeatureLinearPattern5 Method (IFeatureManager) 


This code is based on the macro recorder, but I've cleaned it up a bit. It does not create a feature


Option Explicit

Sub main()
Dim swApp As ISldWorks
Dim swModel As ModelDoc2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Dim featureMark As Integer, edgeMark As Integer
featureMark = 4
edgeMark = 1

swModel.Extension.SelectByID2 "DerivedHolePattern1", "COMPPATTERN", 0, 0, 0, False, featureMark, Nothing, 0
swModel.Extension.SelectByRay -0.153348876802255, -7.0921728047324E-04, 3.94164786965234E-02, 0.105422075835155, 0.835855193918556, -0.538732104784911, 4.41934305387608E-04, 1, True, edgeMark, 0

Dim swFeat As Object, swFeatMgr As Object, swFeatData As Object
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 = 1
swFeatData.SynchronizeFlexibleComponents = False

Set swFeat = swFeatMgr.CreateFeature(swFeatData)
End Sub


Any idea how I can get this to work? I have been able to pattern a single component, but not this feature.


Do I need to treat the Derived Pattern as a feature or a component? In the UI, it seems to be selected as a component, see the second image.


I have attached my assembly so you can test it quickly.


Edit: ok the first thing I learned after writing this is that a linear pattern is for parts and a local pattern is for assemblies. I'll keep you posted.