Hi all, I have a problem with the intersection of a line3d with a certain number of sketchCurves proiected on a sketch (PS).
I have a set of circle on a sketch (CS) and a surface of revolution (RS) created by a revolve operation.
This surface is created in a case by the revolve of a profile that is constituted by an arc (Ex1), in another case by the revolve of a profile that is constituted by a spline (Ex2). In each case the profile is closed by two lines.
The circles reside on a plane orthogonal to the plane of the profile. This plane contains the sketch with the circles.
I consider only one circle for the presentation of my problem, but the issue can be found for each circle.
I would like to project (orthogonally) the center of the circle on the surfaces generated by the profile: the base and the cap.
To do that, I create a plane from three points (3P): the origin of the profile(O), the center of the circle (C) and a point that have the same x and y but different z respect the center of the circles and can be considered the proiection point (P). I create a line3d (3L) that link P with C.
I project the surface to this sketch. The result is a section of the cap that has almost the same shape.
The first question is:
Different projection of the surface over the plane generate differents numbers of sketchCurves. In certain cases are 3 in other case are 4 or 5. I cannot understand why.
SK-Vertical (EX1)
Curve: adsk::fusion::SketchLine
Curve: adsk::fusion::SketchLine
Curve: adsk::fusion::SketchArc
Curve: adsk::fusion::SketchLine
Or
SK-Vertical (2) (EX1)
Curve: adsk::fusion::SketchLine
Curve: adsk::fusion::SketchArc
Curve: adsk::fusion::SketchLine
In the first case (EX1) the projected curves are sketchLines and sketchArcs, in the second case they are sketchLines and sketchFixedSpline.
SK-Vertical (EX2)
Curve: adsk::fusion::SketchLine
Curve: adsk::fusion::SketchLine
Curve: adsk::fusion::SketchFixedSpline
Curve: adsk::fusion::SketchFixedSpline
Curve: adsk::fusion::SketchLine
I would like to find the intersection points between the line 3L and the projected curves.
This is the result of my code:
- no problem with the intersections with the sketchArcs (Ex1)
- problems with the intersections with the sketchLines (Ex1-Ex2). Sometimes the points are found and sometime not
- many problems with the sketchFixeSpline (Ex2). Rarelly the points are found.
I use the same code in all the cases. I change only the test on the type of curve to be intercepted.
I cannot understand this kind of issue.
Many Thanks Dino
I attach a part of the code:
# proietto la calotta sullo sketchVPlane projectCurves = sketchVPlane.project(calotta) nProjCurve = projectCurves.count print("N. Project Curve: ", nProjCurve) # trovo gli item delle curve che sono SketchFittedSpline itemCurve=[] for i in range(0,nProjCurve): print("Project Curve type: " + str(i) + " " + str(projectCurves.item(i).objectType)) # if projectCurves.item(i).objectType == "adsk::fusion::SketchArc": # print("SketchArc = "+str(i)) # if projectCurves.item(i).objectType == "adsk::fusion::SketchLine": # print("SketchLine = "+str(i)) if projectCurves.item(i).objectType == "adsk::fusion::SketchFixedSpline": print("SketchFixedSpline = "+str(i)) itemCurve.append(i) for i in range(0,len(itemCurve)): print("Item: " + str(itemCurve[i])) # trovo i punti sul nuovo sketch PWS = calottaCenter.worldGeometry # point in WorldSpace calottaCenterSS = sketchVPlane.modelToSketchSpace(PWS) PWS = centerCircle.worldGeometry # point in WorldSpace centerCircleSS = sketchVPlane.modelToSketchSpace(PWS) PWS = modelOrigin.worldGeometry # point in WorldSpace modelOriginSS = sketchVPlane.modelToSketchSpace(PWS) # trovo un quarto punto da cui proiettare i centri in maniera ortogonale.i orthoP = adsk.core.Point3D.create(centerCircleSS.x, 10, centerCircleSS.y ) orthoPoint = planeVSketchPoints.add(orthoP) planeSketchLines = sketchVPlane.sketchCurves.sketchLines planeSketchLine = planeSketchLines.addByTwoPoints(orthoPoint, centerCircleSS) # trova il punto di intersezione della linea che congiunge # il centro della calotta con il centro del cerchio line3D = adsk.core.Line3D.create( centerCircleSS, orthoPoint.geometry) infiniteLine = line3D.asInfiniteLine() # esamina tutto il vettore delle SketchFixedSpline proiettate for i in range(0, len(itemCurve)): print("ItemCurve: " + str(itemCurve[i])) projectCurve = projectCurves.item(itemCurve[i]) calottaPoints = infiniteLine.intersectWithCurve(projectCurve.geometry) print("N Inters. Points: " + str(i) + " " + str(calottaPoints.count)+"\n") # coordinate punto sulla calotta (proiezione del centro del cerchio) # lo aggiungo alla collezione dei punti sullo sketch verticale (planeVSketchPoints) point = calottaPoints.item(0)
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
I took an entirely different approach that for me is simpler and doesn't require the creation of the curves. In this approach it doesn't matter what the surface is. Below are a couple of examples, with the left being a revolve of an ellipse and on the right being a random sculptured surface. The centers of the circles in the selected sketch are projected onto the surface and the spheres are created there. I'm bypassing a lot of construction by doing this in direct modeling mode. The program creates a base feature and does the modeling there. There are less restrictions that way because I don't have to define all of the parametric relationships.
I took an entirely different approach that for me is simpler and doesn't require the creation of the curves. In this approach it doesn't matter what the surface is. Below are a couple of examples, with the left being a revolve of an ellipse and on the right being a random sculptured surface. The centers of the circles in the selected sketch are projected onto the surface and the spheres are created there. I'm bypassing a lot of construction by doing this in direct modeling mode. The program creates a base feature and does the modeling there. There are less restrictions that way because I don't have to define all of the parametric relationships.
Here's the code. It prompts you to select the face and the sketch containing the circles.
import adsk.core, adsk.fusion, traceback import os.path, sys import math def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface des = adsk.fusion.Design.cast(app.activeProduct) root = des.rootComponent toFaceSel = ui.selectEntity('Select face to project to.', 'Faces') if toFaceSel: toFace = adsk.fusion.BRepFace.cast(toFaceSel.entity) circSketchSel = ui.selectEntity('Select the circle sketch.', 'Sketches') if circSketchSel: circSketch = adsk.fusion.Sketch.cast(circSketchSel.entity) if not toFaceSel or not circSketch: return # Determine the projection direction. projDir = circSketch.xDirection.crossProduct(circSketch.yDirection) # Determine if the face is in the direction of the vector or not. maxSize = toFace.boundingBox.maxPoint.distanceTo(toFace.boundingBox.minPoint) pntVec = circSketch.origin.vectorTo(toFace.pointOnFace) originOffset = adsk.core.Vector3D.cast(None) if projDir.dotProduct(pntVec) < 0: projDir.scaleBy(-1) originOffset = projDir.copy() originOffset.scaleBy(-maxSize) else: originOffset = projDir.copy() originOffset.scaleBy(maxSize) baseFeature = root.features.baseFeatures.add() baseFeature.startEdit() # Iterate through the circles on the selected sketch. circ = adsk.fusion.SketchCircle.cast(None) lastFeature = None for circ in circSketch.sketchCurves.sketchCircles: origin = circ.centerSketchPoint.worldGeometry origin.translateBy(originOffset) hitPoints = adsk.core.ObjectCollection.create() foundFaces = root.findBRepUsingRay(origin, projDir, adsk.fusion.BRepEntityTypes.BRepFaceEntityType, 0.0001, True, hitPoints) # Look for the toFace in the foundFaces list. for i in range(foundFaces.count): if foundFaces.item(i) == toFace: pstn = hitPoints.item(i) # Draw a construction plane parallel to the sketch plane and at the intersection point. planeInput = root.constructionPlanes.createInput() planeInput.targetBaseOrFormFeature = baseFeature planeInput.setByPlane(adsk.core.Plane.create(pstn, projDir)) plane = root.constructionPlanes.add(planeInput) # Create a sketch on the plane. sk = root.sketches.add(plane) # Draw the sketch geometry to create a sphere. centerPnt = sk.modelToSketchSpace(pstn) startPnt = adsk.core.Point3D.create(centerPnt.x, centerPnt.y-circ.radius, 0) arc = sk.sketchCurves.sketchArcs.addByCenterStartSweep(centerPnt, startPnt, math.pi) axisLine = sk.sketchCurves.sketchLines.addByTwoPoints(arc.startSketchPoint, arc.endSketchPoint) # Create the revolve feature. prof = sk.profiles.item(0) revInput = root.features.revolveFeatures.createInput(prof, axisLine, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) revInput.targetBaseFeature = baseFeature revInput.setAngleExtent(False, adsk.core.ValueInput.createByReal(math.pi*2)) root.features.revolveFeatures.add(revInput) if baseFeature: baseFeature.finishEdit() except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Hi Brian, it is really fantastic. I thank you a lot. I spent a lot of time to create a very long script (that have some problem) and I see how short is the code that you sent me. It uses a lot of objects and methods that I don’t know. This a good starting point to improve my knowledge about Api. My intention is to try to understand the functions that you use and, if you allow, I will ask you some more question about them.
Thank you very much for all your time.
Dino