Three point plane with points in different sketches

Three point plane with points in different sketches

daniel.ashbrook
Contributor Contributor
700 Views
2 Replies
Message 1 of 3

Three point plane with points in different sketches

daniel.ashbrook
Contributor
Contributor

I'm trying to programmatically create a 3-point construction plane, using points that are in three different sketches. Doing it manually in Fusion works fine, but via the API I get an InternalValidationError. Here's some sample non-working code:

 

import adsk.core, adsk.fusion

def run(context):
	ui = None
	try:
		app        = adsk.core.Application.get()
		design     = app.activeProduct
		rootComp   = design.rootComponent
		sketches   = rootComp.sketches
		planes     = rootComp.constructionPlanes
		planeInput = planes.createInput()

		#Convenience functions
		planeXY    = rootComp.xYConstructionPlane
		realVal    = adsk.core.ValueInput.createByReal
		point3D    = adsk.core.Point3D.create

		#Point 1
		sketch = sketches.add(rootComp.xYConstructionPlane)
		sp = sketch.sketchPoints
		sp1 = sp.add(point3D(1, 1, 0))

		#Point 2
		planeInput.setByOffset(planeXY, realVal(1))
		plane = planes.add(planeInput)
		sketch = sketches.add(plane)
		sp = sketch.sketchPoints
		sp2 = sp.add(point3D(1.25, 1.25, 0))

		#Point 3
		planeInput.setByOffset(planeXY, realVal(2))
		plane = planes.add(planeInput)
		sketch = sketches.add(plane)
		sp = sketch.sketchPoints
		sp3 = sp.add(point3D(1.5, 1.5, 0))

		planeInput.setByThreePoints(sp1, sp2, sp3)
		plane = planes.add(planeInput)

	except:
		if ui:
			ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
		else:
			raise

If I change the code so that sp2 and sp3 are defined instead as:

 

		sketch = sketches.add(rootComp.xYConstructionPlane)
		sp = sketch.sketchPoints
		sp1 = sp.add(point3D(1, 1, 0))
		sp2 = sp.add(point3D(1, 1, 1))
		sp3 = sp.add(point3D(1.5, 1.5, 2))

it works without the InternalValidationError.

 

 

0 Likes
Accepted solutions (1)
701 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

I tried running your example and also see the failure.  However, when I try to manually create a plane through the three points created by the program, it also fails and tells me it failed because the three points are collinear do they don't define a plane.  I changed your line:

 

sp3 = sp.add(point3D(1.5, 1.5, 0))

to:

 

sp3 = sp.add(point3D(2.0, 1.5, 0))

so that the points are no longer collinear and and now it works.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 3

daniel.ashbrook
Contributor
Contributor

Ah, I see that collinearity is in fact the problem, along with the error message. Any way to get the API to report a useful message like "These points are co-linear" rather than "InternalValidationError"?