Also counting reference parts, which it should not.!

Also counting reference parts, which it should not.!

LSA-skan
Advocate Advocate
980 Views
5 Replies
Message 1 of 6

Also counting reference parts, which it should not.!

LSA-skan
Advocate
Advocate

Hi all

 

I have this great code i got from this thread..:

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Extract-part-qty-with-ilogic/m-p/37815...

 

What it does, is that it counts the total of occurences throughout an assy. Both Parts and sub assys. 

 

Unfortunately i just discovered that it also counts parts and assy's which are set to Reference in BOM, which is a big problem, as we use this from time to time, for our modular configurations.

 

The code i use now is slightly diffrent as i have added some other functions, but they shouldn't have anything to do with the problem im discribing above.

 

Dim openDoc As Document
Dim docFile As Document
Dim assemblyDoc As AssemblyDocument
Dim assemblyDef As AssemblyComponentDefinition
Dim partQty As ComponentOccurrencesEnumerator
Dim FNamePos As Long
Dim docFName As String
Dim Ordre As String

ThisApplication.StatusBarText = "Jeg arbejder... rolig nu.!"

openDoc = ThisDoc.Document        
Ordre = iProperties.Value("Project", "Project")
Ordre = InputBox("Er " & Ordre & " det rigtige ordre nr? Ellers skriv det rigtige", "Ordre nummer", Ordre)
iProperties.Value("Project", "Project") = Ordre
If openDoc.DocumentType = kAssemblyDocumentObject Then  
    For Each docFile In openDoc.AllReferencedDocuments
    FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        If docFile.IsModifiable = True Then
        assemblyDoc = openDoc        
        assemblyDef = assemblyDoc.ComponentDefinition
        partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
                Try
                    If partQty.Count <>  iProperties.Value(docFName, "Custom", "PCS") Then                
                        iProperties.Value(docFName, "Custom", "PCS") = partQty.Count
                    End If                      
                    Catch
                        iProperties.Value(docFName, "Custom", "PCS") = partQty.Count
                    End Try
                Try
                    If Ordre <>  iProperties.Value(docFName, "Project", "Project") Then                
                        iProperties.Value(docFName, "Project", "Project") = Ordre
                    End If                      
                    Catch
                        iProperties.Value(docFName, "Project", "Project") = Ordre
                End Try
        End If
    Next
    ThisApplication.StatusBarText = "Ready"
Else
MessageBox.Show("Du kan KUN køre denne regel i en Assembly", "Forkert Filtype",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 

Hope someone knows how to make this rule not count the reference occurences..!

 

/LSA

 

981 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

I have the same issue. My understanding is that the line that reads

partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)

 is the issue. It should say something like

partQty = assemblyDef.Occurrences.NOTREF(docFile)

or maybe

partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile).NOTREF

I would think. But  I don't know where to find documentation on assemblyDef.Occurrences so that I can replace NOTREF with whatever name is needed fix it.

0 Likes
Message 3 of 6

MechMachineMan
Advisor
Advisor

Well, considering "NOTREF" or anything similar isn't a valid method/property of the ComponentOccurrence object, you are SOL.

 

Use the link below and search for ComponentOccurrence. It will find you the API resources on the topic, where you can see available properties/methods for yourself.

 

http://help.autodesk.com/view/INVNTOR/2019/ENU/

 

You have to revised most of your approach in order to carefully establish what parts are and aren't reference.

 

Please make sure to take a look at the 4th BOM idea in my signature as it seems to be in line with the functionality you want. Thanks!


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 6

Anonymous
Not applicable

Realize this is an old thread, but seems like this problem has yet to find a solution, so hoping to restart the conversation.  I too use the referenced code and wish it did not count parts if they are in a sub assembly with BOM structure set as reference, nor if the part BOM structure is set to reference either within the sub or master.  

 

There are at least two other threads that touch on this question:

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-count-all-normal-components-in-assembly...

 

https://forums.autodesk.com/t5/inventor-customization/extract-part-qty-with-ilogic/td-p/3564644

 

From the top link, the Normal BOM structure state can be referenced in the code with 

 

