- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
For a rectangular, planar face from corner-to-corner, 0,0,0 to 10,10,0, a point at 5,5,0 can round-trip through the nativeObject face's SurfaceEvaluator like so:
Point3D to project: (5.0, 5.0, 0.0)
getParameterAtPoint: (0.0, 0.0)
isParameterOnFace: True
getPointAtParameter: (5.0, 5.0, 0.0)
On the other hand, for an occurrence of the component that contains the face that is translated 10 in +X, a round-trip attempt starting at 15,0,0 fails:
Point3D to project: (15.0, 5.0, 0.0)
getParameterAtPoint: (20.0, 0.0)
isParameterOnFace: False
getPointAtParameter: (35.0, 5.0, 0.0) (This reflects double the aforementioned transformation.)
The 15,0,0 point is returned when the starting point is -5,5,0, even though no negative values were used in the creation of the patch nor the transformation of the component:
Point3D to project: (-5.0, 5.0, 0.0)
getParameterAtPoint: (0.0, 0.0)
isParameterOnFace: True
getPointAtParameter: (15.0, 5.0, 0.0)
It is as if getParameterAtPoint is using a proxy of the face that has been transformed from the nativeObject to the inverse of the occurrence's transform.
Does anyone know what is going on here?
import adsk.core as ac
import adsk.fusion as af
import traceback
app: ac.Application = ac.Application.get()
ui: ac.UserInterface = app.userInterface
def addComponent():
matrix = ac.Matrix3D.create()
matrix.translation = ac.Vector3D.create(10,0,0)
des:af.Design = app.activeProduct
root = des.rootComponent
return root.occurrences.addNewComponent(matrix)
def createAndAddPatch(occ: af.Occurrence):
comp:af.Component = occ.component
sketch: af.Sketch = comp.sketches.add(comp.xYConstructionPlane)
sketch.sketchCurves.sketchLines.addTwoPointRectangle(
ac.Point3D.create(0,0,0), ac.Point3D.create(10,10,0)
)
profile = sketch.profiles.item(0)
patchFeatures = comp.features.patchFeatures
patchInput = patchFeatures.createInput(
profile,
af.FeatureOperations.NewBodyFeatureOperation)
patchFeatures.add(patchInput)
return patchFeatures.item(0)
def printPerSrfEval(face: af.BRepFace, pt_ToProj: ac.Point3D):
app.log('-'*40)
srfEval = face.evaluator
app.log(f"Point3D to project: {pt_ToProj.asArray()}")
bSuccess, uv = srfEval.getParameterAtPoint(pt_ToProj)
if not bSuccess:
app.log("getParameterAtPoint failed.")
return
app.log(f"getParameterAtPoint: {uv.asArray()}")
app.log(f"isParameterOnFace: {srfEval.isParameterOnFace(uv)}")
bSuccess, pt_FromParam = srfEval.getPointAtParameter(uv)
if not bSuccess:
app.log("getPointAtParameter failed.")
return
app.log(f"getPointAtParameter: {pt_FromParam.asArray()}")
def main():
occ = addComponent()
patch = createAndAddPatch(occ)
pts = [
ac.Point3D.create(5,5,0),
ac.Point3D.create(15,5,0),
ac.Point3D.create(-5,5,0),
]
app.log('-'*60)
face = patch.faces.item(0)
app.log("nativeObject face")
for pt in pts:
printPerSrfEval(face, pt)
app.log('-'*60)
face = face.createForAssemblyContext(occ)
app.log("Transformed occurrence face")
for pt in pts:
printPerSrfEval(face, pt)
def run(context):
try:
app.log('-'*80)
main()
except:
app.log('Failed:\n{}'.format(traceback.format_exc()))
app.log("\nEnd of script.")
Solved! Go to Solution.