As far as I can tell, you just have to get the Feature corresponding to the pattern and convert it to a TablePatternFeatureData object (by Feature::GetDefinition).
Then you can use TablePatternFeatureData::CoordinateSystem
If you are changing the coordinate system, you will need to use the AccessSelections method (equivalent to Edit Feature in the UI), change the coordinate system, and then Feature::ModifyDefinition
Thank you Simon for the quick response.
In my searching I did find examples of code for creating a new pattern and in that instance dictating the necessary elements that make up the pattern (coordinate system, seed feature, etc). I had considered just deleting the pattern and remaking it each time, but the pattern I am moving actually has a part pattern in an assembly file that moves with the feature pattern. So remaking the pattern each time would not be efficient.
I also noticed the AccessSelections method but it looked like it was used to just get information from the pattern. Do you have any code showing how to modify or edit a feature (a table driven pattern feature would be excellent) using the AccessSelections method and ModifyDefinition?
I don't have any examples to hand, but if you search the API help for "AccessSelections AND example", you will find plenty of examples.
I actually forgot I had used the AccessSelections function to create a macro for changing out the text file that drove the patterns' locations.
I reviewed it and pulled the code into this macro, but I was unable to determine how to get the Coordinate System to be recognized as the correct object type and tried a slew of methods. I was about to post the code in the hopes you could assist in finding the issue and to make the debugging easier I was going through the different methods I used and what error codes I received. I was removing the ' to allow the macro to read the code and I must have modified the code after trying it because the second time I tried the section it worked.
All of that to say thank you Simon for setting me on the correct path, I am posting the code below and highlighting the section that was the subject of this posting:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swFace As SldWorks.Face2
Dim swTablePatternFeatData As SldWorks.TablePatternFeatureData
Dim swCoordSys As SldWorks.Feature
Dim TurnOffScreen As ModelView
Dim SuppState As Variant
Dim ConfigNames As Variant
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
'Turn off screen updating
Set TurnOffScreen = swModel.ActiveView
TurnOffScreen.EnableGraphicsUpdate = False
'Check if model is part file
If Not swModel Is Nothing Then
If Not swModel.GetType = SwConst.swDocumentTypes_e.swDocPART Then GoTo Wrongtype:
'Activate Heater Hole Position Sketch for Editing
boolstatus = swModelDocExt.SelectByID2("HH Position", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
'Select Hole Point and Remove Horizontal Relation
boolstatus = swModelDocExt.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
swModel.SketchConstraintsDel 0, "sgHORIZONTALPOINTS2D"
'Select Point and add new Horizontal Relationship
boolstatus = swModelDocExt.SelectByID2("Point10@Angled Heater Cut and Heaters Position Sketch", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
'Select Angled Face and Heater Hole Position Sketch and redefine sketch plane
boolstatus = swModelDocExt.SelectByID2("HH Position", "SKETCH", 0, 0, 0, True, 0, Nothing, 0)
Set swFace = swModel.GetEntityByName("Angled Heater Face", 2)
swFace.Select2 True, True
boolstatus = swModelDocExt.ChangeSketchPlane(1, Nothing)
'Clear Selections and prepare to change Coordinate System
'Select the Table-Driven Pattern and access it to change coordinate system
boolstatus = swModelDocExt.SelectByID2("Heater Hole Pattern", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swTablePatternFeatData = swFeat.GetDefinition
swTablePatternFeatData.AccessSelections swModel, Nothing
'Select new coordinate system and change to it
boolstatus = swModelDocExt.SelectByID2("Angled Heater CS", "COORDSYS", 0, 0, 0, False, 0, Nothing, 0)
Set swCoordSys = swSelMgr.GetSelectedObject6(1, -1)
swTablePatternFeatData.CoordinateSystem = swCoordSys
'Exit feature with changes intact
swFeat.ModifyDefinition swTablePatternFeatData, swModel, Nothing
'No issues with code > exit sub
TurnOffScreen.EnableGraphicsUpdate = True
'Wrong file type error
TurnOffScreen.EnableGraphicsUpdate = True
MsgBox ("This macro reguires a SolidWorks Part file.")
Glad you got it working. I'm not sure if you actually need to select the coordinate system in order to access it.
I think just getting the Feature called "Angled Heater CS" (e.g. by PartDoc.FeatureByName) would do the trick.
But if your method works, then maybe stick with that.