Code to retrieve a bolt's part number using ilogic to display it in a custom column in my parts list

Code to retrieve a bolt's part number using ilogic to display it in a custom column in my parts list

Anonymous
Not applicable
835 Views
7 Replies
Message 1 of 8

Code to retrieve a bolt's part number using ilogic to display it in a custom column in my parts list

Anonymous
Not applicable

Hi,

 

I know that a bought out part (for example: bolts, nuts, washers, etc) cannot be modified in terms of adding ilogic or forms. I want to put an ilogic in my assembly file to identify a purchased part and retrieve its part number to display it in my parts list custom column. I want to write something as follows:

If BOM_Structure = "Purchased" Then
			iProperties.Value("Custom", "SPECIFICATIONS") = iProperties.Value("Project", "Part Number")
End If

Please correct my ilogic as I know it not this way to identify a purchased part from the BOM structure.

 

Thanks,

Anas.

 

 

 

 

0 Likes
836 Views
7 Replies
Replies (7)
Message 2 of 8

j.pavlicek
Collaborator
Collaborator

Hi, what about something like code below?

Sub Main
	
	'Your other code must be inside (Sub Main ... End Sub) too
	
	Dim oDoc As AssemblyDocument = ThisAssembly.Document
	
	'Chose if you want to check occurences (just parts of this assembly) or leaf occurences (all parts-only even in subassemblies)
'	Dim Occurs As Object = oDoc.ComponentDefinition.Occurrences
	Dim Occurs As Object = oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
	
	Dim item As Object
	For Each item In Occurs
		If item.BOMStructure = kPurchasedBOMStructure Then
			Dim PartNo As String = GetIpropValue(item.Definition.Document, "Design Tracking Properties", "Part Number") 'Gets Part Number of a component
			Logger.Info(item.name & "(" & PartNo & ")" & "is purchased") 'Logs into iLogic Log
			' do what you want 
		End If
	Next item
End Sub

'This is function for reading iProperty from another document than rule is ran from.
Private Function GetIpropValue(ByVal oDoc As Document, ByVal iSetName As String, ByVal iPropName As String) As String
	Dim iPropSet As PropertySet
	iPropSet = oDoc.PropertySets(iSetName)
	
	Try 
		iPropValue = iPropSet.Item(iPropName).Value
		GetIpropValue = iPropValue
	Catch
		GetIpropValue = Nothing
	End Try	
End Function

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 3 of 8

Anonymous
Not applicable

I can understand some parts of the ilogic. I seem to me that I can use it. I will have to make some changes .

See below, what I exactly what I want to do.

I want to put the part number of the wing nut into the SPECIFICATIONS column (SPECIFICATIONS id a custom iProperty I created).

Capture.PNG

I should be able to write an ilogic in the assembly file in order for what is in the Description column in red to be displayed in the green cell.

 

Thanks.

0 Likes
Message 4 of 8

j.pavlicek
Collaborator
Collaborator

@Anonymous I'm affraid that this is not possible, custom iProperties are stored in  a *.ipt file which is read-only for Content Center parts.

 

I suggest to create Your Own Content Center Library (About Customized Content Center Libraries). Then copy existing family there and add column SPECIFICATIONS as Expression column (with value from Part Number) and use this families instead bundled ones.

 

In steps:

 

  1. File > Manage > Project
  2. Configure Content Center Libraries (last button in right row)
  3. Create Library (Book with spark icon, second from left)
  4. Fill what you want as name
  5. Close all dialogs and save changes
  6. Manage (if no document open Tools) > Content Center section > Editor
  7. Find wanted family (for example ISO 4014)
  8. Left click on family (is greyed out - its ok), Save Copy As (do not use Copy to!)
  9. (In dialog) Select your library, check Independent family, and fill what you want (or just delete "Copy of " prefix and add your to Family Folder Name)
  10. Find your new Family (editable families are not greyed out)
  11. Right click - Family Table
  12. Add Column
  13. Right click to Column Header and select Column Properities
  14. Check Expression
  15. Use button with three dots and select "Part Number" from there
  16. Map to Inventor Property Custom and fill SEMIPRODUCTS in new availible field
  17. Save and use this part instead the bundled one.

 

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 5 of 8

Anonymous
Not applicable

I feared that.

I did a custom content center which I could edit etc, but it is not practical for my purpose. Extracting info from bought outs from the Content Center is , as far as I know ilogic, impossible to do. Is there no other way to counter the step of creating a custom CC(Content Center)?

 

Anas.

0 Likes
Message 6 of 8

j.pavlicek
Collaborator
Collaborator

@Anonymous Maybe there is a solution...

Why exactly do you need this data in BOM? Who uses them?

 

For example: Do you want to see them in PartsList on drawing, or in exported Excel table?

 

Wait... There is no need for iLogic when you fill SPECIFICATIONS in Content Center (and map it as Custom iProperty). And if you need to read it with iLogic, you can access iProperties of Content Center files as standard IPT file (but you cannot to change them, because read-only).



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 7 of 8

Anonymous
Not applicable

 

I need this data in my parts list in the my drawing space. I do not need them in my BOM. It is for production purposes. For the excel I do not have to export the data.

0 Likes
Message 8 of 8

j.pavlicek
Collaborator
Collaborator

Ok.

I still think a Custom Library is best solution, but...

 

You can add custom column into PartsList (in Parts List Column Chooser), which could be filled manually. Or by iLogic, but this is not simple iLogic.

 

You need to get AssemblyDocument object, go trough whole BOM and check every row in BOM if purchased item is here. If yes, get and store it's part number + Item number. Then get PartsList object in drawing, and cycle trough all rows in PartsList and check theirs item numbers against values stored from Assembly BOM. If you find purchased item Item number in PartsList, fill cell in a new Column with value of Part number stored before.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes