DXF code usage in python

DXF code usage in python

tanmayms3009
Participant Participant
951 Views
4 Replies
Message 1 of 5

DXF code usage in python

tanmayms3009
Participant
Participant

Hello,

 

I am working on the pyautocad module to automate autocad tasks using python as a substitute to LISP/VBA. But while using commands which need the dxf group codes I am facing problems.

 

e.g. https://help.autodesk.com/view/ACD/2017/ESP/?guid=GUID-EF0393EC-8446-4989-8C72-F3AE49D81176

 

As given in the link above, we have to use DXF codes as XDataType. But when I try using the same with python, It's not working. The code is given below:

"

from pyautocad import Autocad, APoint, aDouble

acad = Autocad(create_if_not_exists=True)

#Create Object
p = acad.model.AddPoint(APoint(100, 100, 0))
#Add dictionary to an object
p_dict = p.GetExtensionDictionary()
#Check if the dictionary has been assigned to the object
print(p.HasExtensionDictionary)
#Add X Record in the dictionary
p_xrecord = p_dict.AddXRecord("Object1")
print(p_xrecord) #XRecord
#Add Data into XRecord
print(p_xrecord.Name)
p_xrecord.SetXRecordData(102, "Hello")

"

I would like to know the possible solutions to this.

0 Likes
952 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

Hi,

The SetXrecordData method needs two arrays as arguments (data_type and data_value).

The 102 code group is only used for curly braces ("{" and "}") for grouping data.

You should try something like this (not tested, I do not use Python for AutoCAD customization)

data_type = [1]
data_value = ["Hello"]
p_xrecord.SetXRecordData(data_type, data_value)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5

tanmayms3009
Participant
Participant

Thanks a lot for your response @_gile.

 

I have tried passing arrays as input to that command previously, but it did not work.

Even the VBA/LISP documentation on the official AutoCAD page shows that we need to pass arrays. But it isn't working with python. I hope there is some way to perform this task.

0 Likes
Message 5 of 5

tanmayms3009
Participant
Participant

Thanks a lot for the reply @hosneyalaa . I'll try using dynamo too.