Results 1 to 6 of 6

Thread: Automate AutoCad Script

  1. #1

    Automate AutoCad Script



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I have developed an AutoCAD script file (XYZ.scr) from Excel file (ABC.xlsx) using VBA Macro.
    Saved XYZ.scr in the same folder as that of Excel file (ABC.xlsx).
    Then launched AutoCAD from the ABC.xlsx.

    Now, I need the Excel VBA solution for launching (drag and drop) XYZ.scr to AutoCAD (to create drawing). Will be through sendcommand or shell or some other and how? An example will be of great help.
    Thanks in advance.

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,225
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Spage,

    Welcome to the forum. I've split your question into a new thread as it wasn't relevent to the one you posted on. In future, please start a new thread if you have a new question.

    As to your question, I have never used AutoCAD, so just need to clarify something. If you doubleclick the .scr file, does it launch AutoCAD and run the script automatically? Or does the .scr have to be loaded from within AutoCAD?
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Thank you Ken for your prompt reply. I was away in country side, so delay in responding back.

    Coming to thread.

    I want to run certain command(s) in AutoCAD, eg, draw a line followed by text writing etc. I have to execute LINE command (with start and end point of line), then another command of TEXT (with font type, inclination, size & the text matter etc.) is to be executed. This is the way AutoCAD works. In order to execute these commands in AutoCAD, I write these in Excel (as the start and end point has to be calculated in excel. Likewise the text matter), save these (set of commands) with .scr extension (directly or may be using notepad).
    Now there are two ways to generate AutoCAD drawing with this scr file.
    Either drag and drop the SCR file onto already opened AutoCAD
    or run the SCRIPT command in AutoCAD (In second method, SCRIPT command will demand the scr file which has to be browsed and endered).
    At the end, in both the methods, the SCRIPT command executes the preset set of command(s).
    I am able to create .scr file with excel macro. Also, I can start AutoCAD again from excel file with macro. The problem is how to send the .scr file as AutoCAD command to AutoCAD file.
    Hope the task is clear.
    Thanks for valuable time.

    Spage,

    Welcome to the forum. I've split your question into a new thread as it wasn't relevent to the one you posted on. In future, please start a new thread if you have a new question.

    As to your question, I have never used AutoCAD, so just need to clarify something. If you doubleclick the .scr file, does it launch AutoCAD and run the script automatically? Or does the .scr have to be loaded from within AutoCAD?

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,225
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    I took a look around, and it looks like the syntax should be something like the following:

    Code:
    sFullFilePath = ThisWorkbook.Path & Application.PathSeparator & "XYZ.scr"
    appAutoCad.ActiveDrawing.SendCommand 'script chr(34) & sFullFilePath & chr(34) & vbCrLf

    The code above was adapated from something I found that was posted from the AutoCad side. I don't have access to the code libraries for this though, so I'm guessing on some of it as I've tried to adapt it for Excel.

    I'm assuming that you've bound to an AutoCad application (I called it appAutoCad), and am guessing that there must be a ActiveDrawing object. Even if that's right, I don't know that this will work due to the ' before script. That should kick the rest of the lines into comments.

    Is there any help syntax in the AutoCad documentation that gives an overview of the SendCommand method?
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  5. #5
    Thank you once again, Dear Ken.
    I feel, it will be better to provide you the excel file with the macro. (I will do it after few hours).
    With season's greetings,
    Vinod Trivedi

  6. #6
    Dear Ken
    Attachment will take you further into my work.
    Thanks for your nice support.
    Attached Files Attached Files

Posting Permissions

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