Sunday 3 September 2017

Let Python do the job for you: AutoCAD drawings printing bot

Recently I’ve been getting familiar with AutoCAD and at the same time I’m trying to improve my Python skills. Odd mix, huh?!

While trying to improve my Python skills I thought I could exercise myself on automating boring tasks. I remembered that a few years ago I was given a boring job which involved printing a lot of drawings directly in PDF format from Autocad. I was too lazy to print the drawings one by one and I knew the process could be automated. At the time I put together a Python script that did the job fine, but it was a bit messy. I thought I could make an improved version.

When nice APIs are not available, such as in the case of AutoCAD (at least that was the case a few years ago, nowdays things may have changed), using Pyautogui may help in the task of automating boring tasks.

The logic of the program is simple:

  1. Look for all the .dwg files in a directory given by the user.
  2. For each file, open the file using the default program, then emulate the sequence of keys the user would need to press in order to print out the file in .pdf format.
  3. Check if file has been printed.
  4. Save log at all the steps in a log file.

Other than the fail safe provided by Pyautogui, some other checks have been added.

A small disadvantage of this program is that it assumes that the drawings are ready to be printed and that the selected printer can be chosen by pressing “am” on the printing menu. These assumptions come basically from the choice of automating the process using Pyautogui and making the program do every single step as a human would do using the computer’s GUI. On the other hand, by going through the printing procedure on your machine and by editing the Pyautogui steps on the code, you can easily fit the code to your needs.

If anything, this is another example of how Python can help in everyday tasks too. The program is shown in a gist below.


Thanks for reading this post.

35 comments:

  1. Thanks for the post. Good solution to automating programs with no native python interface. I'm also interested in using python in the engineering domain (in my case finite element analysis) so this will certainly be useful. Thanks.

    ReplyDelete
    Replies
    1. Thank you for passing by and reading!

      Delete
    2. The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download Now

      >>>>> Download Full

      The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download LINK

      >>>>> Download Now

      The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download Full

      >>>>> Download LINK RH

      Delete
  2. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post.architect planning

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Thank you for sharing such a wonderful information
    python training in Hyderabad the best career

    ReplyDelete
  5. Very good information. we need learn from real time examples and for this we choose good training institute, I'm interested to know about digital marketing which is quite interesting. i need a good training institute for my learning .. so am attending the free demo class which is provided by Apponix Technologies.
    https://www.apponix.com

    ReplyDelete
  6. I need job from home at insurance car
    https://job-for-you-at-home.blogspot.com/

    ReplyDelete
  7. Amazing Article and best information in blog.this Auto CAD drawings printing bot for post.thank for sharing us...

    ReplyDelete
  8. Interesting read. I am an experienced AutoCAD (ACAD) user and AutoLISP developer dipping my toes into Python for Revit. Just curios about the overlap into ACAD. Thanks.

    ReplyDelete
  9. Doesn't work for me
    Shows this error
    RESTART: E:\SARAFAT WORK\2018\17. Akij Bakers Canopy\Approved Drawings\Print to pdf.py
    Traceback (most recent call last):
    File "E:\SARAFAT WORK\2018\17. Akij Bakers Canopy\Approved Drawings\Print to pdf.py", line 159, in
    full_file_path = extract_selected_format(data_wd)
    File "E:\SARAFAT WORK\2018\17. Akij Bakers Canopy\Approved Drawings\Print to pdf.py", line 29, in extract_selected_format
    files = os.listdir(directory_path)
    FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Michy\\Desktop\\autocad_tutorial'
    >>>

    ReplyDelete
  10. It can not open files with spaces

    ReplyDelete
  11. Including 7Notes, any iphone app this inspired the creation of the item, Mazec is incredible by analyzing text message however not as much warm from punctuation. https://imgur.com/a/f1LiH29 https://imgur.com/a/cS5qQ9C https://imgur.com/a/gsaoGpH https://imgur.com/a/OWVn6bh https://imgur.com/a/MxqCTCT http://nzxpx03fma.dip.jp https://imgur.com/a/M56glrv

    ReplyDelete
  12. This would probably be one of the easiest ways to get paid to help out in your local community. Learn more about jobs online on this link.

    ReplyDelete
  13. Ccna training in Banglore
    Thanks, this is generally helpful.Thanks for sharing the information about the and keep updating us.This information is really useful to me.


    Ccna classes in Banglore

    ReplyDelete
  14. If you're interested in getting a job in Python, look at the advanced Python training offered at Hyderabad from AI Patasala. Python Training in Hyderabad by trained experts at AI Patasala training centre is the best option.
    Online Python Course in Hyderabad

    ReplyDelete
  15. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating.
    Python Online Course Training
    Best Python Online Course

    ReplyDelete
  16. The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download Now

    >>>>> Download Full

    The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download LINK

    >>>>> Download Now

    The Beginner Programmer: Let Python Do The Job For You: Autocad Drawings Printing Bot >>>>> Download Full

    >>>>> Download LINK Er

    ReplyDelete
  17. Asset Plus Buyers Agents is the perfect choice if you're looking for the best buyers agent near me. We're a team of experienced professionals dedicated to helping you find the ideal property. We'll work with you to find the right property, negotiate the best price, and help you through the entire process. Contact us today, and let us help you find your dream property. Buyers agent near me

    ReplyDelete
  18. Standout Music Studio offers the best French Horn Lessons in sydney, Australia. Our experienced and certified instructors will help you improve your skills and technique. Contact us today to book your free trial lesson!

    ReplyDelete
  19. Are you looking for the Best Luxury Home Builders in Melbourne, Australia? Bullseye Home Builders are the experts in high-end home construction, focusing on quality craftsmanship and innovative design. We build homes that are not only beautiful and luxurious but also functional and liveable.

    ReplyDelete
  20. Are you looking for Wallpaper in Melbourne, Australia? Divine Interiors specialises in providing high-quality, stylish wallpaper for your home or office.

    ReplyDelete
  21. Are you looking for an Online Hacking Course in Hindi? Cyberpratibha offers a comprehensive course that will teach you everything you need to know about hacking. With over 50 hours of content, you will learn the basics of hacking, how to protect yourself from hackers, and how to use hacking to your advantage.

    ReplyDelete
  22. Double X Power can help to improve sensual function by increasing blood flow to the genital part and delaying ejaculation.
    Boost Stamina on Bed With Double X Power

    ReplyDelete

  23. I really appreciate this post - it was incredibly informative and knowledgeable. I thank you for sharing more content like this.
    CCNA training in Pune

    ReplyDelete
  24. I like your blog! This article provides a practical and insightful approach to automating a repetitive task using Python. The step-by-step explanation of the code and its functionality is clear and well-structured, making it easy for readers to follow along and implement.
    Python Career Opportunities: Why Python Programming is an Ideal Career Option

    ReplyDelete
  25. Thanks for sharing this here. Great Post, really it was very helpful for us. I found this blog to be very useful! python classes in satara

    ReplyDelete
  26. Impressive work! Your Python script for automating the printing of AutoCAD drawings is both practical and well-explained.
    Also Read: Python vs. C++: A Comparison for High-Performance Computing

    ReplyDelete