I'm developing a VBA macro to automatically design and assemble a chair in SolidWorks. The individual parts create successfully, but I'm having issues with the assembly - components are not positioning correctly.
My Chair Structure:
Part1: Seat (rectangular plate, 45x45x3 cm)
Part2: Backrest (vertical plate)
Parts 3-6: Four legs (cylinders)
Parts 7-8: Optional armrests
What I need to achieve:
Fix the seat as the base component at origin
Position the backrest ON TOP of the seat at the rear edge
Position four legs UNDERNEATH the seat at the corners (5cm inset from edges)
Position optional armrests on the sides
Current Code Approach (not working):
' Example of current mating approach
swAssy.Extension.SelectByID2 "Top Plane@Part1-1@" + AssemblyTitle, "PLANE", 0, 0, 0, True, 1, Nothing, 0 swAssy.Extension.SelectByID2 "Top Plane@Part3-1@" + AssemblyTitle, "PLANE", 0, 0, 0, True, 1, Nothing, 0 Set mateFeature = swAssy.AddMate3(5, 0, False, -Thick / 2, 0, 0, 0, 0, 0, 0, 0, False, errors)
Specific Questions:
What's the correct syntax for
AddMate3
when I need to position a component at a specific offset distance? (e.g., leg bottom surface needs to be flush with seat bottom surface)How do I create a distance mate that positions a component at specific X,Y coordinates? (e.g., leg at X = -20cm, Y = -20cm from seat center)
Should I be using face-to-face mates instead of plane-to-plane mates for better control?
Is there a better approach than using standard planes (Top/Front/Right) for positioning - should I create reference geometry?
Environment: SolidWorks 2019, VBA macro
Any examples of properly assembling furniture-like structures with VBA would be greatly appreciated, especially showing how to position components at specific offsets in 3D space.