IPT solid body rename using part number

IPT solid body rename using part number

eucci
Advocate Advocate
338 Views
4 Replies
Message 1 of 5

IPT solid body rename using part number

eucci
Advocate
Advocate

Hello,

I have a situation where I have imported an assembly of individual step files and the result is an iam with many ipt files. Each ipt has the correct part number and filename. But, the solid body name in the part is something like "Solid2". Is there a script that will take all ipts in an assembly and update the solid body name to match the part number?

 

See attached

0 Likes
Accepted solutions (1)
339 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @eucci.  If a part has multiple solid bodies in it, but the part only has one Part Number, then how should each solid body's name be different?  Should there be something like a " - 1", " -2" (space, dash,  Index integer) added to the end of each body's name?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

eucci
Advocate
Advocate

In this scenerio, there will be no multibody parts. They will all have just one solid body

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

OK @eucci.  Then something relatively simple like the following iLogic rule example should work OK for you.  It gets the current document, checks if it is either a part or assembly, and if neither, it will exit the rule.  Then it calls a small, custom Sub routine to run on the current document...in case it is a part.  Then, it will iterate through all the documents being referenced within the current document...in case it is an assembly, and call that routine to run on each of them.  The routine will only attempt to do something to the document if it is a part, and only if it has at least 1 body in it.  Then it will get that part's Part Number value, and try to set that as the first body's name.  Then it updates the current document.

Sub Main
	Dim oDoc As Inventor.Document = ThisDoc.Document
	If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
	RenameFirstBodyToPartNumber(oDoc)
	For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
		RenameFirstBodyToPartNumber(oRefDoc)
	Next
	oDoc.Update2(True)
End Sub

Sub RenameFirstBodyToPartNumber(oDoc As Inventor.Document)
	If Not TypeOf oDoc Is PartDocument Then Return
	Dim oPDoc As PartDocument = oDoc
	Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
	If oBodies.Count = 0 Then Return
	Dim sPN As String = oPDoc.PropertySets.Item(3).Item(2).Value 'Part Number
	Try : oBodies.Item(1).Name = sPN : Catch : End Try
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

eucci
Advocate
Advocate

Awesome!

I ran it on an assembly of about 100 parts. It ran so quickly I didn't think it worked!

 

Thank You!

 

 

0 Likes