How to change components in a component pattern

160 views
Skip to first unread message

Bjarning

unread,
Apr 26, 2006, 2:58:58 AM4/26/06
to SolidWorks-API
Hi all. I creating a product configurator (using VB). In some
assemblies I use (linear) component patterns. Via API I would like to
be able to change which components is patterned. I believe I need to
use "LocalLinearPatternFeatureData.SeedComponentArray" but I'm new to
SW API and I can't figure out how to do...

Anyone has an example or a tip?

Regards
Jorn Bjarning

Mr. Who

unread,
Apr 27, 2006, 4:54:45 PM4/27/06
to SolidWorks-API
Should be something like this.

' Open an assembly
Dim swApp As Object
Dim Part As Object
Dim SelectionManager As Object
Dim Feature As Object
Dim FeatureData As Object

Set SwApp = Application.Sldworks
Set Part = SwApp.Activedoc
Set SelectionManager = Part.SelectionManager

'1. Find the linear component pattern in tree. Select it with your
mouse.
Set Feature = SelectionManager.GetSelectedObject5(1)

2. Get FeatureData object for Feature.
Set FeatureData = Feature.GetDefinition

3. Make an array of which components are patterned.
'Select new component in tree
Dim newComponents(0) As Variant
newComponents(0) = selectionmanager.GetSelectedObject5(1)

4. Edit the feature
FeatureData.AccessSelections Part, Nothing
FeatureData.SeedComponentArray = newComponents
Feature.ModifyDefinition FeatureData, Part, Nothing

Pretty straightforward.

Bjarning

unread,
Apr 28, 2006, 12:05:36 PM4/28/06
to SolidWorks-API
Mr. Who,

I have tried your example with addition of 2 lines where I select a
pattern and the component to add to the pattern (while testing). I get
the error: "Run-time error '438': Object doesn't support this property
or method" in the line "newComponents(0) =
SelectionManager.GetSelectedObject5(1)".

How come?


Public Sub Main()

' Open an assembly
Dim swApp As Object
Dim Part As Object
Dim SelectionManager As Object
Dim Feature As Object
Dim FeatureData As Object


Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelectionManager = Part.SelectionManager


'Select the linear component pattern in tree.
Part.Extension.SelectByID2 "LocalLPattern1", "COMPPATTERN", 0, 0,
0, False, 0, Nothing, 0
Set Feature = SelectionManager.GetSelectedObject5(1)

'Get FeatureData object for Feature.
Set FeatureData = Feature.GetDefinition

'Make an array of which components are patterned. Select component
to add to pattern
Part.Extension.SelectByID2 "Part3-1@Assem1", "COMPONENT", 0, 0, 0,
False, 0, Nothing, 0

Dim newComponents(0) As Variant
newComponents(0) = SelectionManager.GetSelectedObject5(1)

'Edit the feature


FeatureData.AccessSelections Part, Nothing
FeatureData.SeedComponentArray = newComponents
Feature.ModifyDefinition FeatureData, Part, Nothing

End Sub

Mr. Who

unread,
Apr 28, 2006, 3:04:38 PM4/28/06
to SolidWorks-API
You are storing an object in an array. So you need to use Set
newComponents(0) = SelectionManager.GetSelectedObject5(1).

Then because you have an object array you need to store it in a variant
instead.
Dim vNewComponents as Variant
vNewComponents = newComponents

Then in your modify call:
FeatureData.SeedComponentArray = newComponents

Unforunately I was messing around with this a bit and it looks like the
api is broken in sw2006 at least. I can't add any new components to a
pattern. Sorry for the bad news!

Bjarning

unread,
Apr 29, 2006, 4:01:36 AM4/29/06
to SolidWorks-API
I have been messing around with a lot and it seems to be the same for
SW2005. I believe it goes wrong when trying to add components to the
array (not when updating the pattern), because I managed to remove
components from an existing pattern by reducing the size of the array
and then updating the pattern.

Corey Scheich

unread,
May 1, 2006, 8:49:47 AM5/1/06
to SolidWo...@googlegroups.com
Are you passing the array back with () around it? I believe it is
necessary, though I am not certain.
accessGained = DerivedPatternFeatureData.AccessSelections(topDoc, component)
DerivedPatternFeatureData.ISetSeedComponentArray (featCount, (ArrayDataIn))

You also have to call
DerivedPatternFeatureData.ModifyDefinition to release the selections while
applying the change.

Bjarning

unread,
May 2, 2006, 5:35:03 PM5/2/06
to SolidWorks-API
According to the SW API help the syntax for OLE solutions is:
LocalLinearPatternFeatureData.SeedComponentArray = ArrayDataIn (VB Set
property).

The () is for COM solutions. And as I stated above it works when I
remove a component from the array (by reducing the array size). As I
see it I am either missing something when adding a component to the
pattern or the API is broken here.

Thanks for your input anyway Corey. Any new ideas/comments?

Mr. Who

unread,
May 4, 2006, 6:30:57 PM5/4/06
to SolidWorks-API
I think Corey is right, you do need to place the variant inside an
additional set of parentheticals. Might be worth trying. Let me know
if it works because it actually affects my work.

Bjarning

unread,
May 6, 2006, 2:55:26 AM5/6/06
to SolidWorks-API
I contacted API-support and they confirmed that the API is broken here.
The problem received SPR 320071. A workaround could be to delete the
pattern and create it again every time but in some cases there are
refences to other components (mates etc.) and drawings (dimensions
etc.). I think for now I will accept having a bunch of patterns for
individual components instead of controlling which components is
contained in a single pattern.

Case closed... Thank you all for your input.

Reply all
Reply to author
Forward
0 new messages