Automate AutoCad Script

spage

New member
Joined
Dec 5, 2012
Messages
4
Reaction score
0
Points
0
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.​
 
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?
 
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?
 
I took a look around, and it looks like the syntax should be something like the following:

Code:
[FONT=Arial][SIZE=2][FONT=Verdana]sFullFilePath = ThisWorkbook.Path & Application.PathSeparator & "XYZ.scr"
[/FONT][/SIZE][/FONT]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?
 
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
 
Dear Ken
Attachment will take you further into my work.
Thanks for your nice support.
 

Attachments

  • Dick.xlsm
    28.5 KB · Views: 522
Back
Top