dwg = ezdxf.new('R2010') msp = dwg.modelspace() # include-start ucs = UCS(origin=(0, 2, 2), ux=(1, 0, 0), uz=(0, 1, 1)) msp.add_arc( center=ucs.to_ocs((0, 0)), radius=1, start_angle=ucs.to_ocs_angle_deg(45), # shortcut end_angle=ucs.to_ocs_angle_deg(270), # shortcut dxfattribs={ 'extrusion': ucs.uz, 'color': 2, }) center = ucs.to_wcs((0, 0)) msp.add_line( start=center, end=ucs.to_wcs(Vector.from_deg_angle(45)), dxfattribs={'color': 2}, ) msp.add_line( start=center, end=ucs.to_wcs(Vector.from_deg_angle(270)), dxfattribs={'color': 2}, ) # include-end ucs.render_axis(msp) dwg.saveas('ocs_arc.dxf')
# License: MIT License # include-start import ezdxf from ezdxf.algebra import UCS, Vector dwg = ezdxf.new('R2010') msp = dwg.modelspace() # thickness for text works only with shx fonts not with true type fonts dwg.styles.new('TXT', dxfattribs={'font': 'romans.shx'}) ucs = UCS(origin=(0, 2, 2), ux=(1, 0, 0), uz=(0, 1, 1)) # calculation of text direction as angle in OCS: # convert text rotation in degree into a vector in UCS text_direction = Vector.from_deg_angle(-45) # transform vector into OCS and get angle of vector in xy-plane rotation = ucs.to_ocs(text_direction).angle_deg text = msp.add_text( text="TEXT", dxfattribs={ # text rotation angle in degrees in OCS 'rotation': rotation, 'extrusion': ucs.uz, 'thickness': .333, 'color': 2, 'style': 'TXT', }) # set text position in OCS text.set_pos(ucs.to_ocs((0, 0, 0)), align='MIDDLE_CENTER')
import ezdxf from ezdxf.algebra import Vector, UCS dwg = ezdxf.new('R2010') msp = dwg.modelspace() # center point of the pentagon should be (0, 2, 2), and the shape is # rotated around x-axis about 45 degree, to accomplish this I use an # UCS with z-axis (0, 1, 1) and an x-axis parallel to WCS x-axis. ucs = UCS( origin=(0, 2, 2), # center of pentagon ux=(1, 0, 0), # x-axis parallel to WCS x-axis uz=(0, 1, 1), # z-axis ) # calculating corner points in local (UCS) coordinates points = [Vector.from_deg_angle((360 / 5) * n) for n in range(5)] # converting UCS into OCS coordinates ocs_points = list(ucs.points_to_ocs(points)) # LWPOLYLINE accepts only 2D points and has an separated DXF attribute elevation. # All points have the same z-axis (elevation) in OCS! elevation = ocs_points[0].z msp.add_lwpolyline( # LWPOLYLINE point format: (x, y, [start_width, [end_width, [bulge]]]) # the z-axis would be start_width, so remove it points=[p[:2] for p in ocs_points], dxfattribs={ 'elevation': elevation, 'extrusion': ucs.uz, 'closed': True,