Editing Mates in an Assembly with a Macro

Discussion in 'SolidWorks' started by vmuntean, Jul 26, 2007.

  1. vmuntean

    vmuntean Guest

    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@").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@").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@").systemvalue = _
    Excel.Range("E1") * 0.0254

    What am I missing? Please help!

    Thank you,

    Vlad
     
    vmuntean, Jul 26, 2007
    #1
  2. vmuntean

    Bill Briggs Guest

    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@") is not the right string for the name of
    the parameter.
     
    Bill Briggs, Jul 26, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.