Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I've posted code below. When you use intersectWithCurve on a sketch circle it only returns one point since it is just a single closed curve. I need the opposite point as well. Is there a way to accomplish this? I tried converting the circle to a nurbs curve and it returned no intersections?
Thanks in advance.
Eric
#Author-Autodesk Inc.
#Description-Demo command input examples
import adsk.core, adsk.fusion, traceback
def sketchLIntersect():
ui: adsk.core.UserInterface = adsk.core.UserInterface.cast(None)
try:
app: adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
msg: str = 'Select SketchLine'
selFiltter: str = 'SketchLines'
sel: adsk.core.Selection = selectEnt(msg, selFiltter)
if not sel:
return
ent: adsk.fusion.SketchEntity = findNearest(sel)
if not ent:
return None
return ent
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def selectEnt(
msg: str,
filtterStr: str) -> adsk.core.Selection:
try:
app = adsk.core.Application.get()
ui = app.userInterface
sel = ui.selectEntity(msg, filtterStr)
return sel
except:
return None
def findNearest(sel: adsk.core.Selection):
# -- support function --
def getSketchEntities(
sktCrvs: adsk.fusion.SketchCurves) -> list:
sktCrvGroups = [
sktCrvs.sketchArcs,
sktCrvs.sketchCircles,
sktCrvs.sketchConicCurves,
sktCrvs.sketchEllipses,
sktCrvs.sketchEllipticalArcs,
sktCrvs.sketchFittedSplines,
sktCrvs.sketchFixedSplines,
sktCrvs.sketchLines,
]
sktEnts = []
for group in sktCrvGroups:
sktEnts.extend([e for e in group])
return sktEnts
# return [[SketchEntity, Point3D],]
def getIntersectingEntities(line: adsk.fusion.SketchLine,sktEnts: list) -> list:
ray: adsk.core.InfiniteLine3D = line.worldGeometry.asInfiniteLine()
ent: adsk.fusion.SketchEntity
intersects = []
for ent in sktEnts:
geo = ent.worldGeometry
res: adsk.core.ObjectCollection = ray.intersectWithCurve(geo)
if res.count < 1:
continue
intersects.append([ent, res[0]])
return intersects
# get sketchLine, sketch
line: adsk.fusion.SketchLine = sel.entity
skt: adsk.fusion.Sketch = line.parentSketch
# get all Sketch Entities
sktEnts = getSketchEntities(skt.sketchCurves)
sktEnts.remove(line)
if len(sktEnts) < 1:
return None
# get intersection Entities & point3d
intersects = getIntersectingEntities(line, sktEnts)
if len(intersects) < 1:
return None
return intersects
intersects = sketchLIntersect()
print(intersects)
# Arc3DCurveType 1 Transient 3D arc.
# Circle3DCurveType 2 Transient 3D circle.
# Ellipse3DCurveType 3 Transient 3D ellipse.
# EllipticalArc3DCurveType 4 Transient 3D elliptical arc.
# InfiniteLine3DCurveType 5 Transient 3D infinite line.
# Line3DCurveType 0 Transient 3D line segment.
# NurbsCurve3DCurveType 6 Transient 3D NURBS curve.
Solved! Go to Solution.