Can someone help me out with the macro

Discussion in 'SolidWorks' started by SW Monkey, Jun 25, 2003.

  1. SW Monkey

    SW Monkey Guest

    Below is a simple macro to export the current drawing as a DXF file to
    N:\DXF. As you can see, it names the DXF "Draw1.dxf". How can I edit
    the macro to so the dxf filename is the same filename as the
    SolidWorks drawing, which is our part numbering system. Thanks in
    advance.


    Dim swApp As Object
    Dim Part As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long
    Dim Annotation As Object
    Dim Gtol As Object
    Dim DatumTag As Object
    Dim FeatureData As Object
    Dim Feature As Object
    Dim Component As Object
    Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    Part.SaveAs2 "N:\DXF\Draw1.DXF", 0, True, False
    End Sub
     
    SW Monkey, Jun 25, 2003
    #1
  2. This should work.............

    Dim swApp As Object
    Dim Part As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long
    Dim Annotation As Object
    Dim Gtol As Object
    Dim DatumTag As Object
    Dim FeatureData As Object
    Dim Feature As Object
    Dim Component As Object
    Dim PartTitle As String

    Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc

    PartTitle = Part.GetTitle

    Part.SaveAs2 "N:\DXF\" & PartTitle & ".DXF", 0, True, False
    End Sub
     
    Corey Scheich, Jun 25, 2003
    #2


  3. Dim swApp As Object
    Dim Part As Object
    dim partitle as string
    dim partitlelen as integer
    dim partName as string

    Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc

    partitle = part.gettitle
    partitlelen = len(partitle)
    partname = left(partitle,partitlelen - (partitlelen -7))

    Part.SaveAs2 "N:\DXF\" & partname & ".DXF", 0, True, False

    End Sub
     
    Sean Phillips, Jun 25, 2003
    #3
  4. SW Monkey

    SW Monkey Guest

    Thanks! Works great. One last question, is there a command to add to
    this that would scale the drawing view 1:1 automatically before
    exporting as a DXF?
     
    SW Monkey, Jun 26, 2003
    #4
  5. Can we add a suffix to each part number while running this macro? In our
    case "-01" to identify the first configuration.

    Thanks in advance.
     
    Peter F. Clarke, Jun 30, 2003
    #5
  6. Dim swApp As Object
    Dim Part As Object
    dim partitle as string
    dim partitlelen as integer
    dim partName as string

    Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc

    partitle = part.gettitle
    partitlelen = len(partitle)
    partname = left(partitle,partitlelen - (partitlelen -7))

    'YOU CAN ADD A LINE LIKE THIS
    SUFFIX = "-1"
    Part.SaveAs2 "N:\DXF\" & partname & SUFFIX & ".DXF", 0, True, False

    End Sub

    If you need to get your config names

    Dim Config As SldWorks.configuration

    Set Config = Part.GetActiveConfiguration
    ConfigName = Config.Name
    Part.SaveAs2 "N:\DXF\" & partname & ConfigName & ".DXF", 0, True, False
     
    Corey Scheich, Jun 30, 2003
    #6
  7. Thanks Corey!
     
    Peter F. Clarke, Jul 1, 2003
    #7
  8. SW Monkey

    SW Monkey Guest

    I couldnt get the 1:1 scale code to work. Maybe I placed it in the
    wrong part of the macro. Can you explain. Thanks.

    I also wanted to know if its possible to close the drawing without
    saving after the DXF file has been created.

    Thanks. :)
     
    SW Monkey, Jul 2, 2003
    #8
  9. You have to rebuild after the 1:1

    You have to do a rebuild you have finished scaling. Use the sub
    below. This way if you want .25 scale or 1 or 2 or 50 you can call it
    from another sub and specify the scale

    Sub viewScale(MyScale As Double)
    Dim swView As SldWorks.View
    Dim swApp As SldWorks.SldWorks
    Dim Part As DrawingDoc

    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Set swView = Part.GetFirstView

    'this while statement will traverse every view on the sheet

    While Not swView Is Nothing
    swView.ScaleDecimal = MyScale
    Set swView = swView.GetNextView
    Wend
    Part.EditRebuild

    End Sub


    This should do it. I think that if you want to save you have to do a
    Part.Save before CloseDoc

    Dim ModelDocument as SldWorks.ModelDoc2
    Set ModelDocument = Part
    swApp.CloseDoc ModelDocument.GetTitle
     
    Corey Scheich, Jul 2, 2003
    #9
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.