1. Get fabricationlayergfxs for each component, of type epcbfabassembly, type 1
2. Get the geometries and pointsarrays of each item in the fabricationlayergfxs collections
3. create a min_distance variable, set it to some very high number
4. create a for loop that cycles through each pointsarray from the first component's fab gfxs
5. Inside that loop, make another loop that cycles through the pointsarrays of the second component's fab gfxs.
6. compute the distance from each point in the two pointsarrays in each loop.
7. If the distance is smaller than the min_distance, set min_distance to that distance
8. Keep going till the looping is all done
9. min_distance will be the minimum distance between the assembly graphics of the two components
Here is a possible function. I did not verify that it works, but it's pretty much what is needed.
Public Function get_min_assygfx_distance(comp1 As MGCPCB.Component, comp2 As MGCPCB.Component) As Double
Dim min_d, d As Double
Dim geom1, geom2 As MGCPCB.Geometry
Dim ptary1, ptary2 As Object
Dim n, i As Integer
Dim fabgfxs1, fabgfxs2 As MGCPCB.FabricationLayerGfxs
Dim fabgfx1, fabgfx2 As MGCPCB.FabricationLayerGfx
Dim x1, y1, x2, y2 As Double
fabgfxs1 = comp1.FabricationLayerGfxs(1, 0)
fabgfxs2 = comp2.FabricationLayerGfxs(1, 0)
min_d = 10000000000000000
For Each fabgfx1 In fabgfxs1
geom1 = fabgfx1.Geometry
ptary1 = geom1.PointsArray
For Each fabgfx2 In fabgfxs2
geom2 = fabgfx2.Geometry
ptary2 = geom2.PointsArray
For n = 0 To UBound(ptary1, 2)
x1 = ptary1(0, n)
y1 = ptary1(1, n)
For i = 0 To UBound(ptary2, 2)
x2 = ptary2(0, i)
y2 = ptary2(1, i)
d = get_distance(x1, y1, x2, y2)
If d < min_d Then
min_d = d
Public Function get_distance(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double
Dim x, y, r As Double
x = Math.Abs(x2 - x1)
y = Math.Abs(y2 - y1)
r = (x ^ 2 + y ^ 2) ^ 0.5
Maybe that also can help you
ident = pcbDoc.SelectedObjectIds --> puts all idents of the selected objects in an array
Set mobj1 = pcbDoc.FindObjectById(ident(0))
Set mobj2 = pcbDoc.FindObjectById(ident(1))
myactualclearance = pcbDoc.Clearance.GetActualMinClearance(mobj1, mobj2)
Thanks Patrick for quick response.
I am getting error at below mentioned line. I am getting Geometry for component 1 , but when try to find out PointsArray, it's giving error saying object required. Can you please help
Set geom1 = fabgfx1.Geometry
MsgBox(geom1.IsRect()) == > it is giving True
Set ptary1 = geom1.PointsArray==> This is failing with Error Object required.
2 of 2 people found this helpful
The PointsArray is not an object but an array (X,Y,R)
You can also use the GetActualMinClearance on the assembly gfx objects, might be a bit slower but will then also work for filled shapes and arcs:
Const IngoreLineWidths = true 'Set true to measure from centerline on the assembly Gfx (GetActualMinClearance is from edge to edge)
msgbox GetCompPackageClearance(PcbDocObj.components(epcbSelectSelected).item(1),PcbDocObj.components(epcbSelectSelected).item(2)) & "mm"
Dim MinClearance : MinClearance = -9999
for each Comp1AssyGfx in CompObj1.FabricationLayerGfxs(epcbFabAssembly,epcbSelectAll,epcbSideTopOrBottom)
For each Comp2AssyGfx in CompObj2.FabricationLayerGfxs(epcbFabAssembly,epcbSelectAll,epcbSideTopOrBottom)
Dim Clearance : Clearance = PcbdocObj.clearance.GetActualMinClearance(Comp1AssyGfx,Comp2AssyGfx,epcbUnitmm)
if IngoreLineWidths = true and Clearance <> 0 then 'option to ignore linewidths
Dim LineWidthToIgnore : LineWidthToIgnore = 0
if Comp1AssyGfx.geometry.Filled = False then 'Filled shapes have 0 linewidth
LineWidthToIgnore = LineWidthToIgnore + Comp1AssyGfx.geometry.LineWidth(epcbUnitmm)/2
if Comp2AssyGfx.geometry.Filled = False then 'Filled shapes have 0 linewidth
LineWidthToIgnore = LineWidthToIgnore + Comp2AssyGfx.geometry.LineWidth(epcbUnitmm)/2
Clearance = Clearance + LineWidthToIgnore
If MinClearance = -9999 or Clearance < MinClearance then
MinClearance = Clearance
GetCompPackageClearance = MinClearance
Thanks Matthias your solution worked.
Thanks Everyone for providing response to my query.
Very good method. I did not know you could use actualminclearance with assembly graphics.
Thank you for posting this solution.