major refactor on processing approach
instead of processing from an Assembly Link prospective, it now just pulls bodies from the first level Links in the Assembly. From those LCS points are found. Planes and sketches are created from there
This commit is contained in:
parent
99799697b9
commit
6b1f8f0074
1 changed files with 63 additions and 34 deletions
|
@ -18,7 +18,7 @@ class FlatpackGroupViewProvider():
|
||||||
self.Proxy = group
|
self.Proxy = group
|
||||||
|
|
||||||
class FlatpackWBTools():
|
class FlatpackWBTools():
|
||||||
def createDatumPlaneOnLink(self, part, link):
|
def createDatumPlaneOnLink(self, part):
|
||||||
plane = part.newObject('PartDesign::Plane', 'DatumPlane')
|
plane = part.newObject('PartDesign::Plane', 'DatumPlane')
|
||||||
|
|
||||||
return plane
|
return plane
|
||||||
|
@ -33,48 +33,69 @@ class FlatpackWBTools():
|
||||||
|
|
||||||
self.links = self.findLinks(asm)
|
self.links = self.findLinks(asm)
|
||||||
|
|
||||||
|
assembly_bodies = []
|
||||||
|
|
||||||
for link in self.links:
|
for link in self.links:
|
||||||
attached_to = ad.getObject(link.AttachedTo.split('#')[1])
|
if link.LinkedObject not in assembly_bodies:
|
||||||
|
assembly_bodies.append(link.LinkedObject)
|
||||||
# not much to do when attached to the root
|
|
||||||
if attached_to.Name == 'LCS_Origin':
|
|
||||||
print('Skipping LCS_Origin')
|
|
||||||
continue
|
|
||||||
|
|
||||||
print(link.Name, link.Placement)
|
continue
|
||||||
|
|
||||||
# find all the App::Links that are on the same Plane as this one
|
for body in assembly_bodies:
|
||||||
coplaner_links = []
|
sketch_planes = {}
|
||||||
for i in [ l for l in link.OutList if l.TypeId == 'PartDesign::CoordinateSystem' ]:
|
sketch_pockets = {}
|
||||||
if l not in coplaner_links and abs(link.Placement.Base.z - l.Placement.Base.z) < 0.000001:
|
sketch_pads = {}
|
||||||
print(link.Label, l.Label, abs(link.Placement.Base.z- l.Placement.Base.z), link.Placement.Base.z==l.Placement.Base.z)
|
|
||||||
coplaner_links.append(l)
|
|
||||||
|
|
||||||
print('coplaner_links', coplaner_links)
|
for lcs in self.findLCS(body.OutList):
|
||||||
for cp_link in coplaner_links:
|
base = lcs.Placement.Base
|
||||||
base = cp_link.Placement.Base
|
z = base.z
|
||||||
|
|
||||||
# create DatumPlane for Sketch Support
|
if sketch_planes.get(z) is None:
|
||||||
# TODO track planes per Z offset
|
# create new plane to hold sketch
|
||||||
plane = self.createDatumPlaneOnLink(link.LinkedObject, link)
|
plane = self.createDatumPlaneOnLink(body)
|
||||||
plane.Visibility = False
|
plane.Visibility = False
|
||||||
plane.Placement.Base.z = base.z
|
plane.Placement.Base.z = z
|
||||||
|
|
||||||
# create Sketch for drawing attachment features
|
sketch_planes[z] = plane
|
||||||
sketch = self.createSketch(link.LinkedObject, plane)
|
else:
|
||||||
sketch.Visibility = False
|
plane = sketch_planes[z]
|
||||||
|
|
||||||
# TODO needs input parameters from 1) the Flatpack object 2) the depth of the LinkedObject
|
bb = body.Shape.BoundBox
|
||||||
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y, 0), App.Vector(base.x+10, base.y, 0)), False)
|
if self.insideBB(bb, lcs.Placement.Base):
|
||||||
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y, 0), App.Vector(base.x+10, base.y + 5, 0)), False)
|
sketch_book = sketch_pockets
|
||||||
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y + 5, 0), App.Vector(base.x-10, base.y + 5, 0)), False)
|
sketch_label = 'Inside'
|
||||||
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y + 5, 0), App.Vector(base.x-10, base.y, 0)), False)
|
else:
|
||||||
|
sketch_book = sketch_pads
|
||||||
# TODO determine if Feature should be Pad or Pocket, based on inside/outside of BoundingBox
|
sketch_label = 'Outside'
|
||||||
|
|
||||||
|
if sketch_book.get(z) is None:
|
||||||
|
sketch = self.createSketch(body, plane)
|
||||||
|
sketch.Visibility = False
|
||||||
|
sketch.Label = sketch_label
|
||||||
|
sketch_book[z] = sketch
|
||||||
|
else:
|
||||||
|
sketch = sketch_book[z]
|
||||||
|
|
||||||
|
tab_length = abs(bb.ZMin) + bb.ZMax
|
||||||
|
|
||||||
|
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y - (tab_length / 2), 0), App.Vector(base.x+10, base.y - (tab_length / 2), 0)), False)
|
||||||
|
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y - (tab_length / 2), 0), App.Vector(base.x+10, base.y + tab_length / 2, 0)), False)
|
||||||
|
sketch.addGeometry(Part.LineSegment(App.Vector(base.x+10, base.y + tab_length / 2, 0), App.Vector(base.x-10, base.y + tab_length / 2, 0)), False)
|
||||||
|
sketch.addGeometry(Part.LineSegment(App.Vector(base.x-10, base.y + tab_length / 2, 0), App.Vector(base.x-10, base.y - (tab_length / 2), 0)), False)
|
||||||
|
|
||||||
|
for z in sketch_pads:
|
||||||
|
sketch = sketch_pads[z]
|
||||||
pad = link.LinkedObject.newObject('PartDesign::Pad', 'Pad')
|
pad = link.LinkedObject.newObject('PartDesign::Pad', 'Pad')
|
||||||
pad.Profile = sketch
|
pad.Profile = sketch
|
||||||
# TODO get value from elsewhere
|
pad.Length = tab_length
|
||||||
pad.Length = 10
|
pad.Midplane = 1
|
||||||
|
pad.Refine = 1
|
||||||
|
|
||||||
|
for z in sketch_pockets:
|
||||||
|
sketch = sketch_pockets[z]
|
||||||
|
pad = link.LinkedObject.newObject('PartDesign::Pocket', 'Pocket')
|
||||||
|
pad.Profile = sketch
|
||||||
|
pad.Length = tab_length
|
||||||
pad.Midplane = 1
|
pad.Midplane = 1
|
||||||
pad.Refine = 1
|
pad.Refine = 1
|
||||||
|
|
||||||
|
@ -99,16 +120,24 @@ class FlatpackWBTools():
|
||||||
def findLinks(self, asm, discard_origin = False):
|
def findLinks(self, asm, discard_origin = False):
|
||||||
return [] if not asm else [el for el in asm.OutList if el.TypeId == 'App::Link']
|
return [] if not asm else [el for el in asm.OutList if el.TypeId == 'App::Link']
|
||||||
|
|
||||||
|
def findLCS(self, obj_list):
|
||||||
|
return [ l for l in obj_list if l.TypeId == 'PartDesign::CoordinateSystem' ]
|
||||||
|
|
||||||
def getLinkOwner(self, link):
|
def getLinkOwner(self, link):
|
||||||
return link.LinkedObject
|
return link.LinkedObject
|
||||||
|
|
||||||
|
def insideBB(self, bb, p):
|
||||||
|
return (p.x > bb.XMin and p.x < bb.XMax) and (p.y > bb.YMin and p.y < bb.YMax) and (p.z > bb.ZMin and p.z < bb.ZMax)
|
||||||
|
|
||||||
FP = App.Flatpack = FlatpackWBTools()
|
FP = App.Flatpack = FlatpackWBTools()
|
||||||
asm = Gui.ActiveDocument.Document.getObject('Model')
|
asm = Gui.ActiveDocument.Document.getObject('Model')
|
||||||
|
|
||||||
asm = FP.findAssembly()
|
asm = FP.findAssembly()
|
||||||
|
|
||||||
if asm:
|
if asm:
|
||||||
|
ad.openTransaction('flatpack')
|
||||||
FP.createGroup(asm)
|
FP.createGroup(asm)
|
||||||
|
ad.commitTransaction()
|
||||||
else:
|
else:
|
||||||
print('No Assembly selected.')
|
print('No Assembly selected.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue