<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Implementing Python to AutoCAD in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/6861674#M123969</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find some information here:&amp;nbsp;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/03/using-ironpython-with-autocad.html" target="_self"&gt;using-ironpython-with-autocad&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 04:13:15 GMT</pubDate>
    <dc:creator>hgasty1001</dc:creator>
    <dc:date>2017-02-08T04:13:15Z</dc:date>
    <item>
      <title>Implementing Python to AutoCAD</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/6858701#M123968</link>
      <description>&lt;P&gt;Good day people of AutoCAD,&lt;/P&gt;&lt;P&gt;firstly,&amp;nbsp;in the link &lt;A title="Section view from Point Cloud" href="https://forums.autodesk.com/t5/autocad-2013-2014-2015-2016-2017/simplifying-process-to-extract-section-view-from-point-cloud/m-p/6858423#M161782" target="_blank"&gt;here&lt;/A&gt;, I have drew a section view of a model using point cloud, section lines and paperspace.&lt;/P&gt;&lt;P&gt;I am now trying to automate the process that I conducted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the progress so far.&lt;/P&gt;&lt;P&gt;As you can see in Script 2, I am simply repeating the procedure.&lt;/P&gt;&lt;P&gt;I have heard about pyAutoCAD, which connects python and autocad. Here is the link if anyone is interested.&lt;/P&gt;&lt;P&gt;&lt;A href="https://media.readthedocs.org/pdf/pyautocad/latest/pyautocad.pdf" target="_blank"&gt;https://media.readthedocs.org/pdf/pyautocad/latest/pyautocad.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, with current documentation, I am not cleared about its functionality, since what I need are&amp;nbsp;&lt;STRONG&gt;direct implementation of commands in Autocad to Python workspace,&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;Selection of an object purely based on command line/code without using mouse &lt;/STRONG&gt;and/or&amp;nbsp;&lt;STRONG&gt;Assignment of variable based on data in AutoCAD&lt;/STRONG&gt;&lt;STRONG&gt;.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I mean by this is that in my python script I wish to import commands directly (eg: PCExtractsection, 3dmove, etc) and select a point cloud without any filter. For now, as you could see, I&amp;nbsp;can use fence and manually type in input, however it is not the most effective way. Also, if I can identify boundary of a point cloud and assign it as variables, all the work can be extremely efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you know a method for any of above or who to contact to, any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;***Script 1***
-DWGUNITS
6
2
4
Y
Y


_POINTCLOUDATTACH
"C:\Users\Charlie Lee\Desktop\2d_elevation\point clouds\Kuring_gai_fullpoint.rcp" 0,0,0 1 0
_ai_selall

_ai_selall
rotate3d X 0,0,0 -90


SECTIONPLANE
O
T
SELECT
l

_ZOOM
e
_Cancel


***Script 2***
PCEXTRACTSECTION
all
a
3DMOVE
FENCE
0,170,0
0,180,0


0,0,0
0,0,-0.1
-PCEXTRACTSECTION
all
3DMOVE
FENCE
0,170,0
0,180,0


0,0,0
0,0,-0.1
-PCEXTRACTSECTION
all
3DMOVE
FENCE
0,170,0
0,180,0


0,0,0
0,0,-0.1
-PCEXTRACTSECTION
all
3DMOVE
FENCE
0,170,0
0,180,0


0,0,0
0,0,-0.1
-PCEXTRACTSECTION
all
3DMOVE
FENCE
0,170,0
0,180,0


0,0,0
0,0,-0.1
-PCEXTRACTSECTION
all
3DMOVE
FENCE
0,170,0
0,180,0



&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 01:57:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/6858701#M123968</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-02-07T01:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing Python to AutoCAD</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/6861674#M123969</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find some information here:&amp;nbsp;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/03/using-ironpython-with-autocad.html" target="_self"&gt;using-ironpython-with-autocad&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 04:13:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/6861674#M123969</guid>
      <dc:creator>hgasty1001</dc:creator>
      <dc:date>2017-02-08T04:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing Python to AutoCAD</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/8254031#M123970</link>
      <description>&lt;P&gt;Well, you can use &lt;EM&gt;&lt;A href="https://pythonhosted.org/comtypes/" target="_blank"&gt;comtypes&lt;/A&gt;&amp;nbsp;&lt;/EM&gt;disutil, install it from cmd using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;python -m pip install comtypes&lt;/PRE&gt;&lt;P&gt;then, the simplest python script to apply a command would be like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#Import needed modules
import os
import comtypes.client
from comtypes import COMError
from comtypes.client import CreateObject, GetActiveObject

def main():
    try: #Get AutoCAD running instance
        acad = GetActiveObject("AutoCAD.Application.20")&lt;BR /&gt;        state = True
    except(OSError,COMError): #If autocad isn't running, open it
        acad = CreateObject("AutoCAD.Application.20",dynamic=True)&lt;BR /&gt;        state = False
    &lt;BR /&gt;    if state: #If you have only 1 opened drawing
        doc = acad.Documents.Items(0)&lt;BR /&gt;    else:&lt;BR /&gt;        filepath = "E:/Dir1/Dir2/myDWG.dwg" #Replace it with the actual drawing path&lt;BR /&gt;        doc = acad.Documents.Open(filepath)&lt;BR /&gt;&lt;BR /&gt;    #Our example command is to draw a line from (0,0) to (5,5)
    command_str = '._line 0,0 5,5 ' #Notice that the last SPACE is equivalent to hiting ENTER
    #You should separate the command's arguments also with SPACE

    #Send the command to the drawing
    doc.SendCommand(command_str)

#Execution Part
if __name__ == '__main__':
    main()&lt;/PRE&gt;&lt;P&gt;___________&lt;BR /&gt;To communicate between AutoCAD and python using COM technology you have to know about the AutoCAD Object Model (ActiveX), refer to these documentation files within your AutoCAD's installation path.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;acadauto.chm: The official reference for AutoCAD's Object Model (ActiveX).&lt;/LI&gt;&lt;LI&gt;acad_aad.chm: ActiveX Developer's Guide.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 21:35:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/implementing-python-to-autocad/m-p/8254031#M123970</guid>
      <dc:creator>serag.hassouna</dc:creator>
      <dc:date>2018-09-07T21:35:52Z</dc:date>
    </item>
  </channel>
</rss>

