Message 2 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.