Skip to content
Snippets Groups Projects
Commit ada3eaf4 authored by Jingyan Ling's avatar Jingyan Ling
Browse files

upload dxf processing code

parent 865980c7
No related merge requests found
**test
\ No newline at end of file
......@@ -28,10 +28,11 @@
- Cut and etching from same `Inkscape` file
### 06/28/2019 (Fri)
##### Connection and fabrication approach confirmed !
- Confirm that copper tape has better conductivity than aluminum sheet when attaching microcontroller pins through `H-shape` cut
- Copper tape is harder to be scratched, which provides less risk of disconnection during assessmbly.
- Etching on copper type isolates connections
- Research on PCB editor
- EAGLE
- EAGLE cannot import `.pcb` file
......@@ -51,13 +52,13 @@
- Approaches:
- `A`. convert SVG/DXF file to schematic/board design of PCB. Use KiCAD or EAGLE to do autorouting.
- `A`. convert SVG/DXF file to schematic/board design of PCB. Use KiCAD or EAGLE to do auto routing.
- `B`. develop algorithm on auto routing for single layer svg/dxf file. (path finding problem)
##### Approach `A`
- Use regular shape board for PCB in KiCAD
- image processing: divide alternative shape of `paperbot` to multiple rectangles (openCv)
- Use regular shape board for PCB in EAGLE/KiCAD
- image processing: divide alternative shape of `paperbot` to multiple rectangles (openCV)
- Pull required connections and place additional header pins around edges of each rectangle
......@@ -68,15 +69,39 @@
- Schematic design helps with router to know desired connection
- Additional header pins at each side of kink mark
### 06/28/2019 (Sat)
### 06/29 & 06/30/2019 (Sat & Sun)
##### Approach `B`
- Potential needed functions of packages
- A package enable drawing through scripts on SVG/DXF file
- A package draws on DXF file through script
- A script that pulls out pins' coordinate on paper chassis
- Or a image process package (OpenCV) that reads pins' coordinate on paper chassis
- A package solves multi-node path finding problem
- Or a image process package (OpenCV) that reads pins' coordinate on paper chassis
- A package solves multi-node path finding problem*
##### Record of Research
- Python Pathfinding package:
- [pathfinding](https://pypi.org/project/pathfinding/#description)
\ No newline at end of file
- Python DXF editor:
- [ezdxf](https://pypi.org/project/ezdxf/)
- [dxfgrabber](https://pypi.org/project/dxfgrabber/)
- `Note`: able to grab simple geometry from file
- [sdxf](http://www.kellbot.com/sdxf-python-library-for-dxf/)
- Going through tutorials of `ezdxf`
- All lines on paper space`layer0`
### 07/01/2019 (Mon)
- Continue dxf processing with `'graph-silhouette.dxf'`
##### Record of tips:
- Put circuit design on a new layer of dxf drawing
- [check doc about layers here](https://ezdxf.readthedocs.io/en/latest/tutorials/layers.html)
- Use block feature to draw similar pattern
- [check doc about block here](https://ezdxf.readthedocs.io/en/latest/tutorials/blocks.html)
- Blocks are `symbol` in Inkscape. Convert `symbol` to `path`
- Edit > Clone > Unlink Clone (Shift+Alt+D), and you have a group, ungroup (Object > Ungroup, or Shift+Ctrl+G) and edit
- Convert `text` to `path`
- Path combine (Ctrl+K)
- Test fabrication with different drawing settings
- Layers can be cut separately but toggling visibility
- Set cuts with same `intensity` and `feedrate` on same layer
- Entities' layer can be changed through `Entity.dxf.layer`
\ No newline at end of file
#!/usr/bin/env python
import numpy as np
import ezdxf
import random
# class dxf_editor:
# def __init__(self,path,dxf_file):
# self.dwg=ezdxf.readfile(path+dxf_file)
# def main():
# path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
# dxf_file='graph-silhouette.dxf'
# edit=dxf_editor(path,dxf_file)
# if __name__ == '__main__':
# main()
path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
dxf_file='graph-silhouette.dxf'
dwg=ezdxf.readfile(path+dxf_file)
# iterate over all entities in model space
def print_entity(e):
print("LINE on layer: %s\n" % e.dxf.layer)
print("start point:",e.dxf.start)
print("end point:" , e.dxf.end)
print("color:", e.dxf.color)
msp = dwg.modelspace()
# for e in msp:
# if e.dxftype() == 'LINE':
# print_entity(e)
i=0
# entity query for all LINE entities in model space
for e in msp.query('LINE[color==1]'):
i+=1
print_entity(e)
print(i)
# for z in msp.query('CIRCLE'):
# print(z)
if not 'Isolation' in dwg.layers:
dwg.layers.new(name='Isolation',dxfattribs={'linetype':'DASHED','color':2})
msp.add_line((0,0),(50,50),dxfattribs={'layer':'Isolation'})
def get_random_point():
"""Creates random x, y coordinates."""
x = random.randint(-100, 100)
y = random.randint(-100, 100)
return x, y
# Create a block with the name 'FLAG'
flag = dwg.blocks.new(name='FLAG')
# Add DXF entities to the block 'FLAG'.
# The default base point (= insertion point) of the block is (0, 0).
# flag.add_polyline2d([(0, 0), (0, 5), (4, 3), (0, 3)]) # the flag as 2D polyline
flag.add_circle((0, 0), .4, dxfattribs={'color': 5}) # mark the base point with a circle
msp.add_blockref('FLAG',(40,40))
dwg.save()
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import ezdxf
import random # needed for random placing points
def get_random_point():
"""Creates random x, y coordinates."""
x = random.randint(-100, 100)
y = random.randint(-100, 100)
return x, y
# Create a new drawing in the DXF format of AutoCAD 2010
dwg = ezdxf.new('ac1024')
if not 'Isolation' in dwg.layers:
dwg.layers.new(name='Isolation',dxfattribs={'color':4})
# Create a block with the name 'FLAG'
flag = dwg.blocks.new(name='FLAG')
# Add DXF entities to the block 'FLAG'.
# The default base point (= insertion point) of the block is (0, 0).
# flag.add_polyline2d([(0, 0), (0, 5)]) # the flag as 2D polyline
flag.add_circle((0, 0), 5, dxfattribs={'color': 5}) # mark the base point with a circle
# flag.add_text("TEST").set_pos((25,280),align="MIDDLE_RIGHT")
# Get the modelspace of the drawing.
modelspace = dwg.modelspace()
# Get 50 random placing points.
placing_points = [get_random_point() for _ in range(50)]
random_scale = 0.5 + random.random() * 2.0
# Add a block reference to the block named 'FLAG' at the coordinates 'point'.
modelspace.add_blockref('FLAG', (15,290), dxfattribs={
'layer':'Isolation',
})
modelspace.add_blockref('FLAG',(8,290))
modelspace.add_text("TEST").set_pos((10,285),align="MIDDLE_RIGHT")
for e in modelspace.query('*[layer=="Isolation"]'):
pass
# Save the drawing.
dwg.saveas("testline.dxf")
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="793.700787402"
height="1122.51968504"
version="1.1"
id="svg43"
sodipodi:docname="testline.svg"
inkscape:version="0.92.4 (unknown)">
<metadata
id="metadata47">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview45"
showgrid="false"
inkscape:zoom="1.6819305"
inkscape:cx="68.223504"
inkscape:cy="1106.5586"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="g33" />
<desc
id="desc2">/home/jingyan/Documents/summer_intern_lemur/roco_electrical/testline.dxf - scale = 1.000000, origin = (0.000000, 0.000000), method = manual</desc>
<defs
id="defs29">
<marker
id="DistanceX"
orient="auto"
refX="0.0"
refY="0.0"
style="overflow:visible">
<path
d="M 3,-3 L -3,3 M 0,-5 L 0,5"
style="stroke:#000000; stroke-width:0.5"
id="path4" />
</marker>
<pattern
height="8"
id="Hatch"
patternUnits="userSpaceOnUse"
width="8"
x="0"
y="0">
<path
d="M8 4 l-4,4"
linecap="square"
stroke="#000000"
stroke-width="0.25"
id="path7" />
<path
d="M6 2 l-4,4"
linecap="square"
stroke="#000000"
stroke-width="0.25"
id="path9" />
<path
d="M4 0 l-4,4"
linecap="square"
stroke="#000000"
stroke-width="0.25"
id="path11" />
</pattern>
<symbol
id="_ArchTick">
<path
d="M -1.889764,1124.409449 L 1.889764,1120.629921"
style="stroke:#000000;fill:none;stroke-linecap: round"
id="path14" />
</symbol>
<symbol
id="*Model_Space" />
<symbol
id="*Paper_Space" />
<symbol
id="FLAG">
<path
d="M 18.897638,1122.519685 A 18.897638,18.897638 -0.000000 1 0 -18.897638,1122.519685 18.897638,18.897638 -0.000000 1 0 18.897638,1122.519685 z"
style="stroke:#0000FF;fill:none"
id="path19" />
</symbol>
<symbol
id="_Open30">
<path
d="M -3.779528,1121.506964 0.000000,1122.519685"
style="stroke:#000000;fill:none;stroke-linecap: round"
id="path22" />
<path
d="M 0.000000,1122.519685 -3.779528,1123.532406"
style="stroke:#000000;fill:none;stroke-linecap: round"
id="path24" />
<path
d="M 0.000000,1122.519685 -3.779528,1122.519685"
style="stroke:#000000;fill:none;stroke-linecap: round"
id="path26" />
</symbol>
</defs>
<g
inkscape:groupmode="layer"
inkscape:label="0"
id="g33">
<use
transform="translate(26.074335,-1096.6576)"
xlink:href="#FLAG"
id="use31"
style="stroke:#800000"
x="0"
y="0"
width="100%"
height="100%" />
</g>
<g
inkscape:groupmode="layer"
inkscape:label="View Port"
id="g35" />
<g
inkscape:groupmode="layer"
inkscape:label="Defpoints"
id="g37" />
<g
inkscape:groupmode="layer"
inkscape:label="Isolation"
id="g41">
<use
transform="translate(52.531031,-1096.6576)"
xlink:href="#FLAG"
id="use39"
style="stroke:#800000"
x="0"
y="0"
width="100%"
height="100%" />
</g>
</svg>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment