Results 1 to 10 of 10

Thread: Programmatically send autocad plot file to printer/plotter?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Programmatically send autocad plot file to printer/plotter?

    I've searched the forum and find similar things, but nothing exactly the same. Does anyone know how I would programmatically print an autocad plot file to a printer or plotter? I don't want to have to involve autocad at all. I just want to make a small program that automatically prints out a list of drawings with a button press. Thanks.

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Programmatically send autocad plot file to printer/plotter?

    These are .DWG files?

    "I just want to make a small program that automatically prints out a list of drawings with a button press."
    I take it you mean 'Prints out drawings from a list' ?

    If you get no further replies, I might take a look at doing this, I have plenty of .dwg files to play with... Snag, I'm going to be away from home for a few days. At least that'll give someone else time to reply.

    I just did a quick check and found that trying to import a .dwg file results in an error (Error Opening File), as you'd expect, so there's no immediate simple answer.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: Programmatically send autocad plot file to printer/plotter?

    I don't use autocad. Of course, it does make .dwg files, but I'm wondering if our designer also creates some sort of plot file for each drawing, if I could just send that to the printer. In the old days of dos, I could use a simple line command in a batch file that would print the file to LPT1 or similar. Now, with windows, I would think it's more involved, but I really don't know the first thing about it. I want to make a VB.NET program in place of a batch file that will keep a list of all drawings that go with a particular product, then, at the press of a button, print out all of the drawings automatically. I know how to do all of it, except send the plot file to the printer. Thanks.

  4. #4
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Programmatically send autocad plot file to printer/plotter?

    Hi, ok, I've made a start which may give you some idea of how to go about it, it's by no means complete but it's a start...

    Start a new project, add 2 buttons, 1 Listbox and a FolderBrowserDialog. I put the buttons at the bottom of the form without changing it's size, and filled the remaining space with the listbox.

    In your C: directory add a folder called C:\DWG (hopefully you don't already have one, still even if you do, that's OK so long as you don't have a file called Test.txt in there, else change the name in the code).

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Dim FilePath, DwgPath, Pdata As String
    4.  
    5.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    6.         Button1.Text = "EXIT"
    7.         Button2.Text = "PRINT"
    8.         Button2.Enabled = False
    9.         SelectFolder()
    10.     End Sub
    11.  
    12.  
    13.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    14.         Application.Exit()
    15.     End Sub
    16.  
    17.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    18.  
    19.         Pdata = ""
    20.         FileOpen(1, DwgPath, OpenMode.Input)
    21.  
    22.         Do While Not EOF(1)
    23.             Pdata += LineInput(1)
    24.         Loop
    25.         FileClose()
    26.  
    27.         FileOpen(1, "C:\DWG\Test.txt", OpenMode.Output)
    28.         Write(1, Pdata)
    29.         FileClose()
    30.  
    31.         Application.Exit()
    32.  
    33.     End Sub
    34.  
    35.     Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    36.  
    37.         DwgPath = FilePath & "\" & ListBox1.SelectedItem.ToString
    38.         Button2.Enabled = True
    39.  
    40.     End Sub
    41.  
    42.     Private Sub SelectFolder()
    43.         Dim a As Integer, z As String
    44.  
    45.         FolderBrowserDialog1.ShowNewFolderButton = False
    46.         If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
    47.             FilePath = FolderBrowserDialog1.SelectedPath
    48.         Else
    49.             Application.Exit()
    50.         End If
    51.         a = 0
    52.         z = ""
    53.         'This will empty the ListBox before collecting files.
    54.         Me.ListBox1.Items.Clear()
    55.         ' Get all files xxx.dwg from folder.
    56.         For Each i In My.Computer.FileSystem.GetFiles(FilePath, FileIO.SearchOption.SearchTopLevelOnly, "*.dwg")
    57.             z = My.Computer.FileSystem.GetName(i)
    58.             ' Add each file to the list box.
    59.             Me.ListBox1.Items.Add(z)
    60.         Next
    61.  
    62.     End Sub
    63.  
    64.  
    65. End Class

    If you add this code and run the app', first you'll be presented with an option to chose a folder in which to find your drawing... select a folder and click OK.
    Next you'll get a list of the '.DWG' files in that folder, click one of those and if all's well, Button2 (Print) will be enabled. Click that and the app' chould close and in your new C:\DWG folder you should have a 'Test.txt' file containing the data for your drawing, byte by byte as the original, now all you need to do is to write code to open this file and send it to your printer or plotter. Of course, once you've done that, you can marry the two app's to cut-out the middle-man Text.txt file.

    I suppose I could've listed the subroutines in the order in which they are called, but by habit I put them in alphabetical order by name, except for the Form1_Load which I always put first... sorry.


    Poppa.
    Last edited by Poppa Mintin; Jun 4th, 2013 at 05:59 PM.
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: Programmatically send autocad plot file to printer/plotter?

    that's a long list of legacy code you're using there.
    you've been programming in .Net a while now. why keep the past alive???

    FileOpen Function - http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
    OpenMode Enumeration - http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
    EOF Function - http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
    LineInput Function - http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
    FileClose Function - http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: Programmatically send autocad plot file to printer/plotter?

    .Net method:

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        IO.File.Copy(DwgPath, "C:\DWG\Test.txt")
    End Sub

  7. #7
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Programmatically send autocad plot file to printer/plotter?

    Quote Originally Posted by .paul. View Post
    .Net method:

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        IO.File.Copy(DwgPath, "C:\DWG\Test.txt")
    End Sub
    That's neat, I'll keep that in mind...

    Actually I was only giving an example of how to select a file...
    DWG files are produced by Auto Cad and can't be used straight from the file anyway... It might be that he'll need to try to break up the file into individual graphic lines, I suspect he won't be able to do that with a straight copy.


    Poppa.
    Last edited by Poppa Mintin; Jun 4th, 2013 at 08:04 AM.
    Along with the sunshine there has to be a little rain sometime.

  8. #8
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Programmatically send autocad plot file to printer/plotter?

    Quote Originally Posted by Poppa Mintin View Post
    It might be that he'll need to try to break up the file into individual graphic lines, I suspect he won't be able to do that with a straight copy.
    As an example, one of my .dwg files has 2099 LineInput lines, the last of which is: ËÏÆ,

    The first is:AC1009 Í Ï äì à t~ @W €- í ) !ð Æ ¨ò ¿ Jû ™ äÿ ˆ‰@ Ё@ HŠ@ ‚@ ˆy@Î0,hmr@ Î0,hm‚@ ð? ð? $@ $@ ð? @ $@ Ì §ëº‚ +ö? ð? l C:\ACAD\SUPPOR ð? @ @ $@ @ @ @ T\MARKEM ð? ô? Ð ÿ¯e% ²M/¯e% ²M/ Î,

    And a typical line from elsewhere (375) is:×£p8@ 9ÜÇ®æÉ?0ù 2 ô(\¢Î€@š™™™™]m@òÂõ(\W$@FT‘áß@7-+·&Ô?{å* ø€@ n@ @ n@¬×* @23333ûm@ @23333ûm@µÐ* @j×7öcÂm@ @j×7öcÂm@¨ƒ* @dffff""l@ @˜™™™™]m@‡ú* @Ì[û<Ïøl@ @Ì[û<Ïøl@˜û* @˜(È œ½k@ @˜(È œ½k@/|* @4¤Ã0‡l@ @4¤Ã0‡l@""Ò 2 ÷(\¢Î€@fffff""l@AÂõ(\W$@?T‘áß@œ-+·&Ô?£}* ø€@ pk@ @ pk@!\* @ÌÌÌÌÌ„k@ @ÌÌÌÌÌ„k@fÕ* ø€@ *j@ èƒ@ÿÿÿÿÿŸj@z* ˆ@ €f@ °…@ €f@çZ* 33333„@üÿÿÿÿ_]@33333„@þÿÿÿÿÏa@¹}* 33333„@üÿÿÿÿ_]@ „@üÿÿÿÿ_]@2y* 33333„@þÿÿÿÿÏa@ „@þÿÿÿÿÏa@:¦* P„@Œiºðria@ P„@à,‹-^@t* ˆƒ@þÿÿÿÿ+a@ ˆƒ@ ¨^@I¦* –ƒ@þÿÿÿÿ?`@ ˜ƒ@dffffÆ]@é* pƒ@ ¨^@œ÷ÀXƒ@¸¥yW1è^@žg* fEG‚{pƒ@øÛT³^@p=9ýAZƒ@Yp¦&ï^@Þ* Dƒ@ ¨^@ dƒ@˜t¨4K_@lX* 33333÷‚@üÿÿÿÿ¿_@33333÷‚@ ¨^@ãA* š™™™™mƒ@üÿÿÿÿ_@ ˆƒ@ ¨^@ýb* „@þÿÿÿÿÏa@ „@üÿÿÿÿ_]@.$* „@þÿÿÿÿÏa@ „@üÿÿÿÿ_]@…ü* ”ƒ@dffffæ]@ ”ƒ@ÊÌÌÌÌŒa@Ã÷* ¼ƒ@ÊÌÌÌÌœa@”%°i?½ƒ@23333Ã`@õ)* ´ƒ@ÊÌÌÌÌœa@”%°i?µƒ@23333Ã`@ * ¬ƒ@ÊÌÌÌÌœa@”%°i?*ƒ@23333Ã`@_F* œƒ@ÊÌÌÌÌœa@ *ƒ@dffffÆ]@ä* ¤ƒ@ÊÌÌÌÌœa@ ¨ƒ@dffffÆ]@Òc* 33333³‚@üÿÿÿÿ¿_@33333³‚@ ¨^@¢÷* 33333›‚@Øÿÿÿÿ§^@33333›‚@ͪù5*`@]D* Dƒ@ ¨^@33333›‚@ ¨^@xˆ* „@üÿÿÿÿ_]@~#ѰJ„@@H*žÔð]@Ü* ”ƒ@ ¨^@ ˆƒ@ ¨^@š’* pƒ@ ¨^@fEG‚{pƒ@øÛT³^@^å* 33333„@üÿÿÿÿ_]@ „@üÿÿÿÿ_]@ÿ 2 H„@à,‹-^@ ð?>Š**¾8@ G* pƒ@ ,a@œ÷ÀXƒ@$-CTça@â´* fEG‚{pƒ@p’U?&a@p=9ýAZƒ@|ÓǬla@ßq* dƒ@ `@ `ƒ@ `@µí* Dƒ@ ,a@ dƒ@²Å«eÚø`@‹* dƒ@ à_@ `ƒ@ à_@¹* 33333÷‚@þÿÿÿÿŸ`@33333›‚@þÿÿÿÿŸ`@=0* 33333÷‚@üÿÿÿÿ¿_@33333›‚@üÿÿÿÿ¿_@¢f* Dƒ@ ,a@33333›‚@ ,a@ͧ* 33333§‚@þÿÿÿÿŸ`@33333§‚@üÿÿÿÿ¿_@l* 33333ë‚@üÿÿÿÿ¿_@23333ë‚@þÿÿÿÿŸ`@§§* ®F<Ç‚@ `_@23333é‚@ `_@†* ®F<Ç‚@033333_@fffffì‚@033333_@* fffffì‚@03333“_@®F<É‚@03333“_@ˆW* ®F<É‚@`fffff_@23333é‚@`fffff_@/v 2 ®F<Ç‚@˜™™™™I_@ffffffÖ?-DTû!ù?Ò!3|Ù@°í 2 ®F<É‚@03333ƒ_@ Ð?-DTû!ù?Ð-DTû! @px* ®F<Ç‚@\ffffv_@®F<Ç‚@03333ƒ_@”8 2 ®F<É‚@`ffffv_@ Ð?4.DTû! @Ò!3|Ù@T* 33333ï‚@˜™™™™I_@33333ï‚@ÈÌÌÌÌ|_@û 2 23333é‚@03333c_@ €™™™™©?Ò!3|Ù@-DTû!ù?lÒ 2 fffffì‚@ÈÌÌÌÌ|_@ffffffÖ? -DTû!ù?£ 2 fffffì‚@˜™™™™I_@ffffffÖ?Ò!3|Ù@ * ®F<·‚@dffff¶`@fffffÚ‚@dffff¶`@‡Í* fffffÜ‚@üÿÿÿÿÏ`@33333Û‚@üÿÿÿÿÏ`@È* fffffÜ‚@dffffæ`@®F<·‚@dffffæ`@ï<* 33333³‚@ ,a@33333³‚@—™™™™á`@. 2 ®F<·‚@˜™™™™Á`@ffffffÖ?-DTû! @Ò!3|Ù@8¸ 2 ®F<·‚@03333Û`@ffffffÖ?-DTû!ù?-DTû! @²¤* àDyGo´‚@03333Û`@àDyGo´‚@þÿÿÿÿ×`@uÃ* 33333÷‚@ ,a@33333÷‚@þÿÿÿÿŸ`@óq 2 fffffÜ‚@03333Û`@ffffffÖ?Ò!3|Ù@-DTû!ù??Ó* fffffÜ‚@ÎÌÌÌÌÄ`@fffffÜ‚@dffff¾`@Xõ 2 fffffÚ‚@dffff¾`@ Ð?Ò!3|Ù@ à6=v¶ 2 fffffÚ‚@ÌÌÌÌÌÄ`@ Ð? ÀA=é\.

    It might also be that he'll need to convert each character into it's ASCII code... again I think he'll need more than just a straight copy.

    I might also mention that I picked this question to answer because nobody else had offered any sort of answer... I always figure an answer, no matter how 'old hat' it might be, is much better than no answer at all.


    Poppa.
    Last edited by Poppa Mintin; Jun 4th, 2013 at 08:37 AM.
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: Programmatically send autocad plot file to printer/plotter?

    I do AutoCAD automation on a grand scale here. If I understand your original question, you want to print "plot" files that were produced by AutoCAD. I'm sure that can be done but my question is why would you want to do that? I am assuming you have AutoCAD available to you. And you can involve AutoCAD without having to involve AutoCAD. That is you can launch it, load and print your drawing and then close it without ever seeing it appear on the monitor. I do this all the time. If you could explain a little more in detail what your setup is that might help. For example, are the "plot" files given to you and you do not have access to AutoCAD itself then we would need to approach this from a different angle. But the best tool to print AutoCAD drawings is AutoCAD. If the folks from your design department are presenting you with "plt" files then why don't they just supply you with PDF files...that would make things much simpler. Also, if you have AutoCAD, this is really a task much better suited to LISP which is again, part of the AutoCAD environment. But if you need to stay completely outside of AutoCAD there are methods available to do what you want.

    And BTW, I found this which might help you if you want to just send plt files straight to your printer.
    Last edited by Vladamir; Jun 4th, 2013 at 10:04 AM.

  10. #10
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Programmatically send autocad plot file to printer/plotter?

    Quote Originally Posted by Vladamir View Post
    I do AutoCAD automation on a grand scale here. If I understand your original question, you want to print "plot" files that were produced by AutoCAD. I'm sure that can be done but my question is why would you want to do that? I am assuming you have AutoCAD available to you.
    Vladamir did you miss the 3rd post ?

    Quote Originally Posted by rickford66 View Post
    I don't use autocad. Of course, it does make .dwg files, but I'm wondering if our designer also creates some sort of plot file for each drawing, if I could just send that to the printer. In the old days of dos, I could use a simple line command in a batch file that would print the file to LPT1 or similar. Now, with windows, I would think it's more involved, but I really don't know the first thing about it. I want to make a VB.NET program in place of a batch file that will keep a list of all drawings that go with a particular product, then, at the press of a button, print out all of the drawings automatically. I know how to do all of it, except send the plot file to the printer. Thanks.
    Hmmm... I've just noticed that I missed: -
    I know how to do all of it, except send the plot file to the printer.
    in the 3rd post myself... (Oh bother!)

    Sorry Rickford, I've been wasting your time. However Vladamir's suggested URL should be exactly what you're after.

    (http://www.lingpartnership.com/plotfiles.htm)

    Poppa.
    Last edited by Poppa Mintin; Jun 4th, 2013 at 06:07 PM.
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width