Ilogic script for Part Number regeneration at .iam level

Ilogic script for Part Number regeneration at .iam level

drafting_nufab
Contributor Contributor
404 Views
6 Replies
Message 1 of 7

Ilogic script for Part Number regeneration at .iam level

drafting_nufab
Contributor
Contributor

Hi Everyone,

 

i have a single line script for Part Number update that works well at the part level

 iProperties.Value("Project", "Part Number")= ThisDoc.FileName

 I would like to apply the same principle at the .iam level so that all components in an .iam have their Part Number regenerated / replaced with the parts current file name. I would like to trigger this at the .iam level to avoid the need to open each part within the assembly.

Appreciate any assistance, cheers, wade

0 Likes
Accepted solutions (1)
405 Views
6 Replies
Replies (6)
Message 2 of 7

m_baczewski
Advocate
Advocate

Hello,

Try this code. This code will change the name in all PartDocument in your assembly.Did I understand you correctly?

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

If oDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}"
	For Each oReferenced In oDoc.AllReferencedDocuments
		If oReferenced.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
			oReferenced.PropertySets.Item("Design Tracking Properties").Item("Part Number").Expression = ThisDoc.FileName
		End If
	Next 
Else
	MsgBox("It`s not a assembly document")
End If

 

 

Message 3 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Just dropping another similar iLogic code example in here.  This rule does not check any document types, and can be ran on any type of document, making it a good candidate for an external rule.  It will process the current document, and all its referenced documents, setting their Part Number to their file name (without file extension).  Its 'write' lines are wrapped within condensed Try...Catch statements, to avoid any potential errors.  I am not sure if this is what you wanted though, because it was difficult to determine based on the wording/terminology of your initial comments.

Dim oDoc As Document = ThisDoc.Document
Try : oDoc.PropertySets.Item(3).Item(2).Value = ThisDoc.FileName : Catch : End Try
Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
If oRefDocs Is Nothing OrElse oRefDocs.Count = 0 Then Return
For Each oRefDoc As Document In oRefDocs
	Dim sFileName As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
	Try : oRefDoc.PropertySets.Item(3).Item(2).Value = sFileName : Catch : End Try
Next 'oRefDoc
If oDoc.RequiresUpdate Then oDoc.Update2(True)

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)

Message 4 of 7

drafting_nufab
Contributor
Contributor

Gday m-baczewski and WCrihfield. Thanks for the replies and suggestions / scripts. Only working part time, hence the delayed response. I will give your suggestions a go today and see how they work. As far as further details go: 

  • I want to create and save frame generator parts so that their file name is a proprietary file name & that the ‘proprietary file name = (iproperties) ‘part number’. Screen shot 1
  • I don’t want to use the part number or file name generated by the family table. Screen shot 2
  • This is straight forward when making parts that are not generated from the contents centre, eg typical sketched and modelled parts.
  • When making parts generated from contents center tables, I have not found a way to map (overwrite / replace) the generated file name with the ‘proprietary file name’?
  • Is there a method to achieve this via a family table edit? (I could not find a parameter that would map the ‘proprietary file name’ to the iproperties part number.

SS1

projects77VWN_0-1707181117838.png

 

SS2

projects77VWN_1-1707181117840.png

 

Also, I am interested in learning more about iLogic script writing. Are there any forums, documents etc that you could recommend to a beginner?

thanks again, Wade

0 Likes
Message 5 of 7

drafting_nufab
Contributor
Contributor

Hi WC, further to my earlier response, your script worked beautifully. Just what I was trying to achieve. Great start to the week 👍so thanks very much. 

With regard to skilling up on iLogic, do you know of any good resources for beginners?

All the best, Wade

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @drafting_nufab.  I am glad I was able to help you some.  I do not use the Frame Generator or Content Center stuff that much anymore, and even when I was, I was not controlling them by code.  I know that the files they generate are generally ReadOnly, like Library files, are given 'generated' names, and stored in a specific location/file structure.  Some of these aspects did not work very well with how we need to be able to do things, or with our filing system/structure.  What few things we did use from those resources, we sometimes copied a file externally, then converted it into a 'regular' part, then controlled its size/shape by other configuration means, such as by using iLogic.  So, I am not personally sure how you would 'map' one detail to another within that Content Center system by code.

 

As for learning to control Inventor by utilizing its API and iLogic, that is something that most folks just seem to learn as they go, by trial & error testing, looking at existing examples and breaking it down logically, and reviewing every little iLogic related resource we see available along the way.  There does not seem to be a super good one stop place to learn everything there is to learn about the Inventor API, or the iLogic API.  However, I have attached a PDF that you might find helpful.  Good luck.  It has been a very rewarding journey for me, so I hope it will be for you also. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

drafting_nufab
Contributor
Contributor

thanks again for your time and effort to assist me. much appreciated. 

0 Likes