Sample along sketch

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
browntoastjam
Posts: 37
Joined: Fri Aug 20, 2021 9:51 pm

Sample along sketch

Post by browntoastjam »

Hello All,

I want to place equally-spaced vias in kicad at the edge of the board. The edge of the board is a sketch exported from FreeCAD as a dxf file.

Given a closed sketch, how do I 2-d offset this curve, and from this offset curve equally sample x points and export them to csv/[any text] (to be read by KiCAD scripting)

To illustrate the problem in the trivial case for a line joining [-5,0] and [5,0], I would export this array:

Code: Select all

numberofvias=10
np.linspace(-5,5,num=numberofvias)
I just don't know how to get the equivalent for any closed loop.

Code: Select all

OS: Ubuntu 20.04.4 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.
Build type: Release
Branch: unknown
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.2
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4 0.12.0
  * fasteners 0.3.44
  * sheetmetal 0.2.49
  * Defeaturing
  * Lithophane
  * Curves 0.4.4
  * Behave-Dark-Colors 0.0.1
  * Assembly3 0.11.3
  * kicadStepUpMod 10.13.0
  * PieMenu
  * ProDarkThemePreferencePack 1.0.0
What I got so far:

Code: Select all

doc = App.getDocument("samplesketch")

orignalsketch=doc.getObjectsByLabel("Outline")

doc.addObject("Part::Offset2D","Offset2D")
doc.Offset2D.Source = orignalsketch[0]
doc.Offset2D.Value = -1
doc.recompute()


noofvias=100
doc.OfsetCurve.shape.discretize(Number=noofvias) # Throws an error here


References:
[1]: https://forum.freecadweb.org/viewtopic. ... ch#p234937
[2]: https://forum.freecadweb.org/viewtopic.php?t=7316
Attachments
samplesketch.FCStd
(4.55 KiB) Downloaded 7 times
edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Sample along sketch

Post by edwilliams16 »

Code: Select all

wire = doc.getObject("Offset2D").Shape.Wires[0]
points = wire.discretize(Number=noofvias)
or maybe

Code: Select all

edges = doc.getObject("Offset2D").Shape.Edges
points = [edge.discretize(Number = noofvias) for edge in edges]
if you want to discretize each edge
Post Reply