Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export World geometry of sketch points

5 REPLIES 5
Reply
Message 1 of 6
_fabschke_
850 Views, 5 Replies

Export World geometry of sketch points

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)

Bildschirmfoto 2019-10-21 um 15.06.43.png

In this example there you can see the 3 linked STLs and their sketch points which I select.

 

 

 

Bildschirmfoto 2019-10-21 um 15.07.44.pngThose are the linked bone STLs in which i created the sketch points

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 REPLIES 5
Message 2 of 6
JeromeBriot
in reply to: _fabschke_

Hello,

 

You have to use the worldGeometry property as I told you before.

Coordinate algebraic sign (-) in point geometry print command

 

 

Message 3 of 6
kandennti
in reply to: _fabschke_

 
I can't explain because I'm not good at English.
The following code displays the position of all visible sketch points.
That is the "real" world position.
 
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]
Message 4 of 6
_fabschke_
in reply to: JeromeBriot

@JeromeBriot 

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 🙂

Message 5 of 6
kandennti
in reply to: _fabschke_

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

Message 6 of 6
marlon.weinert
in reply to: _fabschke_

Awesome! Thanks a lot, this is exactly what I was looking for!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report