Re-naming created body with API?

Re-naming created body with API?

knightsAHN63
Participant Participant
850 Views
2 Replies
Message 1 of 3

Re-naming created body with API?

knightsAHN63
Participant
Participant

Hi everyone! I have been able to find some resources on renaming components with the API, but no luck finding anything for renaming bodies. Is this possible? The Add-On our team is working on creates a new body via a 0mm offset and then a 3mm thicken, but the body is named something arbitrary like 'body456' - is there any way to choose what this name will be, or edit it after creating?

Thank you so much in advance for your help / insight! 

 '''

                    Offset Feature

                '''

                # Create input entities for offset feature
                inputEntities = adsk.core.ObjectCollection.create()
                for face in faces:
                    inputEntities.add(face)

                # Distance for offset feature
                distance = adsk.core.ValueInput.createByString('0 mm')

                # Create an input for offset feature
                offsetFeatures = features.offsetFeatures
                offsetInput = offsetFeatures.createInput(
                    inputEntities, distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

                # Create the offset feature
                # offsetFeatures.add(offsetInput)
                offsetBody = offsetFeatures.add(offsetInput)

                '''

                    Thicken Feature

                '''

                # Create the thicken feature
                thickenFeatures = features.thickenFeatures
                inputSurfaces = adsk.core.ObjectCollection.create()
                thickenFaces = offsetBody.faces
                for face in thickenFaces:
                    inputSurfaces.add(face)
                thickness = adsk.core.ValueInput.createByString('3 mm')
                thickenInput = thickenFeatures.createInput(
                    inputSurfaces, thickness, False, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
                thickenedBody = thickenFeatures.add(thickenInput)

 

0 Likes
Accepted solutions (1)
851 Views
2 Replies
Replies (2)
Message 2 of 3

tykapl.breuil
Advocate
Advocate
Accepted solution

Simply use the BRepBody.name method, you can find the documentation here.

In your case, you probably need to do something along those lines:

 

thickenFeature = thickenFeatures.add(thickenFeatureInput)
thickenedBody = thickenFeature.bodies.item(0) #Assuming only one body is created/modified through this feature
thickenedBody.name = 'Name of the body'

 

 

Message 3 of 3

knightsAHN63
Participant
Participant

Worked like a charm! Thank you so much!! 😊