Grouping of all the entity/elements in python ezdxf

186 views
Skip to first unread message

akhil verma

unread,
Mar 22, 2021, 6:26:29 AM3/22/21
to python-ezdxf
Hello Team,

I have written below code for drawing dxf file but when I was opening the the python generated dxf file into AutoCAD I had to done grouping of all the elements. Can you please let me know what I am missing in my code so that grouping issue could be resolved. Thanks.

import ezdxf

# doc = ezdxf.new('R2010')  # create a new DXF R2010 drawing, official DXF version name: 'AC1024'
doc = ezdxf.new('R2010', setup=True)
msp = doc.modelspace()  # add new entities to the modelspace

####### Tank 1 ###########
msp.add_line((0, 0), (10, 0)) 
msp.add_line((0, 10), (0, 0))
msp.add_line((0, 10), (10, 10))
msp.add_line((10, 10), (10, 0))
msp.add_arc(
    center=(5, 10),
    radius=5.0,
    start_angle=0,
    end_angle=180,
    dxfattribs={'layer': 'arc'},
)

####### Tank 2 ###########
msp.add_line((50, 0), (60, 0)) 
msp.add_line((50, 10), (50, 0))
msp.add_line((50, 10), (60, 10))
msp.add_line((60, 10), (60, 0))
msp.add_arc(
    center=(55, 10),
    radius=5.0,
    start_angle=0,
    end_angle=180,
    dxfattribs={'layer': 'arc'},
)

##### Feed ##############
msp.add_line((-40, 5), (-35, 5)) 
msp.add_line((-40, 7), (-40, 5)) 
msp.add_line((-40, 7), (-35, 7))
msp.add_line((-35, 7), (-34, 6)) 
msp.add_line((-34, 6), (-35, 5)) 
# msp.add_line((-35, 7), (-35, 5)) 

######### Line1 ##############
msp.add_line((-34, 6), (0, 6))

######### Arrow1 #############
msp.add_line((-1, 7), (0, 6))
msp.add_line((0, 6),(-1, 5))  

######### Line2 ##############
msp.add_line((10, 5), (50, 5))
######### Arrow2 #############
msp.add_line((50-1, 6), (50, 5))
msp.add_line((50, 5),(50-1, 4))  

######### Line3 ##############
msp.add_line((5, 0), (5, -15))
msp.add_line((5, -15), (55, -15))

######### Arrow3 #############
msp.add_line((55-1, -14), (55, -15))
msp.add_line((55, -15),(55-1, -16))

######### Line4 ##############
msp.add_line((55, 0), (55, -15))

######### Arrow4 #############
msp.add_line((56, -14), (55, -15))
msp.add_line((55, -15),(54, -14))  

######### Line5 ##############
msp.add_line((60, 2), (91, 2))
######### Arrow5 #############
msp.add_line((91-1, 3), (91, 2))
msp.add_line((91, 2),(91-1, 1))

####### Dot #############
circle = msp.add_circle((55, -15), radius=0.25)
# circle.dxf.true_color = 0xFF0000
circle.dxf.color = 7
########## Text ###########

# Using a text style
msp.add_text("Feed",
             dxfattribs={
                 'style': 'LiberationSerif',
                 'height': 0.45}
             ).set_pos((-39, 4), align='CENTER')

msp.add_text("Equalization Tank_CAW",
             dxfattribs={
                 'style': 'LiberationSerif',
                 'height': 0.45}
             ).set_pos((4, 16), align='CENTER')
msp.add_text("Effluent Tank_CAW",
             dxfattribs={
                 'style': 'LiberationSerif',
                 'height': 0.45}
             ).set_pos((55, 16), align='CENTER')
msp.add_text("CO2 Stripper",
             dxfattribs={
                 'style': 'LiberationSerif',
                 'height': 0.45}
             ).set_pos((90, 4), align='CENTER')

x = -90
width = 0
height=0

#Polyline 1
polyline1_Points=[(1.61458-x, 1.46875,), 
(1.61458-x, 3.23264) ,
(1.61458-x, 3.23264) ,
(1.61719-x, 3.24046) ,
(1.62771-x, 3.26107) ,
(1.65007-x, 3.29053) ,
(1.68838-x, 3.32465) ,
(1.74647-x, 3.35949) ,
(1.82844-x, 3.39085) ,
(1.93821-x, 3.41476) ,
(2.04438-x, 3.42594),
(2.07986-x, 3.42708),
(2.07986-x, 3.42708),
(2.09782-x, 3.42649),
(2.14572-x, 3.4235),
(2.21425-x, 3.4165),
(2.29428-x, 3.40365),
(2.37651-x, 3.38336),
(2.45193-x, 3.35385),
(2.51118-x, 3.31347),
(2.54069-x, 3.27496),
(2.54514-x, 3.26042),
(2.54514-x, 1.46875),
(1.61458-x, 1.46875)]
#Polyline #1D
polyline2_Points=[(1.40625-x, 1.46875),
(2.75521-x, 1.46875),
(2.75521-x, 0.652778),
(1.40625-x, 0.652778),
(1.40625-x, 1.46875)]
#Polyline #25
polyline3_Points=[(1.61458-x, 2.68403),
(2.54514-x, 2.68403),
(2.54514-x, 2.0034),
(1.61458-x, 2.00347),
(1.61458-x, 2.68403)]
#Polyline #2D
polyline4_Points=[(1.61458-x, 2.00347),
(2.51042-x, 2.68403)]
#Polyline #32
polyline5_Points=[(1.61458-x, 2.68403),
(2.54514-x, 2.00347)]
#Polyline #37
polyline5_Points=[(1.88151-x, 3.49089),
(1.88151-x, 3.56119),
(2.29036-x, 3.56119),
(2.29036-x, 3.49089)]
#Polyline #3E
polyline6_Points=[(1.94922-x, 3.54557),
(1.94922-x, 3.41629)]
#Polyline #43
polyline7_Points=[(2.21744-x, 3.54557),
(2.21744-x, 3.41629)]
#Polyline #48
polyline8_Points=[(1.47657-x, 1.46875),
(1.47657-x, 1.97917),
(1.47657-x, 1.97917),
(1.47592-x, 1.98492),
(1.47282-x, 1.99994),
(1.46571-x, 2.02121),
(1.45281-x, 2.04557),
(1.4324-x, 2.06999),
(1.40294-x, 2.09125),
(1.36263-x, 2.10628),
(1.32308-x, 2.11199),
(1.3099-x, 2.11199),
(1.3099-x, 2.11199),
(1.30235-x, 2.1116),
(1.28244-x, 2.10938),
(1.25434-x, 2.10379),
(1.22217-x, 2.0931),
(1.18994-x, 2.0759)]

msp.add_lwpolyline(polyline1_Points)
msp.add_lwpolyline(polyline2_Points)
msp.add_lwpolyline(polyline3_Points)
msp.add_lwpolyline(polyline4_Points)
msp.add_lwpolyline(polyline5_Points)
msp.add_lwpolyline(polyline6_Points)
msp.add_lwpolyline(polyline7_Points)
msp.add_lwpolyline(polyline8_Points)

doc.saveas('test.dxf')

Manfred Moitzi

unread,
Mar 22, 2021, 6:42:44 AM3/22/21
to python-ezdxf
I don't understand your question. What do you mean by "I had to done grouping of all the elements".

akhil verma

unread,
Mar 22, 2021, 11:15:02 PM3/22/21
to python-ezdxf
I got the Solution. Sorry to disturb you. Thank you!
Reply all
Reply to author
Forward
0 new messages