'However, I suggest to not remove it in order to give AutoCAD the necessary time to execute the command. 'Pause a few milliseconds before proceed to the next command. 'character 'vbCr' is applied in all commands. 'In the newest version of AutoCAD (2015) the carriage-return If Val(acadApp.Version) 0 Or InStr(1, acadCmd, "AI_SELALL", vbTextCompare) Then 'Create a string that incorporates all the commands that exist in each row.ĪcadCmd = acadCmd &. ![]() 'Check if there is at least one command to send. 'Activate the Send AutoCAD Commands sheet and find the last row. Set sht = ThisWorkbook.Sheets("Send AutoCAD Commands") 'Set the sheet name that contains the commands. 'It goes without saying that AutoCAD, as well as VBA in AutoCAD, must be installed at your computer before running this code. 'The code uses late binding, so no reference to external AutoCAD (type) library is required. 'So, if you want to move an object, first send the select command and then the move the opposite will NOT work!!! 'Moreover, unlike the typical AutoCAD behavior, you must first select an object and then apply any modifications to it. Note that it works only for VALID AutoCAD commands! 'It uses the AutoCAD SendCommand method to send the user commands. 'The macro sends the commands that exist in the sheet named "Send AutoCAD Commands" to the opened or to a new AutoCAD drawing. Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) However, the latter is not required for the newest version of AutoCAD (2015 – version 20). One tricky part here was the usage of carriage-return character (vbCr) on Select and Select All (AI_SELALL) commands, which allows the objects to remain selected after the loop moves to the next command (which will make the object editing). The code consists of two loops the first one concatenates the contents of every column into a single string, whereas the second one sends the concatenated string to AutoCAD via the SendCommand method. VBA code for sending AutoCAD commands from ExcelĪ large portion of the code is used to initialize the AutoCAD object, as well as the active/new drawing. ![]() So, for example, if you want to move a polyline, you must first send the select command and then the move the opposite will NOT work! Moreover, unlike the typical AutoCAD behavior, you must first select an object and then apply any modifications to it. Note that the sample workbook that you will find in the Downloads section works only with valid AutoCAD commands (obviously). The object this method applies to.Ĭommand: String input-only. So, based on AutoCAD VBA help, the structure of the SendCommand method is given below: This method processes any AutoCAD command-line function, including LISP expressions. If the drawing specified isn’t active, it will be made active. To cut a long story short, the answer is yes and the proposed solution is based on the SendCommand method of AutoCAD, which sends a command string from a VB or VBA application to the document to be processed. He asked me if it is possible to send AutoCAD commands directly from Excel. About three weeks ago I received an email request from Mohammed.
0 Comments
Leave a Reply. |