The following code is a snippet of my add-in, Basically, it will create a ConstructionPlane based on a Plane. However, it failed at sketch = sketches.add(cons_plane).After debugging, I found constructionPlanes.add returns nothing, that is why sketches.add failed.
import adsk.core, adsk.fusion, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface product = app.activeProduct rootComp = product.rootComponent pt_3d_1 = adsk.core.Point3D.create(0,0,0) normal = adsk.core.Vector3D.create(0,0,1) plane = adsk.core.Plane.create(pt_3d_1,normal) print(plane.normal.x,plane.normal.y,plane.normal.z) cons_planes = rootComp.constructionPlanes print(cons_planes.count) cons_planeInput = cons_planes.createInput() cons_planeInput.setByPlane(plane) cons_plane = cons_planes.add(cons_planeInput) #watch cons_plane. it is none. sketches = rootComp.sketches #throw exception because cons_plane is none sketch = sketches.add(cons_plane) #can work if using default plane #xyPlane = rootComp.xYConstructionPlane #sketch = sketches.add(xyPlane) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
When we create a construction plane in [non-Parametric Modeling], it has no relationship to anything else and is positioned in space. We can use the Move command to reposition it anywhere in the model. When working in [Parametric Modeling], the construction plane remembers the input geometry and is tied to it. If that geometry changes, the construction plane will be recomputed. It’s not possible to create a construction plane that has not relationship to anything. The exception to this is because I create a construction plane and then delete whatever it’s dependent on. But then it just becomes sick and the only option is to redefine it which means I need to re-associate it to some other geometry. Finally, I got know the root reason. It is an as design behavior in [Parametric Modeling]. Fusion 360 provides two types of modeling: [Parametric Modeling] and [non-Parametric Modeling]. The former is also called modeling with history, while the latter is called direct modeling.
Construction planes are real entities, while Plane object is transient, which just provides the mathematical definition of a plane.
So in [non-Parametric Modeling], the code will work well.
In default, the modeling mode follows the setting in Preference
If you want to switch the modeling mode in the middle way, you can right click the root node and click the last menu item.