Hi, I've written a script that, after selecting a point on the model, creates a construction plane at that point, oriented according to the viewport.
Here's how it works:
- You must be in the design environment
- Run the script
- Select the point
- Construction plane is created
import adsk.core, adsk.fusion, traceback
def run(context):
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
view = app.activeViewport
def center_view_on_point(point):
cam = view.camera
offset = adsk.core.Vector3D.create(
point.x - cam.target.x,
point.y - cam.target.y,
point.z - cam.target.z
)
new_eye = cam.eye.copy()
new_eye.translateBy(offset)
new_target = cam.target.copy()
new_target.translateBy(offset)
cam.eye = new_eye
cam.target = new_target
cam.isFitView = False
view.camera = cam
view.refresh()
def create_plane():
rootComp = design.rootComponent
camera = app.activeViewport.camera
cam_eye = camera.eye
sketches = rootComp.sketches
sketch3D = sketches.add(rootComp.xYConstructionPlane)
sketchLines = sketch3D.sketchCurves.sketchLines
vector = adsk.core.Vector3D.create(
cam_eye.x - point_of_interest.x,
cam_eye.y - point_of_interest.y,
cam_eye.z - point_of_interest.z
)
vector.normalize()
# construction plane scale
scale_factor = 10.0
vector.scaleBy(scale_factor)
transformed_point = adsk.core.Point3D.create(
point_of_interest.x + vector.x,
point_of_interest.y + vector.y,
point_of_interest.z + vector.z
)
line = sketchLines.addByTwoPoints(transformed_point, point_of_interest)
planes = rootComp.constructionPlanes
planeInput = planes.createInput()
distance = adsk.core.ValueInput.createByReal(1)
planeInput.setByDistanceOnPath(line, distance)
construction_plane = planes.add(planeInput)
construction_plane.name = "Plane from view"
sketch3D.name = "plane sketch"
sketch3D.isVisible = False
if not design:
ui.messageBox('You need to be in the design workspace')
return
ui.messageBox('Select a point on the model.')
selection = ui.selectEntity('Select a point on the model.', 'Vertices,ConstructionPoints')
if not selection:
ui.messageBox('No point was selected.')
return
selected_point = selection.entity.geometry
point_of_interest = adsk.core.Point3D.create(selected_point.x, selected_point.y, selected_point.z)
center_view_on_point(point_of_interest)
create_plane()