Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Empty part number if BOM is phantom

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mrawesomelemons
480 Views, 5 Replies

Empty part number if BOM is phantom

I want to empty my part number if my assembly or part BOM structure is set to phantom. I have already fiddled with it a little and came up with some different ideas. Sadly none of them worked how I wanted them to.

What I have now is this:

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'Check if the BOM of the document is Phantom
If oDoc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	'Set the Part Number to blank
	iProperties.Value("Project", "Part Number") = ""
End If

But if I run it on an assembly I get the error:

The public member BOMStructure for type AssemblyDocument not found.

If I run it on a part I get the error:

The public member BOMStructure for type PartDocument not found.

I don't know if it's possible to have one iRule for both assemblies and parts.
If possible I also would like to run the rule for all the sub assemblies and parts in an assembly if possible.

 

Can someone help me with this?

5 REPLIES 5
Message 2 of 6
clutsa
in reply to: mrawesomelemons

BOMStructure is part of the ComponentDefinition not the document so this should solve your first issue.

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'Check if the BOM of the document is Phantom
If oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	'Set the Part Number to blank
	iProperties.Value("Project", "Part Number") = ""
End If
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
Message 3 of 6
clutsa
in reply to: clutsa

Try this for the assembly loop...

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim compDef As ComponentDefinition
compDef = oDoc.ComponentDefinition
Dim compOcc As ComponentOccurrence

For Each compOcc In compDef.Occurrences
	If compOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	'Set the Part Number to blank
	iProperties.Value(compOcc.Name,"Project", "Part Number") = ""
End If
Next

I didn't filly test this so let me know if you have issues.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
Message 4 of 6
mrawesomelemons
in reply to: clutsa

Thank you for your reply! It seems that I was somewhat close.

It seems to work now for assemblies (phantom parts and assemblies do get their partnumber deleted albeit after a few tries).

But if I run the rule the top assembly doesn't get it's part number deleted. The same goes if I run the rule on a phantom part (ipt).

It seems that we're close. Thank you for your help. If you have some advice please let me know.

 

Seems like  I got it. I just combined your two replies and it works now.

This is what I ended up with:

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim compDef As ComponentDefinition
compDef = oDoc.ComponentDefinition
Dim compOcc As ComponentOccurrence

'Check if the BOM of the document is Phantom
If oDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	'Set the Part Number to blank
	iProperties.Value("Project", "Part Number") = ""
End If

For Each compOcc In compDef.Occurrences
	If compOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	'Set the Part Number to blank
	iProperties.Value(compOcc.Name,"Project", "Part Number") = ""
End If
Next
Message 5 of 6

Okay my colleague told me this was a good start but he also wants to use it for the parts in a weldment.

We have different categories in the Vault for these. I added them to their templates so I could use them.

I made this iRule to empty the part number. It works but not for any sub assemblies or parts in an assembly.

What am I doing wrong?

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'Define all the documents in an assembly
Dim compDef As ComponentDefinition = oDoc.ComponentDefinition
Dim compOcc As ComponentOccurrence

Try
	'Check if the Category is either Without Item or Weldment Part
	If iProperties.Value("CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value("CUSTOM", "ItemCategory") = "Weldment Part"
		'Set the Part Number to blank
		iProperties.Value("Project", "Part Number") = ""
	End If
Catch
End Try

For Each compOcc In compDef.Occurrences
	Try
		'Check if the Category is either Without Item or Weldment Part for each document in assembly
		If iProperties.Value("CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value("CUSTOM", "ItemCategory") = "Weldment Part"
			'Set the Part Number to blank
			iProperties.Value("Project", "Part Number") = ""
		End If
	Catch
	End Try
Next
'Update file
iLogicVb.UpdateWhenDone = True

 
EDIT: Got it!

I forgot to add comOcc.Name in front of the iProperty value.

Now it is working great.

For anyone who wants to add this to their Inventor here is the code:

Note:

- This will empty the part number for parts and assemblies with the category "Without Item" or "Weldment Part" in the Vault. These need to be added to the template of those parts.

- If the file doesn't have the property this rule will just skip it.

 

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'Define all the documents in an assembly
Dim compDef As ComponentDefinition = oDoc.ComponentDefinition
Dim compOcc As ComponentOccurrence

Try
	'Check if the Category is either Without Item or Weldment Part
	If iProperties.Value("CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value("CUSTOM", "ItemCategory") = "Weldment Part"
		'Set the Part Number to blank
		iProperties.Value("Project", "Part Number") = ""
	End If
Catch
End Try

For Each compOcc In compDef.Occurrences
	Try
		'Check if the Category is either Without Item or Weldment Part for each document in assembly
		If iProperties.Value(compOcc.Name,"CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value(compOcc.Name,"CUSTOM", "ItemCategory") = "Weldment Part"
			'Set the Part Number to blank
			iProperties.Value(compOcc.Name,"Project", "Part Number") = ""
		End If
	Catch
	End Try
Next
'Update file
iLogicVb.UpdateWhenDone = True
Message 6 of 6

After using it today I did find a bug. I managed to fix it and now it works.

This is the code I am using:

'Define the open document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument


Try
	'Check if the Category is either Without Item or Weldment Part
	If iProperties.Value("CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value("CUSTOM", "ItemCategory") = "Weldment Part"
		'Set the Part Number to blank
		iProperties.Value("Project", "Part Number") = ""
	End If
Catch
End Try

If oDoc.DocumentType = kAssemblyDocumentObject
'Define all the documents in an assembly
Dim compDef As ComponentDefinition 
compDef = oDoc.ComponentDefinition
Dim compOcc As ComponentOccurrence
For Each compOcc In compDef.Occurrences
	Try
		'Check if the Category is either Without Item or Weldment Part for each document in assembly
		If iProperties.Value(compOcc.Name,"CUSTOM", "ItemCategory") = "Without Item" Or iProperties.Value(compOcc.Name,"CUSTOM", "ItemCategory") = "Weldment Part"
			'Set the Part Number to blank
			iProperties.Value(compOcc.Name,"Project", "Part Number") = ""
		End If
	Catch
	End Try
Next
End If

'Update file
iLogicVb.UpdateWhenDone = True

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report