API help

Discussion in 'SolidWorks' started by Jean Marc, Sep 23, 2005.

  1. Jean Marc

    Jean Marc Guest

    While in a drawing, I need to write (at the push of a macro button) in a
    text file the document name and the current sheet name. And if possible
    print the current sheet (only).

    Anyone could get me started?

    TIA
    JM
     
    Jean Marc, Sep 23, 2005
    #1
  2. Jean Marc

    That70sTick Guest

    No, I can't.

    Writing the document name to a filie is no problem. (For a log file,
    right?)

    Printing in VB is tricky. However, it can be greatly simplified if you
    fix the printer name, sheet size, etc.
     
    That70sTick, Sep 23, 2005
    #2
  3. Jean Marc

    Jean Marc Guest

    The writing in the text file is the main (and mandatory) part. Yes, it's
    kind of a log file for following up the making of the part (prototype) in
    our shop.
    I would use the default or current settings.

    Thanks
    JM
     
    Jean Marc, Sep 23, 2005
    #3
  4. Jean Marc

    GreenHex Guest

    Hi,

    You want to have a look at the sources to swBatchPrint
    available at swCP3.com?

    Would that be of any help?

    With regards,

    Vinodh Kumar M.
    www.swCP3.com
     
    GreenHex, Sep 23, 2005
    #4
  5. Jean Marc

    CS Guest

    To Print

    Part.PrintDirect 'will send all sheets
    look up
    Part.PrintOut2 ' this will allow you to specify a printer specific
    pages to print and other settings

    this will get you really close

    'you must reference "Microsoft Scripting Runtime"
    'Tools>References then select "Microsoft Scripting Runtime" from the
    list

    Dim swApp As SldWorks.SldWorks
    Dim Model As SldWorks.ModelDoc2
    Dim Drawing As SldWorks.DrawingDoc
    Dim PgSetup As SldWorks.PageSetup

    'this is the path to the log file change it to whatever you desire.
    Const LogFileLocation = "C:\PrintLog.txt"

    Sub main()

    Dim FS As New FileSystemObject
    Dim Log As TextStream

    Set swApp = Application.SldWorks
    Set Model = swApp.ActiveDoc
    Set PgSetup = Model.PageSetup

    'connect to log file if it doesn't exist it will create it
    automatically
    Set Log = FS.OpenTextFile(LogFileLocation, ForAppending, create:=True)

    'write the date and time and the file path to the file
    Log.WriteLine Format(Now, "MM/DD/YYYY HH:MM AMPM") & _
    " " & Chr(34) & Model.GetPathName & Chr(34)

    'close the file
    Log.Close

    'Print the entire document (all sheets)
    Model.PrintDirect

    End Sub
     
    CS, Sep 27, 2005
    #5
  6. Jean Marc

    Jean Marc Guest

    Thanks a bunch, that will help me a lot.

    JM
     
    Jean Marc, Sep 28, 2005
    #6
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.