Hi there,
for my student project I need to export the coordinates of multiple landmarks of a bone.
For this case I put sketch_points on the landmarks on the bone stl and imported that in another fusion file.
Now i build a skript to export those sketch point coordinates into an csv file.
But the problem is that i get the same coordinates every time, unrelated where the bone is in the world.
I guess the false output is the coordinate of the point inside the bone STL but not in the enviroment which the STL are now.
How can I get the "real" world geometry that I also get in the down right corner when I select the sketch point?
Output:
8.88178419700126e-18,-5.813692761401534,-0.4320296700973223
8.88178419700126e-18,-5.813692761401534,-0.4320296700973223
8.88178419700126e-18,-5.813692761401534,-0.4320296700973223
which I clearly do not want it to be.
more like
0.0,7.704120366290506,17.327285482391748
0.0,10.99999975413084,20.069999551400542
0.0,12.089999729767442,21.599999517202377
Thank you guys in dadvance for your help
import adsk.core, adsk.fusion, adsk.cam, traceback, csv app = adsk.core.Application.get() ui = app.userInterface # Initialize variables i = 0 coord = [] templist = () #1 pntEntity = ui.selectEntity('Select a sketch point', 'SketchPoints') pnt = adsk.fusion.SketchPoint.cast(pntEntity.entity) templist = ('{}'.format(pnt.geometry.z), '{}'.format(pnt.geometry.y), '{}'.format(pnt.geometry.x)) coord.append(templist) print(templist) templist = 0 #1,2,3...... depends how many pntEntity = ui.selectEntity('Select a sketch point', 'SketchPoints') pnt = adsk.fusion.SketchPoint.cast(pntEntity.entity) templist = ('{}'.format(pnt.geometry.z), '{}'.format(pnt.geometry.y), '{}'.format(pnt.geometry.x)) coord.append(templist) print(templist) templist = 0 print(coord) Point = ['name_of_bone'] header = ['X-Coordinate', 'Y-Coordinate', 'Z-Coordinate'] coordinates = open('path/coordinates_calc.csv', 'a') with coordinates: writer = csv.writer(coordinates) writer.writerow(Point) writer.writerow(header) for row in coord: writer.writerow(row)
In this example there you can see the 3 linked STLs and their sketch points which I select.
Those are the linked bone STLs in which i created the sketch points
Hello,
You have to use the worldGeometry property as I told you before.
Coordinate algebraic sign (-) in point geometry print command
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file
def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface des = adsk.fusion.Design.cast(app.activeProduct) #displayed sketches skts = [skt for comp in des.allComponents if comp.isSketchFolderLightBulbOn for skt in comp.sketches if skt.isVisible] #extension_method adsk.fusion.SketchPoint.toGeoTF = SketchPointToGeoTransform adsk.fusion.Component.toOcc = ComponentToOccurrenc #Get 3D coordinate values pos_lst = [] for skt in skts: mat = skt.transform.copy() occ = skt.parentComponent.toOcc() if not occ is None: mat.transformBy(occ.transform) for skt_pnt in skt.sketchPoints[1:]: pnt3d = skt_pnt.toGeoTF(mat) pos_lst.append('{},{},{}'.format(pnt3d.x,pnt3d.y,pnt3d.z)) #finish ui.messageBox('\n'.join(pos_lst)) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) #adsk.fusion.SketchPoint extension_method def SketchPointToGeoTransform(self,mat3d): geo = self.geometry.copy() geo.transformBy(mat3d) return geo #adsk.fusion.Component extension_method #Get occurrence from component root is None def ComponentToOccurrenc(self): root = self.parentDesign.rootComponent if self == root: return None occs = [occ for occ in root.allOccurrencesByComponent(self) if occ.component == self] return occs[0]
Yeah sorry I know. But when I used it the code did not work.
With the other answer after you I found my error. And of course you were right.It was just using the worldGeomertry property. 😉
Thank you again
@kandenntiThank you also. I found the error in my code thanks to your response 🙂
In the above code, the correct value was not obtained.
Therefore, the following part has been modified and published here.
https://github.com/kantoku-code/Fusion360-ExportSketchPointsCoordinate
・ Deep component (occurrence) acquisition of correct value
・ Considering the unit when the user executes
・ Export as CSV file