I hope the below gets you a push in the right direction.
To Insert a component named MySlotWashers into the assembly:
Set MySWComponent = swApp.OpenDoc6(MySlotWashers, swDocPART,
swOpenDocOptions_Silent, "", fileerror, filewarning)
Set MySWAssembly = swApp.ActivateDoc2(MySWAssembly.GetPathName,
Set NewComponentID = MySWAssembly.AddComponent4(MySlotWashers,
MySlotWasherConfig, 0, 0, 0)
To Add a Coincident Mate:
boolstatus = EntityArray(1).Select4(True, swSelData)
boolstatus = MySWAssembly.Extension.SelectByID("Bottom Mate Plane@"
& NewComponentID.Name2 & "@" & MySWAssemblyName, "PLANE", 0, 0, 0,
True, 0, Nothing)
Set SWFeature = MySWAssembly.AddMate2(0, 0, False, 0, 0, 0, 0, 0,
0, 0, 0, longstatus)
As for the Lookup Table statement, I think I should have used a
different term. Yes Excel has a native lookup function that would work
just fine, but I would recommend *not* involving Excel in this mix
unless you have to because you're just adding more complexity (that I
think you don't need to get into for this project). For now (or maybe
at least for starters), just keep all the code and conditional stuff
inside your macro. The lookup I was talking about was something along
the lines of:
Sub main ()
Set swApp = CreateObject("SldWorks.Application")
Set MySWAssembly = swApp.ActiveDoc
<<<All your code to read in the dimension value, I'll call it DimVal>>>
'Poor man's Lookup Table to get Filename of Component to Insert into
Dim MyInsertComponentFilename as String
If DimVal = 0.250 Then
MyInsertComponentFilename = "0.250-SHAFT.SLDPRT"
ElseIf DimVal = 0.500 Then
MyInsertComponentFilename = "0.500-SHAFT.SLDPRT"
ElseIf DimVal = 0.750 Then
MyInsertComponentFilename = "0.750-SHAFT.SLDPRT"
ElseIf DimVal = 1.000 Then
MyInsertComponentFilename = "1.000-SHAFT.SLDPRT"
MsgBox "Error. Filename for " & DimVal & " Not Found."
<<< Stuff to Insert and Mate your Component, or whatever you you want
to do. >>>>