title: "exception: access violation writing" error in Python (ctypes)
body: <p>I've been learning python (2.7) for a couple of weeks to be able to automatise autocad, so, be patient I'm python noob.</p>
  
  <p>I'm trying to get the attributes of a newely created block to modify them, the <a href="http://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-ActiveX/files/GUID-3E8E1756-F45D-4CCE-838B-00FBC0374278-htm.html" rel="nofollow noreferrer">doc</a> says that in VBA it would be: </p>
  
  <pre><code>Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "TESTBLOCK", 1#, 1#, 1#, 0)
  varAttributes = blockRefObj.GetAttributes
  For I = LBound(varAttributes) To UBound(varAttributes)
      strAttributes = strAttributes &amp; vbLf &amp; "  Tag: " &amp; varAttributes(I).TagString &amp; _
          vbLf &amp; "  Value: " &amp; varAttributes(I).TextString &amp; vbLf &amp; "    "
  </code></pre>
  
  <p>I've been translating several snippets of VBA code to Python code and it worked every time, but for this one, I'm trying:</p>
  
  <pre><code>acad = comtypes.client.GetActiveObject("AutoCAD.Application")
  doc = acad.ActiveDocument
  ms = doc.ModelSpace
  myBlock = ms.InsertBlock(array.array('d', [0, 0, 0]), 'TESTBLOCK', 1, 1, 1, 0)
  varAttributes = myBlock.getAttributes()
  for i in varAttributes:
      print i
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Ab******/test3/abtro2.py", line 84, in &lt;module&gt;
      add_PB(pt[0], pt[1], PB, int(ELR), PB_type, type_PEO, int(sorties), PB_addr[float(re.sub('PB', '', PB))])
    File "C:/Ab******/test3/abtro2.py", line 33, in add_PB
      varAttributes = myPB_Block.getAttributes()
    File "C:\Python27\lib\site-packages\comtypes\automation.py", line 506, in __ctypes_from_outparam__
      result = self.value
    File "C:\Python27\lib\site-packages\comtypes\automation.py", line 457, in _get_value
      typ = _vartype_to_ctype[self.vt &amp; ~VT_ARRAY]
  KeyError: 9
  Exception WindowsError: 'exception: access violation writing 0x005608A4' in  ignored
  </code></pre>
  
  <p>From what I read from the VBA snippet, <code>getAttributes</code> method must return an array, so my question is twofold:</p>
  
  <ol>
  <li><strike>Is using <code>.getAttributes</code> and <code>.getAttributes()</code> the same thing in python?</strike> <strong>noob question</strong></li>
  <li>Why the ActiveX method used in Python does not give the same result (an array) as in VBA?</li>
  </ol>
  
  <p><strong>EDIT</strong>
  From <a href="https://stackoverflow.com/questions/1382076/windowserror-exception-access-violation-ctypes-question">here</a> I understand that perhaps Python is:</p>
  
  <blockquote>
    <p>performing illegal operations (the kind of operations that if went
    unchecked would probably crash your system).</p>
  </blockquote>
  
  <p>From the doc, the kind of array returned is:</p>
  
  <blockquote>
    <p>Type: Variant (array of AttributeReference objects)</p>
  </blockquote>
  
  <p>So, perhaps it's because it's not a simple array, but an array of objects that is returned, does somebody knows how to circumvent this?</p>