0

I'm trying to get XRecords' data [DXF group codes + values] in a python script with the help of the VBA macro and the python function provided in this answer.

In python, I get the handle of the XRecord using the Handle property, however, not all XRecords does return successfully their data, and an Unknown handle error is thrown at the line Set myXRecord = mydoc.HandleToObject(handler) at the VBA macro.

I've looked for an explanation, one of them is this one, but my case is different in that it takes the XRecord's handle at first then supply it, so, no assumptions are made on how handles are created at the AutoCAD drawing.

So, how can an XRecord return its handle, then HandleToObject method can't find that XRecord from its Handle property's value?!

Edit:-

I guess the problem is with HandleToObject itself, I get python to preview the handle which invokes the error (say "3E7") then I open the drawing and get the XRecord's data from the ordinary entget preview using (entget (handent "3E7")) in AutoCAD's command line, and the result is successful.

((-1 . <Entity name: 7ff649f06e70>) (0 . "XRECORD") (5 . "3E7") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ff649f06e20>) (102 . "}") (330 . <Entity name: 7ff649f06e20>) (100 . "AcDbXrecord") (280 . 1) (1 . "Wall1"))

Can there be any workaround to this issue?!!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0

NOTE: THIS IS NOT A SOLUTION, IT'S ANOTHER WAY TO REFERENCE XRECORDS

I've replaced dealing with object's handle to object's object ID, then I've taken a copy of the vba macro, renamed the copied macro to "getfromid", taken a copy of XRecord_return, renamed the copy to XRecord_return_1, then made minor changes as following:-

At the vba macro getfromid

1- Go to line Set myXRecord = mydoc.HandleToObject(handler) and replace HandleToObject with ObjectIDToObject

2- Change Dim name2 As String to Dim name2 As String, handler As LongPtr

At the python function XRecord_return_1

1- Change the line xl.Application.Run("facilitator.xlsm!mod_facilitate.getxrecord") to xl.Application.Run("facilitator.xlsm!mod_facilitate.getfromid")


This should avoid the source of Unknown handle error.

Community
  • 1
  • 1