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: 

Find All T-Splines by text command or python

3 REPLIES 3
Reply
Message 1 of 4
support4NXZA
237 Views, 3 Replies

Find All T-Splines by text command or python

Hello 

 

I am sure this is an easy question but I searched all day for a solution. I am writing a script to automate some modification on 3D models before CAM.

 

In design, Some 3d meshes ( with .obj extension)  are imported and converted to "Quad to T-spline". I can do that with this script.

 

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import os

ui = None
app = adsk.core.Application.get()
ui  = app.userInterface

def run(context):
    try:
        string = ui.inputBox("Directory","File link")
        ui.messageBox(string[0])

        design = adsk.fusion.Design.cast(app.activeProduct)
        design.designType = adsk.fusion.DesignTypes.ParametricDesignType
        
        #Import Meshes
        file_list = os.listdir(string[0])
        for obj in file_list:
            file_url = os.path.join(string[0], obj)
            design.rootComponent.meshBodies.add(file_url, adsk.fusion.MeshUnits.MillimeterMeshUnit) 
        design.designType = adsk.fusion.DesignTypes.DirectDesignType
        
        #Change Names of Meshes and Create T-Spline from them
        array = design.rootComponent.meshBodies
        for component in array:
            component.name = ' '.join([str(elem) for elem in component.name.split(' ')[4:]])
            ui.activeSelections.clear()
            ui.activeSelections.add(component)
            
            #Create T-Spline for each model
            app.executeTextCommand("Commands.Start TSpline2BRepCommand")
            x = app.executeTextCommand("NuCommands.CommitCmd")
            
            # At this point, I added a screenshot of the browser
            # For now, I need to do these
            # 1) Changing name of T-Spline with component.name
            # 2) Add thicken feature to Mesh with 0.1 mm 

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

My problem is that I can not iterate the T-Spline objects. If I can get the T-spline which is created with textcommand above.  I can change its name and add a thichen modification.

 

Best Regards

Tags (2)
Labels (2)
3 REPLIES 3
Message 2 of 4
kandennti
in reply to: support4NXZA

Hi @support4NXZA .

 

Could you please attach a couple of OBJ files?
The error occurs in an unrelated area and it is difficult to reproduce the situation.

Message 3 of 4
support4NXZA
in reply to: kandennti

Hi 

 

Thank you for your help.  I attached the sample folder.

1) Exporting zip file to someplace

2) When you run the script, copy- and paste the directory of the folder into the input box.

 

C:\Users\xxxx\Downloads\xxxx\sample

 

The script is working on windows system but I think it also works on Linux or Mac because of python libraries.

 

Best Regards

Message 4 of 4
kandennti
in reply to: support4NXZA

@support4NXZA .

 

I couldn't find a way to access the TSplineBody, so I went into Parametric Design to edit the FormFeatur and converted it.

After that, I think I can add the thickness of the surface.

import adsk.core, adsk.fusion, adsk.cam, traceback
import os

ui = None
app = adsk.core.Application.get()
ui  = app.userInterface

def run(context):
    try:
        # string = ui.inputBox("Directory","File link")
        # ui.messageBox(string[0])
        string  = [r'C:\Temp']
        design = adsk.fusion.Design.cast(app.activeProduct)
        design.designType = adsk.fusion.DesignTypes.ParametricDesignType

        #Import Meshes
        file_list = os.listdir(string[0])
        for obj in file_list:
            file_url = os.path.join(string[0], obj)
            design.rootComponent.meshBodies.add(file_url, adsk.fusion.MeshUnits.MillimeterMeshUnit) 
        # design.designType = adsk.fusion.DesignTypes.DirectDesignType

        # Create FormFeature
        root = design.rootComponent
        forms = root.features.formFeatures
        fFeat :adsk.fusion.FormFeature = forms.add()
        tBodies :adsk.fusion.TSplineBodies = fFeat.tSplineBodies

        # FormFeature start edit
        fFeat.startEdit()

        #Change Names of Meshes and Create T-Spline from them
        meshBodies = design.rootComponent.meshBodies
        for mBody in meshBodies:
            mBody.name = ' '.join([str(elem) for elem in mBody.name.split(' ')[4:]])
            ui.activeSelections.clear()
            ui.activeSelections.add(mBody)
            
            #Create T-Spline for each model
            app.executeTextCommand("Commands.Start TSpline2BRepCommand")
            app.executeTextCommand("NuCommands.CommitCmd")

            # rename TSplineBody
            tBody :adsk.fusion.TSplineBody = tBodies[-1]
            tBody.name = mBody.name

        # FormFeature finish edit
        fFeat.finishEdit()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

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