AutoCad Command Line Using Dynamo

AutoCad Command Line Using Dynamo

rvtquestions
Advocate Advocate
5,195 Views
6 Replies
Message 1 of 7

AutoCad Command Line Using Dynamo

rvtquestions
Advocate
Advocate

This post is related to an earlier discussion started by  @Yonas89 with a fruitful response by @Anonymous

https://forums.autodesk.com/t5/net/integrate-dynamo-with-autocad/td-p/6674248

 

Basically, my question is if there is a way to call the commandline in AutoCad by using Dynamo? Or is it only accessible to certain methods like .AddLine()?

 

For example, if we had a string input of a list of commands in dynamo:

where IN[0] would receive something like ["-zoom", "extents", "-ai_selall"], can that be summoned into AutoCad? And going further, can we call up a list of lisps to run?

0 Likes
5,196 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

The link refers to roundabouts and intersections, better of looking at Transoft roundabout design it takes into account the type of vehicle travelling through.

 

Why not work in lisp etc so much help.

 

I have some nice stuff for CIV3D like change surface display via tool bar, change point angle by pick. Personally hate the toolspace having to go there to change a display.

 

 

0 Likes
Message 3 of 7

Yonas89
Collaborator
Collaborator

@rvtquestions,

I'm not really sure if I understand your question correctly but I'll try my luck and  ask why not to use Autocad macros functions and scripting? There is also a macro recorder where you can create a "chains" of your commands.

0 Likes
Message 4 of 7

rvtquestions
Advocate
Advocate

Ultimately, I am trying to understand the extents of how the referenced example works. I'm trying to understand if my request is possible or if this Dynamo to Autocad feature is limited to specific commands like drawing a line. My question is basically asking if we could literally send text into an Autocad CommandLine via Dynamo.  So if I had a list of strings [] ["z" "e" …] etc. it would input those into the command line and run. While I understand there are macros, scripts, lisps, etc. I am asking because there is something interesting/powerful to be able to automate tasks in AutoCad along with other parts that I am processing in Dynamo. More specifically, the initial question arose from the fact that I ran into Batch script issues that failed on me. I used Batch scripts and scriptpro type software before but there have been instances when something goes wrong and ultimately leaves it useless. Therefore, I am curious to know if I could workaround it by inputting commands via Dynamo.

Message 5 of 7

Yonas89
Collaborator
Collaborator

@rvtquestionsthat's a very interesting approach actually. Good stuff to think about all the possibilities. 

From what I know so far, AutoCAD could be accessed  from Dynamo through the old fashion COM API only, which I think is very underestimated these days, cause you can access almost every software you have on your windows. Still not sure if you were looking for this, but this simple script sends the "Hello world" command to AutoCAD.

import clr
clr.AddReference('ProtoGeometry')
import Autodesk
from Autodesk.DesignScript.Geometry import *
import System
from System import *

o = "no"
c = IN[0]
if len(c) != 0:
	app = System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application")
	AcDoc = app.ActiveDocument
	AcDB = AcDoc.Database
	AcDoc.SendCommand(c)
	o ="ok"
#Assign your output to the OUT variable.
OUT = o

HelloWorld.PNG

Message 6 of 7

rvtquestions
Advocate
Advocate

@Yonas89 

 

Hey Yonas, 

 

excuse my late reply as I put this on the side but exploring it again now. Thank you for your contribution! While simple, it certainly is an interesting step forward. Replicating your test using Manual Mode, I am able to send whatever text to the Autocad Command Line, however it does complete the command (the text just sits in the command line). Ultimately, it seems to be missing something to replicate the "Enter" key. Even when I send the command "" or " ", it doesn't register. I have a few questions for you:

 

  • Where did you find out about these methods such as SendCommand()? Is that part of a Dynamo API or AutoCad API?
  • It seems to finish my initial request all we would need know is how to:
    • Finish a sent command/simulate the enter key
    • Wait for the command to finish
    • For loop this whole process, for each string x in IN[0]....SendCommand(x)...enter...next
0 Likes
Message 7 of 7

Yonas89
Collaborator
Collaborator

@rvtquestions, please leave space after each text as in my example (If you take a closer look I wrote "HelloWord " and not "HelloWord"). Blank space in string = enter in autocad command line.  These rules comes from AutoCAD scripting principles. Here's short intro about it: https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/AutoC.... So I believe with Dynamo you can extend this scripts by implementing logic and analysis in the middle of your script and make reactions based on the results you get in between. Other way, you don't need dynamo for simple scripting.

AutoCAD has many API's but the only one allows to manage AutoCAD from "outside" and manage the objects not from the drawing. This api is called  COM API. For documentation look here for all the methods and properties: http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30

Click on the "Document" in the chart and you will see "SendCommand" method.