Editing Mates in an Assembly with a Macro

Hello,

I am trying to edit distance mate values in assemblies from an Excel spreadsheet with the help of a macro. It seems to work fine with the following code:

Private Sub Refresh_Click() Set swApp = CreateObject("SldWorks.Application") Set Part = swApp.ActiveDoc Part.Parameter("BevDia2@ snipped-for-privacy@gear.Part").systemvalue = _ Excel.Range("B4") * 0.0254 Part.Parameter("D1@Distance1").systemvalue = _ Excel.Range("E1") * 0.0254 Part.EditRebuild Part.ClearSelection End Sub

This code updates a dimension of a part in the assembly and updates the Dimension Mate. Everything works well untill I drop the assembly into another assembly. I thought that all I would need to change is to add "@assembly name.Part" for it to work.

Part.Parameter("D1@ snipped-for-privacy@Gearbox.Part").systemvalue = _ Excel.Range("E1") * 0.0254

If I drop the assembly into another assembly, the dimensions to individual parts still work fine but I get an error message for the dimension mate:

Object variable or With block variable not set and it highlights this line:

Part.Parameter("D1@ snipped-for-privacy@Gearbox.Part").systemvalue = _ Excel.Range("E1") * 0.0254

What am I missing? Please help!

Thank you,

Vlad

Reply to
vmuntean
Loading thread data ...

Without diving too deeply into this, it seems like you could get the model object for the original assembly and then use the code as it was before inserting it into the assembly. This can be done by using the following:

Set swModel = swApp.GetFirstDocument While Not swModel Is Nothing

' Do Something Here if model name matches Debug.Print swModel.GetPathName

Set swModel = swModel.GetNext Wend

Another thought is did you record a macro editing the dimension in the new assembly? Again with looking to closely, I think the ("D1@ snipped-for-privacy@Gearbox.Part") is not the right string for the name of the parameter.

Reply to
Bill Briggs

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.