- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create a script through python API that allows a user to select the bottom left vertex of "body 1" then the bottom right vertex of "body 2". The script will then generate a 3d spline between these vertices. The script should then add a tangent relationship between the edge adjacent to the bottom right vertex of "body 2" as seen in the screenshot attached. Creating this tangent relationship is causing difficulties. If anyone has some tips about how to achieve this that would be great. Thanks in advance.
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
root = design.rootComponent
#####################################Create the 3d spline sketch#####################################
#use select bottom left vertex of right body
VertexSel1 = ui.selectEntity('Select bottom left vertex of right body', 'Vertices ')
if VertexSel1:
vertex1 = VertexSel1.entity
BNMR1coord = vertex1.geometry
#User select bottom right vertex of left body
VertexSel5 = ui.selectEntity('Select bottom right vertex of left body', 'Vertices ')
if VertexSel5:
vertex5 = VertexSel5.entity
BNMR5coord = vertex5.geometry
#Initialize the active sketch for BNMR
sketches = root.sketches
sketchBNMR = sketches.add(root.xYConstructionPlane)
sketchBNMR.name = 'Bottom Sketch'
#create needed variables
BNMRheight = BNMR5coord.y - BNMR1coord.y
BNMRdepth = BNMR5coord.z - BNMR1coord.z
BNMRwidth = BNMR5coord.x - BNMR1coord.x
#Find all of the z values of the middle coordinates
BNMR2_z = BNMR1coord.z + 0.23*BNMRdepth
BNMR3_z = BNMR1coord.z + 0.57*BNMRdepth
BNMR4_z = BNMR1coord.z + 0.82*BNMRdepth
#find all of the x values of the middle coordinates
BNMR2_x = BNMR5coord.x - 0.69*BNMRwidth
BNMR3_x = BNMR5coord.x - 0.45*BNMRwidth
BNMR4_x = BNMR5coord.x - 0.21*BNMRwidth
#find all of the y values of the middle coordinates
BNMR2_y = BNMR1coord.y + 0.28*BNMRheight
BNMR3_y = BNMR1coord.y + 0.75*BNMRheight
BNMR4_y = BNMR1coord.y + 0.92*BNMRheight
#List the points that will be used to create the spline
BNMR1 = adsk.core.Point3D.create(BNMR1coord.x, BNMR1coord.y, BNMR1coord.z)
BNMR2 = adsk.core.Point3D.create(BNMR2_x, BNMR2_y, BNMR2_z)
BNMR3 = adsk.core.Point3D.create(BNMR3_x, BNMR3_y, BNMR3_z)
BNMR4 = adsk.core.Point3D.create(BNMR4_x, BNMR4_y, BNMR4_z)
BNMR5 = adsk.core.Point3D.create(BNMR5coord.x, BNMR5coord.y, BNMR5coord.z)
#Define a datastruct of points for the spline
BNMRSketchPoints = adsk.core.ObjectCollection.create()
BNMRSketchPoints.add(BNMR1)
BNMRSketchPoints.add(BNMR2)
BNMRSketchPoints.add(BNMR3)
BNMRSketchPoints.add(BNMR4)
BNMRSketchPoints.add(BNMR5)
#sketch the splines
spline1 = sketchBNMR.sketchCurves.sketchFittedSplines.add(BNMRSketchPoints)
#Add a tangent relationship to the spline at vertex 5 and horizontal at vertex 1
face1 = vertex1.faces.item(0) #Get the face attached to the vertex for the forehead
edge1 = face1.edges.item(0) #get the edge
tanline1 = spline1.activateTangentHandle(spline1.startSketchPoint) #use to make tanline horizontal
sketchBNMR.geometricConstraints.addHorizontal(tanline1) #use to make tanline vertical or horizontal
tangent_constraint1 = sketchBNMR.geometricConstraints.addTangent(spline1, edge1)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.