BOMStructureEnum.kNormalBOMStructure 

 

So is it possible to add an If/Then or Try/Catch statement to MegaJerk's code (original post here) to only count an occurrence of a part if the BOM structure is Normal?  I have tried but not a coder, just a lowly technical designer, so any help appreciated. 

 

Not sure if I can post a pack and go here, but I have attached a pack and go (I am using 2018, fyi, but have access to 2019) of a simple test case assembly that spells out what I'm trying to accomplish.  All three of codes from the posts mentioned above are included in the iLogic browser of the master assembly.

 

Thanks in advance.  

0 Likes
Message 5 of 6

pmaxwellNKJEX
Enthusiast
Enthusiast

I have just gone to start this exact topic with a very similar code (also found on these forums)

 

Has there been a simple solution so not too much code needs to change?

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Hi @pmaxwellNKJEX.  There are lots of routes and variations in code that could be used to count quantities in assemblies.  It depends on the needs of the individual, and the requirements of how their company needs the data presented, and it seems like every one wants it done slightly differently.  Here is one example iLogic rule that counts all levels of assembly components just based on BOMStructure alone.  It is obviously not a perfect solution for everyone and every scenario, because it is primarily a research tool, but it does show a couple processes that you might not have seen before that may be useful.  It basically recursively iterates over all components that are not currently suppressed and down through all levels of the assembly, counting components based on their BOMStructure.  In this example the second Sub routine is 'only' used for the 'recursive' functionality, while outsourcing the primary task related to each component to another custom Sub routine.  That is a nice setup/layout that can be transferred and used in several different scenarios where recursive processing of multi-level collections is needed.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	RecurseComponents(oOccs, AddressOf ProcessComponent)
	Dim OATotal As Integer = (NormalCount + InseparableCount + PurchasedCount + PhantomCount + ReferenceCount + VariesCount)
	Dim sReport As String = "Assembly Quantities - By BOMStructure:" & vbCrLf & _
	"Normal Quantity = " & NormalCount.ToString & vbCrLf & _
	"Inseparable Quantity = " & InseparableCount & vbCrLf & _
	"Purchased Quantity = " & PurchasedCount & vbCrLf & _
	"Reference Quantity = " & ReferenceCount & vbCrLf & _
	"Phantom Quantity = " & PhantomCount & vbCrLf & _
	"Varies Quantity = " & VariesCount & vbCrLf & _
	"Overall Total = " & OATotal
	Logger.Info(sReport)
End Sub

Dim NormalCount, InseparableCount, ReferenceCount, PurchasedCount, PhantomCount, VariesCount As Integer

Sub RecurseComponents(oComps As ComponentOccurrences, ComponentProcess As Action(Of ComponentOccurrence))
	If oComps Is Nothing OrElse oComps.Count = 0 Then Return
	For Each oComp As ComponentOccurrence In oComps
		ComponentProcess(oComp)
		If oComp.Suppressed = False AndAlso _
			oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			'RecurseComponents(oComp.Definition.Occurrences, ComponentProcess)
			RecurseComponents(oComp.SubOccurrences, ComponentProcess)
		End If
	Next
End Sub

Sub ProcessComponent(oComp As ComponentOccurrence)
	If oComp Is Nothing OrElse oComp.Suppressed Then Return
	'If TypeOf oComp.Definition Is VirtualComponentDefinition Then Return 'could count these separate
	If TypeOf oComp.Definition Is WeldsComponentDefinition Then Return
	Select Case oComp.BOMStructure
	Case BOMStructureEnum.kNormalBOMStructure
		NormalCount = NormalCount + 1
	Case BOMStructureEnum.kReferenceBOMStructure
		ReferenceCount = ReferenceCount + 1
	Case BOMStructureEnum.kPurchasedBOMStructure
		PurchasedCount = PurchasedCount + 1
	Case BOMStructureEnum.kPhantomBOMStructure
		PhantomCount = PhantomCount + 1
	Case BOMStructureEnum.kInseparableBOMStructure
		InseparableCount = InseparableCount + 1
	Case BOMStructureEnum.kVariesBOMStructure
		VariesCount = VariesCount + 1
	End Select
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