I just re-enabled the event triggers, since I turned them off 2 months ago. I had actually forgot about this problem. I enabled my rules on everyone else PC's and I'm already getting complaints from other people that their Inventor browsers are acting weird and not highlighting or selecting after a short time. I have 5 different rules being triggered at different times. Can anyone see anything in the rules that would cause this erratic behavior in the Inventor browser? Here are the rules:
Rule 1:
iLogicVb.Automation.ParametersXmlLoad(ThisDoc.Document, "L:\Autodesk Software\iLogic Rules\NuTec M_P_S Custom Parameter.xml")
iLogicForm.ShowGlobal("NuTec (M,P,S)", FormMode.Modal)
'This calls the current value of the M_P_S parameter and truncates the value to 1 character
iProperties.Value("Custom", "Mfg, Purchase, Stock") = Left(Parameter("M_P_S"), 1)
'This changes the BOM Structure for this assembly to Purchased if M_P_S = P (Purchased)
'Else it changes the BOM Structure to Normal
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
If Parameter("M_P_S") = "P (Purchased)" Then
oAsmDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
Else
oAsmDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
End If
InventorVb.DocumentUpdate()
Rule 2:
If iProperties.Value("Summary", "Category") = "FASTENERS" Then
MessageBox.Show("This is a FASTENER", "M,P,S")
Return 'Do nothing
Else
'Import custom M_P_S Parameter
MessageBox.Show("This is NOT a FASTENER", "M,P,S")
iLogicVb.Automation.ParametersXmlLoad(ThisDoc.Document, "L:\Autodesk Software\iLogic Rules\NuTec M_P_S Custom Parameter.xml")
iLogicForm.ShowGlobal("NuTec (M,P,S)", FormMode.Modal)
'This calls the current value of the M_P_S parameter and truncates the value to 1 character
iProperties.Value("Custom", "Mfg, Purchase, Stock") = Left(Parameter("M_P_S"), 1)
'This changes the BOM Structure for this part to Purchased if M_P_S = P (Purchased)
'Else it changes the BOM Structure to Normal
Dim oPrtDoc As PartDocument = ThisApplication.ActiveDocument
If Parameter("M_P_S") = "P (Purchased)" Then
oPrtDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
Else
oPrtDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
End If
End If
InventorVb.DocumentUpdate()
Rule 3:
''' <summary>
''' Will only run if the activedocument has been saved.
''' </summary>
Sub Main()
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Export and Attach Step file")
If Parameter("M_P_S") = "P (Purchased)" Then
trans.Abort()
ElseIf Not iProperties.Value("Project", "Part Number") = "" Then
Dim filenameToAttach As String = ExportToStep()
If Not filenameToAttach = String.Empty Then
Dim doc As Document = ThisApplication.ActiveDocument
AddReferences(doc, filenameToAttach)
End If
Else
MessageBox.Show("NuTec Part Number is blank...Cannot save the .stp file","Error Saving File")
trans.Abort()
End If
End Sub
''' <summary>
''' Returns an empty string if the stp file didn't save for some reason.
''' </summary>
''' <returns></returns>
Function ExportToStep() As String
Dim filename As String
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim Rev As String
If iProperties.Value("Project", "Revision Number") = "-" Then
Rev = "_0"
ElseIf iProperties.Value("Project", "Revision Number") = "" Then
Rev = ""
ElseIf Not iProperties.Value("Project", "Revision Number") = "-" Or iProperties.Value("Project", "Revision Number") = "" Then
Rev = "_" & iProperties.Value("Project", "Revision Number")
End If
oStepFileName = iProperties.Value("Project", "Part Number") & Rev
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
' Other options...
'oOptions.Value("Author") = ""
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = ""
'oOptions.Value("Organization") = ""
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = ThisDoc.Path & "\" & oStepFileName & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
filename = oData.FileName
End If
If System.IO.File.Exists(filename) Then
Return filename
Else
Return ""
End If
End Function
''' <summary>
''' Attaches any file using the full c:\path\to\your\file.extension format.
''' </summary>
''' <param name="odoc"></param>
''' <param name="selectedfile"></param>
Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String)
Dim oleReference As ReferencedOLEFileDescriptor
'This deletes any previously attached .stp files before attaching a new .stp file
For Each oleReference In odoc.ReferencedOLEFileDescriptors
Call oleReference.Delete()
Next
If selectedfile.Contains("|") Then ' we have multiple files selected.
Dim file As String() = selectedfile.Split("|")
For Each s As String In file
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1)
Next
Else
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(selectedfile,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
End If
End Sub
Rule 4:
''' <summary>
''' Will only run if the activedocument has been saved.
''' </summary>
Sub Main()
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Export and Attach Stl file")
If Parameter("M_P_S") = "P (Purchased)" Then
trans.Abort()
ElseIf Not iProperties.Value("Project", "Part Number") = "" Then
Dim filenameToAttach As String = ExportToStl()
If Not filenameToAttach = String.Empty Then
Dim doc As Document = ThisApplication.ActiveDocument
AddReferences(doc, filenameToAttach)
End If
Else
MessageBox.Show("NuTec Part Number is blank...Cannot save the .stl file","Error Saving File")
trans.Abort()
End If
End Sub
''' <summary>
''' Returns an empty string if the stl file didn't save for some reason.
''' </summary>
''' <returns></returns>
Function ExportToStl() As String
Dim filename As String
' Get the STL translator Add-In.
Dim STLAddIn As TranslatorAddIn
STLAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim Rev As String
If iProperties.Value("Project", "Revision Number") = "-" Then
Rev = "_0"
ElseIf iProperties.Value("Project", "Revision Number") = "" Then
Rev = ""
ElseIf Not iProperties.Value("Project", "Revision Number") = "-" Or iProperties.Value("Project", "Revision Number") = "" Then
Rev = "_" & iProperties.Value("Project", "Revision Number")
End If
oStlFileName = iProperties.Value("Project", "Part Number") & Rev
' Check whether the translator has 'SaveCopyAs' options
If STLAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("OutputFileType") = 0 ' 0 = Binary , 1 = ASCII
oOptions.Value("ExportUnits") = 2 ' INCH = 2 , FOOT = 3 , CENTIMETER = 4 , MILLIMETER = 5 , METER = 6 , MICRON = 7
oOptions.Value("Resolution") = 0 ' HIGH = 0 , MEDIUM = 1 , LOW = 2 , CUSTOM = 3 , BREP = 4
oOptions.Value("ExportColor") = False
End If
'Set the destination file name
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = ThisDoc.Path & "\" & oStlFileName & ".stl"
STLAddIn.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
filename = oData.FileName
If System.IO.File.Exists(filename) Then
Return filename
Else
Return ""
End If
End Function
''' <summary>
''' Attaches any file using the full c:\path\to\your\file.extension format.
''' </summary>
''' <param name="odoc"></param>
''' <param name="selectedfile"></param>
Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String)
Dim oleReference As ReferencedOLEFileDescriptor
If selectedfile.Contains("|") Then ' we have multiple files selected.
Dim file As String() = selectedfile.Split("|")
For Each s As String In file
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1)
Next
Else
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(selectedfile,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
End If
End Sub
Rule 5:
'This calls the current value of the MASS Inventor property and truncates the value to 2 decimals
iProperties.Value("Custom", "Weight (lb)") = Round(iProperties.Mass,2)
InventorVb.DocumentUpdate()