Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everybody,
I want to create a patch using the loop inside Fig.1 and Fig.2 according to the following flow.
①Gets all loops for each face of the target body.
②If the loop obtained in ① has an internal shape, use this loop to create a sketch.
③Create a patch using the sketch profile created in ②.
Issue: Depending on the shape of the internal loop, the sketch profile for patch creation may not be generated.
For example, [sample_a.step] is NG. [Sample_b.step] is OK.
Can you tell me how to create a patch even with the shape of [sample_a.step]?
# Assuming you have not changed the general structure of the template no modification is needed in this file.
from . import commands
from .lib import fusion360utils as futil
import adsk.core, adsk.fusion, adsk.cam, traceback
_app = None
_ui = None
_design = None
_rootComp = None
def run(context):
try:
# This will run the start function in each of your commands as defined in commands/__init__.py
commands.start()
# fusion情報を取得
global _app, _ui
_app = adsk.core.Application.get()
_ui = _app.userInterface
product = _app.activeProduct
global _design
_design = adsk.fusion.Design.cast(product)
global _rootComp
_rootComp = _design.rootComponent
allBodies = _rootComp.bRepBodies
bodycount = allBodies.count
if allBodies.count < 1:
_ui.messageBox('Body count is not exist')
return
newbody = allBodies.item(0)
# create patch
oresult = [-1]
CreatePatch(newbody, oresult)
return
except:
futil.handle_error('run')
# create patch
def CreatePatch(targetbody,
oresult):
try:
oresult[0] = -1
i = 0
j = 0
for face in targetbody.faces:
for Loop in face.loops:
if Loop.isOuter:
# if Loop is Outer
continue
# create sketch by inter loop
brepEdges = Loop.edges
skt = createsketch(brepEdges)
# can not get sketch's profile
profilecurve = skt.profiles[0]
# Create the patch feature by sketch's profile
patches = _rootComp.features.patchFeatures
patchInput = patches.createInput(profilecurve, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
patches.add(patchInput)
oresult[0] = 0
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# crate loop's sketch
def createsketch(brepEdges):
try:
oresult = -1
skt :adsk.fusion.Sketch = _rootComp.sketches.add(_rootComp.xYConstructionPlane)
skt.arePointsShown = False
edge = brepEdges.item(0)
edgegeo :adsk.core.NurbsCurve3D = None
curveType = edge.geometry.curveType
sktFits = None
if curveType == 2:
# Circle3DCurveType
sktFits :adsk.fusion.SketchFixedSplines = skt.sketchCurves.sketchFixedSplines
else:
# NurbsCurve3DCurveType
sktFits :adsk.fusion.SketchFittedSplines = skt.sketchCurves.sketchFittedSplines
for edge in brepEdges:
if curveType == 2:
# Circle3DCurveType
edgegeo = edge.geometry.asNurbsCurve
sktFits.addByNurbsCurve(edgegeo)
else:
# NurbsCurve3DCurveType
edgegeo = edge.geometry
eva :adsk.core.SurfaceEvaluator = edgegeo.evaluator
_, sPnt, ePnt = eva.getEndPoints()
_, [sPrm, ePrm] = eva.getParametersAtPoints([sPnt, ePnt])
# get Transit point
_, pnts = eva.getStrokes(sPrm, ePrm, 0.01)
pntLst = adsk.core.ObjectCollection.create()
[pntLst.add(p) for p in pnts]
sktFits.add(pntLst)
skt.name = 'test'
return skt
except:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
# Remove all of the event handlers your app has created
futil.clear_handlers()
# This will run the start function in each of your commands as defined in commands/__init__.py
commands.stop()
except:
futil.handle_error('stop')
Solved! Go to Solution.