Can anyone help me with this macro ?

Discussion in 'SolidWorks' started by danferes, Mar 8, 2005.

  1. danferes

    danferes Guest

    In my parts I add 2 custom properties (Proyecto & Piezanum).
    I need that when i do a drawing with this part and save this drawing,
    the name of the drawing file must be "Proyecto-Piezanum.slddrw".
    Is it possible?, How?

    Thanks for your answers :)
    danferes
     
    danferes, Mar 8, 2005
    #1
  2. danferes

    KCS Company Guest

    First off, rely heavily on the API help from the SW help menu.

    FileName = DwgDoc.CustomInfo2(configuration, fieldName1) & "-" _
    & DwgDoc.CustomInfo2(configuration, fieldName2)
    retval = DwgDoc.SaveAs4 (FileName, Version, Options, &Errors, _
    &Warnings)

    Where: FileName = Name of drawing to save
    configuration = Name of part configuration
    (use View.ReferencedConfiguration to extract
    from your drawing view)
    fieldName1&2 = Name of property with values Proyecto & Piezanum
    See API help for other variables

    You should declare all variables.

    If you want to buy a SW utility from my site, I'll write it for you.
    They start at $10 but you can download and use it in a limited but
    still useful mode until registered.
    www.KentContract.com/swmacros.shtml

    Kent
    KCS Company
    www.KentContract.com
     
    KCS Company, Mar 8, 2005
    #2
  3. danferes

    danferes Guest

    Thank you Kent,
    But I'm not sure how to do it.
    Here is my code:
    **********************************************
    Dim swApp As Object
    Dim CurrentDoc As Object
    Dim swModel As SldWorks.ModelDoc2

    Sub main()
    Set swApp = Application.SldWorks
    Set CurrentDoc = swApp.ActiveDoc
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc

    CurrentDoc.ViewZoomtofit2 ' zoom to fit
    CurrentDoc.EditRebuild ' rebuild doc

    CurrentDoc.Save2 False ' "save doc"

    swApp.QuitDoc swModel.GetTitle
    End Sub
    **********************************************
    My idea is substitute "save doc" code with your code (saving the
    drawing file with "Proyecto-Piezanum.drw" file name.
    But I am not capable of doing it, can you help me?
     
    danferes, Mar 10, 2005
    #3
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.