I have an iLogic rule in an assembly file which shrinkwraps the model and is triggered by the Close Document event.
Problem is the message box also appears when the drawing sheet containing views of this model is closed.
Can an iLogic be written to only run the rule when the active document in the graphics is the same document that contains the rule?
I have been able to write an iLogic which runs the rule only when the active document is an assembly file but I would like to change this to be the specific file that contains the rule.
My current rule is as follows:
Sub Main() Try Dim oDoc As Document = ThisApplication.ActiveDocument If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub Else Question = MessageBox.Show("Do you wish to shrinkwrap the Fan Drive Assembly now for use in the General Arrangement?", "Fan Drive Assembly",MessageBoxButtons.YesNo) If Question = vbYes Then Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("GA - FAN ASSEMBLY VIEW").Activate Try Dim g_App As Inventor.InventorServer = ThisApplication Dim AssDoc as Inventor.AssemblyDocument= ThisDoc.Document ' Create a new part document that will be the shrinkwrap substitute Dim oPartDoc As PartDocument oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True) Dim oPartDef As PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition Dim oDerivedAssemblyDef As DerivedAssemblyDefinition oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName) ' Set various shrinkwrap related options oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone) Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone) Dim oDerivedAss As DerivedAssemblyComponent oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef) Call oDerivedAss.BreakLinkToFile() ' Save the part Dim partname As String=ThisDoc.PathAndFileName(False)& " (SHRINKWRAPPED).ipt" ThisApplication.ActiveView.Fit ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute Call oPartDoc.SaveAs(partname , False) Catch ex As Exception ErrorMessage = "Error creating ipt file." End Try oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate Else 'Do Nothing End If End If Catch End Try End Sub
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Hi @kwalker1,
Please try the following iLogic rule. In this, iLogic rule should be mentioned while implementing(Highlighted in red color).
Sub Main() Try Dim oDoc As Document = ThisApplication.ActiveDocument Dim iLogicAuto As Object iLogicAuto = GetiLogicAddin(ThisApplication) If iLogicAuto Is Nothing Then Exit Sub End If Dim rule As Object rule = iLogicAuto.GetRule(doc, "Rule Name") If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Or rule Is Nothing Then Exit Sub Else Question = MessageBox.Show("Do you wish to shrinkwrap the Fan Drive Assembly now for use in the General Arrangement?", "Fan Drive Assembly",MessageBoxButtons.YesNo) If Question = vbYes Then Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("GA - FAN ASSEMBLY VIEW").Activate Try Dim g_App As Inventor.InventorServer = ThisApplication Dim AssDoc as Inventor.AssemblyDocument= ThisDoc.Document ' Create a new part document that will be the shrinkwrap substitute Dim oPartDoc As PartDocument oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True) Dim oPartDef As PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition Dim oDerivedAssemblyDef As DerivedAssemblyDefinition oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName) ' Set various shrinkwrap related options oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone) Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone) Dim oDerivedAss As DerivedAssemblyComponent oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef) Call oDerivedAss.BreakLinkToFile() ' Save the part Dim partname As String=ThisDoc.PathAndFileName(False)& " (SHRINKWRAPPED).ipt" ThisApplication.ActiveView.Fit ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute Call oPartDoc.SaveAs(partname , False) Catch ex As Exception ErrorMessage = "Error creating ipt file." End Try oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate Else 'Do Nothing End If End If Catch End Try End Sub
Please feel free to contact if there is any doubt.
If solve problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
If you are running this as a rule, in the iLogic environment, changing this:
Dim oDoc As Document = ThisApplication.ActiveDocument If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub Else
to this:
Dim oDoc As Document = ThisApplication.ActiveDocument If Not oDoc Is ThisDoc.Document Then Exit Sub
should work just fine.
Hi Chandra,
Thank you for your reply.
I have tried the modified code that you posted but I get the following error message:
Error on Line 6 : 'GetiLogicAddin' is not declared. It may be inaccessible due to its protection level.
I have not personally come across code with the GetiLogicAddin so I tried searching for it in the API Help to better understand it. But I can seem to get any results when searching for it in the help dialogue box.
Regards,
Kurt.
Hi Justin,
Thank you very much for your reply.
I thought I was getting close with different variations of my code but just couldn't seem to get it right.
I've tried your suggestion and it is working perfectly.
My sincere thanks for your assistance.
Regards,
Kurt.