Plots 2D DXF file in current axes/figure (or creates a new figure/axes if none exist).
USAGE: dxf = DXFtool('filename.dxf')
INPUT: filename of dxf file as a string (may also include path).
OUTPUT: dxf object (optional).
- supports: LINE, POINT, ARC, CIRCLE, ELLIPSE, LWPOLYLINE
- colored entities (line and hatch color)
- respects ordering of objects (back to front)
- supports bulges, open/closed polygons
- line dashing
- more entities: DIMENSION, 3D stuff.
- improve handling of splines (currently piecewise linear)
- implement line weight handling
1) Showing the possibilities
2) Using DXFplot to generate graphical legend
3) Importing and plotting CAD model from SolidWorks
Mikkel Pedersen (2021). DXFtool (https://www.mathworks.com/matlabcentral/fileexchange/66632-dxftool), MATLAB Central File Exchange. Retrieved .
Dear Zhao. You can get the vertices of most entities in a dxf file as follows: Try running example1.m. It will create an object called 'dxf', which contains all the information. The vertices of say the first polygon can be retrieved by typing 'dxf.entities(1).poly'. It will return an array with x,y coordinates. For other entities, just replace the '1' with the entity number. Good luck.
Thanks, could you provide an example to show how to use the code?I don't know how to use the code to read polygon and get vertex of the polygon by DXFtool
Thanks Himanshu. Please see the answer for Aurea94 below.
This is amazing and works so good!!! Could you please tell me how I could extract all the circles in the dxf file, thanks!
first of all, thank you for this awesome work.
I want to import a CAD file into a GUI axis. this works fine; however, I can no longer select the points on the figure (in a normal "figure" I can do that but not in a GUI axis)
could you please help me solve this issue
Thanks! My geometry contains lines, splines and arcs. Should I then use the methodology you propose and extract the X Y points of each of the entities manually?
Yes, it is in the optional output, try e.g. dxf = DXFtool('some_dxf_file'). Then the output (dxf) will be a struct containing all relevant information about all the graphical entities in the file. Depending on which entities are contained in the file, it will have fields matching that. For example, if there is only a circle in there, you will get dxf.entities(1).circle, containing Xc,Yc and R = center and radius of the circle, such that you can easily reconstruct it manually!
Is there a way to obtain XY points of the DXF for post-tratment during my program?
Very handy, but when working with polylines that contain arcs, it seems that the coordinates for the arc ends repeat (for example, XData = [1 2 3 3 4 5 . . . 51 52 53 53 54 55] and YData = [3 4 5 5 6 7 . . . 53 54 55 55 56 57], where (3,5) and (53, 55) are the ends of an arc). This makes it a little trickier to work with the XData and YData, so I've taken to exploding my polylines before exporting my file as a .dxf file to separate polylines into lines and arcs. Other than that, this is a very useful function.
I think the problem is due to your old version. Thanks for posting a solution.
I solved issue by adding:
dxf.entities(i).linetype = 'CASE_HATCH';
before switch upper(dxf.entities(i).linetype)
I have an issue with "ex1.dxf": in function plot(dxf), HATCH case don't seems works...
if switch dxf.entities(i).name case is 'HATCH' ther is a bug because switch upper(dxf.entities(i).linetype) is ... I have R2013B version.
Thank you for your work!
works pretty well
Inspired by: Read DXF File Data
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!