@ferdlhons -San.
I have created a script to create a sketch of the FaceGroup boundary.
Note that this is a very slow process.
# Fusion360API Python script
import traceback
import adsk
import adsk.core as core
import adsk.fusion as fusion
import math
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
des: fusion.Design = app.activeProduct
des.designType = fusion.DesignTypes.ParametricDesignType
# select mesh
msg: str = "Select MeshBody"
selFilter: str = "MeshBodies"
sel: core.Selection = select_ent(msg, selFilter)
if not sel: return
baseMesh: fusion.MeshBody = sel.entity
# face group
exec_mesh_calculate_faceGroups_Command(baseMesh, 5.0, 0.1)
# mesh extract
meshes = exec_mesh_extract(baseMesh)
# mesh to brep
breps = meshes_to_brepBodies(meshes)
# open edges
openEdgesLst = get_open_edges_by_bodies(breps)
# draw edges - sketch
comp: fusion.Component = baseMesh.parentComponent
draw_edges_by_edgesList(comp, openEdgesLst)
# remove
[x.deleteMe() for x in meshes]
breps[0].deleteMe()
baseMesh.isLightBulbOn = True
ui.messageBox("Done")
except:
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
def draw_edges_by_edgesList(
comp: fusion.Component,
edgesLst: list[list[fusion.BRepEdge]],
) -> list[fusion.Sketch]:
sktLst = []
for edges in edgesLst:
sktLst.append(
draw_edges(comp, edges)
)
adsk.doEvents()
return sktLst
def draw_edges(
comp: fusion.Component,
edges: list[fusion.BRepEdge],
) -> fusion.Sketch:
if len(edges) < 1: return
skt: fusion.Sketch = comp.sketches.add(
comp.xYConstructionPlane
)
skt.name = "Mesh Group Open Edge"
objs: core.ObjectCollection = core.ObjectCollection.createWithArray(
edges
)
for x in edges:
if not x.classType() == fusion.SketchLine.classType():
print("K")
else:
print("V")
skt.isComputeDeferred = True
skt.include(objs)
skt.isComputeDeferred = False
skt.isComputeDeferred = True
for crv in skt.sketchCurves:
crv.isReference = False
crv.isFixed = True
skt.isComputeDeferred = False
def get_open_edges_by_bodies(
bodies: list[fusion.BRepBody],
) -> list[list[fusion.BRepEdge]]:
openEdgesLst = []
for body in bodies:
openEdgesLst.append(
[e for e in body.edges if e.coEdges.count < 2]
)
return openEdgesLst
def meshes_to_brepBodies(
meshes: list[fusion.MeshBody],
) -> list[fusion.BRepBody]:
if not meshes: return
if len(meshes) < 1: return
app: core.Application = core.Application.get()
comp: fusion.Component = meshes[0].parentComponent
beforeLst = list(comp.bRepBodies)
sels: core.Selections = app.userInterface.activeSelections
sels.clear()
[sels.add(m) for m in meshes]
cmds = [
u"Commands.Start ParaMeshConvertCommand",
u"Commands.SetString ConvertMeshInfoOperation {}".format(
"infoOperationNewBaseFeature"
),
u"Commands.SetString MeshToBREPAlgorithmInput {}".format(
"infoMethodTriangleBased"
),
u"NuCommands.CommitCmd",
]
[app.executeTextCommand(cmd) for cmd in cmds]
return [m for m in comp.bRepBodies if not m in beforeLst]
def exec_mesh_extract(
mesh: fusion.MeshBody,
) -> list[fusion.MeshBody]:
if not mesh: return
app: core.Application = core.Application.get()
comp: fusion.Component = mesh.parentComponent
beforeLst = list(comp.meshBodies)
sels: core.Selections = app.userInterface.activeSelections
sels.clear()
sels.add(mesh)
cmds = [
u"Commands.Start ParaMeshExtractCommand",
u"Commands.SetString infoType {}".format(
"infoTypeAllFaceGroups"
),
u"Commands.SetBool infoPreserveSourceBody 1",
u"NuCommands.CommitCmd",
]
[app.executeTextCommand(cmd) for cmd in cmds]
return [m for m in comp.meshBodies if not m in beforeLst]
def exec_mesh_calculate_faceGroups_Command(
mesh: fusion.MeshBody,
infoOpeningAngle: float = 25.0,
infoFastSegmentArea: float = 0.2,
):
app: core.Application = core.Application.get()
sels: core.Selections = app.userInterface.activeSelections
sels.clear()
sels.add(mesh)
cmds = [
u"Commands.Start ParaMeshCalculateFaceGroupsCommand",
u"Commands.SetString infoSegmentationMethod {}".format(
"infoSegmentationMethodFast"
),
u"Commands.SetDouble infoOpeningAngle {}".format(
math.radians(infoOpeningAngle)
),
u"Commands.SetDouble infoFastSegmentArea {}".format(
infoFastSegmentArea
),
u"NuCommands.CommitCmd",
]
[app.executeTextCommand(cmd) for cmd in cmds]
def select_ent(
msg: str,
filter: str
) -> core.Selection:
try:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
sel = ui.selectEntity(msg, filter)
return sel
except:
return None
