Using iLogic to change part numbers to the saved file name

Using iLogic to change part numbers to the saved file name

SleikerBF
Contributor Contributor
1,065 Views
3 Replies
Message 1 of 4

Using iLogic to change part numbers to the saved file name

SleikerBF
Contributor
Contributor

Good Morning or Afternoon,

 

I'm no stranger to iLogic but I'm still very much a amateur with coding, I've created code that auto creates pdfs of drawings once its saved to a specific folder or creating a fluctuating stair that changes to width and any height. But today I am asking whenever I import a file from content center and the part number in iProperties always changes, if you change the length or the size of that Content Center Part back to the default even if I changed it prior to the saved file name of that part. I want to create code that at assembly level will go through all parts and if its different then the saved ipt file it will change it to that name rather then the default content name it puts there. I've come across a few but I just would like a definitive answer or suggestions. It's been almost a year since I've touched iLogic.

0 Likes
Accepted solutions (1)
1,066 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

Hi @SleikerBF 

Can you clarify with short bullets the sequence of operations and what variants your working with, will it be filename/part number/description. Are the cc files custom? Are you exchanging custom for standard etc?

It can be a little hard to grasp the interactions when instructions are in paragraph form and are lacking the terminology your seeing when interacting with the files.

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @SleikerBF . I hope I understood you correctly. You have parts imported from the content center, which you change and resave, but the information in the PartNumber of these parts is not updated. So you need to update the PartNumber based on the filename.
This code searches your assembly for imported content center components and checks that the PartNumber and filename match, and if they differ, a new PartNumber is written.

Public Sub Main()
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)
	If oADoc Is Nothing Then Exit Sub		
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	For Each oCCDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of PartDocument)
		If oOccs.AllReferencedOccurrences(oCCDoc.ComponentDefinition).Count = 0 Or
			Not oCCDoc.IsModifiable Then Continue For
		Try : propSet = oCCDoc.PropertySets("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")
		Catch : Continue For : End Try
		Dim sNameCC As String = IO.Path.GetFileNameWithoutExtension(oCCDoc.DisplayName)
		Dim oPNumb As Inventor.Property = oCCDoc.PropertySets("Design Tracking Properties")("Part Number")
		If Not oPNumb.Value = sNameCC Then oPNumb.Value = sNameCC
	Next
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 4 of 4

SleikerBF
Contributor
Contributor

This worked great, thank you!

0 Likes