ilogic rule message box elimination - requires ilogic rule editing knowledge

ilogic rule message box elimination - requires ilogic rule editing knowledge

sguan1212
Enthusiast Enthusiast
2,425 Views
10 Replies
Message 2 of 11

ilogic rule message box elimination - requires ilogic rule editing knowledge

sguan1212
Enthusiast
Enthusiast

Anyone who can help please. It will require ilogic rule editing knowledge.
The below ilogic rule copies the QTY in the bom and paste it into individual parts custom property which then allow the QTY to be pickup up by a label
The problem is every time it is ran, a message box pops up. I want to make this message box not appear, can this be done???

Rule is below and image of the message box is attached. 

I found this rule from the internet

 

Sub Main ()

'get the project number of this assembly and use it to build the name of a custom property, i.e. "4100_QTY"
customPropertyName = "QTY REQ"

    oQ=MessageBox.Show(customPropertyName, "Run Qty Generator",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
        If oQ=vbYes
        oDone()
        ElseIf oQ=vbNo
        Call oProject
        ElseIf oQ=vbCancel
        MessageBox.Show("Cancelled", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
        Return
    End If
End Sub


Sub oDone
oCompDef = ThisDoc.Document.ComponentDefinition
openDoc = ThisDoc.Document
customPropertyName = "Qty REQ"
'Let's open the document that inventor has in focus right now
 

'Let's check to make sure that it's an assembly document.'We don't want to run this on just a part document as it -'will have none of the required information! 
If openDoc.DocumentType = kAssemblyDocumentObject Then  
    
    'If it is an assembly document, then we need to get a collection
    'of all the documents that are associated to it. 
    'the following line actually does that, while at the time time
    'starts the loop to look at each one of those documents. 
    
    'imagine that it's written out in this way : 
    'For each Document file in the collection of ALL the document
    'files that are in this open document, do the stuff below... 
    For Each docFile In openDoc.AllReferencedDocuments
        
        'First thing first, we need to make a string that can represent the 
        'document that we're working on. This way it will be easier to 
        'call on that document when we want to make changes to the iproperties. 
        'this is no different than if you just typed out : 
        '        'iProperties.Value("Part_Name_Here.ipt", "Project", "Authority") 
        '        'But because we are doing this dynamically, we don't have to type that 
        'about line out for every single part that is in the document. 
        '        'FNamePos is getting the number of spaces that it takes to get to the 
        'very last back slash in the full file name of our document.         
        FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        
        'We can then take that number (position) and use it to cut off all of the 
        'file path that we don't need. In this case, it's the front of the path
        'that we're getting rid of, leaving us with just the file name.
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        'Let's make sure that we can even change this part. If we can, then we'll continue. 
        If docFile.IsModifiable = True Then
            
            'Because you can only grab the occurrences from an assembly document
            'we need to fill up that empty AssemblyDocument container with an object
            'that we know is definitely an assembly document. Because that was one
            'of the first checks we made up there on this open document, we can safely
            'declare that assemblyDoc (Which is an AssemblyDocument) is equal to 
            ' openDoc (Which is just a regular old Document)             
            assemblyDoc = openDoc        
            
            'While we're at it, let's go on and define the empty ComponentDefinition container
            '(we named ours assemblyDef) with some sort of content. 
            assemblyDef = assemblyDoc.ComponentDefinition
            
            'Now we need to collect every instance of the document against
            'our open assembly and put them all inside of partQty. 
            partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
            
                'Now that we have our collection of instances, we need to populate
                'our target iproperty with the total amount. 
                
                'Instead of just throwing that amount in there, let's make sure that
                'the value inside of the target iProperty isn't already equal to our count. 
                'If it is equal, then we don't have to change anything (which saves us time!),
                'but if it isn't equal then we will need to change it. 
                
                'The Try statement is here because of the next if statement ---
                '                'If partQty.Count <>  iProperties.Value(docFName, "Project", "Authority") Then'
                '                'If we just compare the two values, there is a small chance that our target
                'iProperty is already set to something that is NOT a number, which would create
                'an error (as you can't compare numbers against things that aren't numbers). 
                'So, we TRY to complete that if statement, and if there is an error (The CATCH)
                'we just force that target to equal our part qty total. 
                Try
                        If partQty.Count <>  iProperties.Value(docFName, "Custom", customPropertyName) Then                
                        iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                    End If                      
                    Catch
                    iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                End Try
        End If
    Next
Else

'This is here to warn the user that they are attempting to run this in a document that is invalid!'we don't want them running things that aren't correct! Force them to obey! 
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 
iLogicVb.UpdateWhenDone = True 

End Sub

Sub oProject
    oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
    iProperties.Value("Project", "Project")=oProj
    Main ()
End Sub
 

 

0 Likes
Accepted solutions (1)
2,426 Views
10 Replies
Replies (10)
Message 1 of 11

sguan1212
Enthusiast
Enthusiast

Anyone who can help please. It will require ilogic rule editing knowledge.
The below ilogic rule copies the QTY in the bom and paste it into individual parts custom property which then allow the QTY to be pickup up by a label
The problem is every time it is ran, a message box pops up. I want to make this message box not appear, can this be done???

Rule is below and image of the message box is attached. 

I found this rule from the internet

 

Sub Main ()

'get the project number of this assembly and use it to build the name of a custom property, i.e. "4100_QTY"
customPropertyName = "QTY REQ"

    oQ=MessageBox.Show(customPropertyName, "Run Qty Generator",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question)
        If oQ=vbYes
        oDone()
        ElseIf oQ=vbNo
        Call oProject
        ElseIf oQ=vbCancel
        MessageBox.Show("Cancelled", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
        Return
    End If
End Sub


Sub oDone
oCompDef = ThisDoc.Document.ComponentDefinition
openDoc = ThisDoc.Document
customPropertyName = "Qty REQ"
'Let's open the document that inventor has in focus right now
 

'Let's check to make sure that it's an assembly document.'We don't want to run this on just a part document as it -'will have none of the required information! 
If openDoc.DocumentType = kAssemblyDocumentObject Then  
    
    'If it is an assembly document, then we need to get a collection
    'of all the documents that are associated to it. 
    'the following line actually does that, while at the time time
    'starts the loop to look at each one of those documents. 
    
    'imagine that it's written out in this way : 
    'For each Document file in the collection of ALL the document
    'files that are in this open document, do the stuff below... 
    For Each docFile In openDoc.AllReferencedDocuments
        
        'First thing first, we need to make a string that can represent the 
        'document that we're working on. This way it will be easier to 
        'call on that document when we want to make changes to the iproperties. 
        'this is no different than if you just typed out : 
        '        'iProperties.Value("Part_Name_Here.ipt", "Project", "Authority") 
        '        'But because we are doing this dynamically, we don't have to type that 
        'about line out for every single part that is in the document. 
        '        'FNamePos is getting the number of spaces that it takes to get to the 
        'very last back slash in the full file name of our document.         
        FNamePos = InStrRev(docFile.FullFileName, "\", -1)        
        
        'We can then take that number (position) and use it to cut off all of the 
        'file path that we don't need. In this case, it's the front of the path
        'that we're getting rid of, leaving us with just the file name.
        docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
        
        'Let's make sure that we can even change this part. If we can, then we'll continue. 
        If docFile.IsModifiable = True Then
            
            'Because you can only grab the occurrences from an assembly document
            'we need to fill up that empty AssemblyDocument container with an object
            'that we know is definitely an assembly document. Because that was one
            'of the first checks we made up there on this open document, we can safely
            'declare that assemblyDoc (Which is an AssemblyDocument) is equal to 
            ' openDoc (Which is just a regular old Document)             
            assemblyDoc = openDoc        
            
            'While we're at it, let's go on and define the empty ComponentDefinition container
            '(we named ours assemblyDef) with some sort of content. 
            assemblyDef = assemblyDoc.ComponentDefinition
            
            'Now we need to collect every instance of the document against
            'our open assembly and put them all inside of partQty. 
            partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)
            
                'Now that we have our collection of instances, we need to populate
                'our target iproperty with the total amount. 
                
                'Instead of just throwing that amount in there, let's make sure that
                'the value inside of the target iProperty isn't already equal to our count. 
                'If it is equal, then we don't have to change anything (which saves us time!),
                'but if it isn't equal then we will need to change it. 
                
                'The Try statement is here because of the next if statement ---
                '                'If partQty.Count <>  iProperties.Value(docFName, "Project", "Authority") Then'
                '                'If we just compare the two values, there is a small chance that our target
                'iProperty is already set to something that is NOT a number, which would create
                'an error (as you can't compare numbers against things that aren't numbers). 
                'So, we TRY to complete that if statement, and if there is an error (The CATCH)
                'we just force that target to equal our part qty total. 
                Try
                        If partQty.Count <>  iProperties.Value(docFName, "Custom", customPropertyName) Then                
                        iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                    End If                      
                    Catch
                    iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count
                End Try
        End If
    Next
Else

'This is here to warn the user that they are attempting to run this in a document that is invalid!'we don't want them running things that aren't correct! Force them to obey! 
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 
iLogicVb.UpdateWhenDone = True 

End Sub

Sub oProject
    oProj = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
    iProperties.Value("Project", "Project")=oProj
    Main ()
End Sub
 

 

0 Likes
Message 3 of 11

MechMachineMan
Advisor
Advisor
Accepted solution

Don't be scared - It's actually just the english language written and indented in a weird format.

 

Below is the modified code. I removed all of the comments that dictate what each line is doing, as each line is just plain english.

 

You MUST understand that the way this rule is coded, if you have parts that have the BOM Structure set to reference, their count WILL STILL be included in the quantity that this code spits out.

 

Therefore, a pre-requisite to using this code to ensure there are no errors is to remove ALL reference parts from your model.

 

The alternative is to find/use different code that properly handles reference documents.

 

Also, iLogic/API questions are better suited for the Inventor Customization Forums

 

Sub Main()
    customPropertyName = "Qty REQ"
openDoc = ThisDoc.Document assemblyDef = openDoc.ComponentDefinition If openDoc.DocumentType = kAssemblyDocumentObject Then For Each docFile In openDoc.AllReferencedDocuments

'Convert file name & path into filename. ie; C:\file.ipt -> file.ipt FNamePos = InStrRev(docFile.FullFileName, "\", -1) docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos) If docFile.IsModifiable = True Then partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile) Try If partQty.Count <> iProperties.Value(docFName, "Custom", customPropertyName) Then iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count End If Catch iProperties.Value(docFName, "Custom", customPropertyName) = partQty.Count End Try End If Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If
iLogicVb.UpdateWhenDone = True End Sub

 


--------------------------------------
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
Message 4 of 11

rhasell
Advisor
Advisor

Hi

 

@MechMachineMan, thanks for cleaning it up.

 

This is actually my code, (Which I got from the forums, and modified it to suit my needs.)

 

What is happening, it,  the original code is checking the Project number, and was placing the project number in the "QTY REQ" field.

 

The OP has removed this section of the code, but left the message box, which you have taken out for him. (The original "Sub Main")

 

What is going to happen now,  @sguan1212, you will most probably need to put something back into the rule to distinguish common parts from one another.

 

If you never re-use a part from one model to the next, well then you don't have a problem.

 

EG:

"Cleat A" is used 50 times in "GA - Assembly 01"

but

the same "Cleat A" is only used 12 times in "GA - Assembly 02"

 

If you run the code a second time in "GA - Assembly 02" it will overwrite the QTY requirements of "GA - Assembly 01"

 

So all drawing referencing "GA - Assembly 01" - 'Cleat A" will update with the incorrect value of 12 instead of 50.

 

Reg
2026.1
Message 5 of 11

Xun.Zhang
Alumni
Alumni

Hello,

 

The code sounds correct to me, not sure the reason yet.

@JaneFan, do you have any comments to share?

 

Thanks!


Xun
0 Likes
Message 6 of 11

sguan1212
Enthusiast
Enthusiast

Hi MechMachineMan, 

Thank you very much for your help. It worked brilliantly.

I have this rule triggered at save. The problem with this message box is when you are at the very top assembly level, it triggers all the rules in the sub-assemblies as well, which means this message box pop up as many times as the amount of sub-assemblies there are. 

 

Thanks for informing me about the fact that this QTY generator also counts the reference components. 

I'm not too familiar with the forum, I will make sure to post the correct topic in the right area.

Cheers..

Sean

0 Likes
Message 7 of 11

sguan1212
Enthusiast
Enthusiast

Hi Rhasell,

I believe the ilogic rule did in fact came from 1 of the post which involves you.

Thank you for sharing it. It is treasure.

 

And thank you for informing me that the QTY can be overwritten when the part is used in another assembly. I was made aware of this earlier.

Cheers..

Sean

Message 8 of 11

rhasell
Advisor
Advisor

Pleasure mate.

 

That's what it is all about.

 

Reg
2026.1
0 Likes
Message 9 of 11

sguan1212
Enthusiast
Enthusiast

Hi MechMachineMan,

I don't know if you can help me with this one. Or maybe i'm suppose to begin a new post.

I want to create another custom property in the parts file as BOM number, and using a similar rule to grab the balloon numbers from the BOM and spit it into the custom properties . This mean I have both the QTY & BOM number at my disposal, and i can use it on a label or symbol. 

To do this, I'm thinking i can create another rule for the BOM number, or have both of this rules merged into 1 rule.

 

Is this doable?

0 Likes
Message 10 of 11

MechMachineMan
Advisor
Advisor

Isn't that the same thing as the Item number iProperty as listed in the BOM?


--------------------------------------
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 11 of 11

sguan1212
Enthusiast
Enthusiast

It is indeed the item no. 

on the drawing level this item no. (balloon no.) only comes through from the parts list. And this item no. only belongs in the assembly.

I want this item number to be duplicated into individual parts iproperties, that way i can call it up using a leader, label or symbols. Similar to the QTY generator which is already sorted, I now would like have a BOM Number generator

 

0 Likes