Unknown iLogic error - VaultAccess

Unknown iLogic error - VaultAccess

Anonymous
Not applicable
1,928 Views
9 Replies
Message 1 of 10

Unknown iLogic error - VaultAccess

Anonymous
Not applicable

Why am I getting this error?  This happens after my code creates the rule, and it runs the rule.  The rule has nothing to do with Vault, at least not directly.

 

Error in rule: ClearanceCalcs, in document: C-16000-01.iam

Failed to create VaultAccess object.

System.InvalidOperationException: Failed to create VaultAccess object. ---> System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'VaultAddInLib.IVaultApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6796EC03-5DAB-4B0B-849B-41195C3429E8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at iLogic.VaultApplication..ctor(InventorServerObject app)
   at iLogic.VaultAccess..ctor(InventorServerObject app)
   at iLogic.ComponentInRule..ctor(Document rootDoc, InventorServerObject server)
   --- End of inner exception stack trace ---
   at iLogic.ComponentInRule..ctor(Document rootDoc, InventorServerObject server)
   at iLogic.RuleEvalContainer.GetOrCreateNamedProperty(NamedProperty property)
   at iLogic.RuleEvalContainer.GetCadComponent()
   at LmiRuleScript.SetHost(IRulesHost host)
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

        Dim strRuleClearanceCalcs As String = String.Empty
        ''create the ilogic rule below as ClearanceCalcs and add to save event
        strRuleClearanceCalcs = "Sub Main" & vbCrLf &
        "    RunClearanceCalcs()" & vbCrLf &
        "    GetCustomProperties()" & vbCrLf &
        "End Sub" & vbCrLf &
        "" & vbCrLf &
        "Public Sub RunClearanceCalcs()" & vbCrLf &
        "    Dim LoadComponent As String" & vbCrLf &
        "    Dim CarComponent As String" & vbCrLf &
        "    LoadComponent = ""LOAD""" & vbCrLf &
        "    CarComponent = ""CAR""" & vbCrLf &
        "    Parameter(""LoadWeight"") = iProperties.MassOfComponent(LoadComponent)" & vbCrLf &
        "    centerPt = iProperties.CenterOfGravity" & vbCrLf &
        "    Parameter(""CCOG"") = Round(centerPt.y, 1)" & vbCrLf &
        "    truckHalf = iProperties.Value(CarComponent, ""Custom"", ""HalfTruckCenter"")" & vbCrLf &
        "    Parameter(""TruckReactionLeft"") = ((TruckHalf - centerPt.x) / (2 * TruckHalf)) * iProperties.Mass" & vbCrLf &
        "    Parameter(""TruckReactionRight"") = ((TruckHalf + centerPt.x) / (2 * TruckHalf)) * iProperties.Mass" & vbCrLf &
        "    iProperties.Value(""Custom"", ""RailCar"") = iProperties.Value(CarComponent, ""Custom"", ""CarSeries"")" & vbCrLf &
        "    iProperties.Value(""Custom"", ""Specification"") = iProperties.Value(LoadComponent, ""Custom"", ""Specification"")" & vbCrLf &
        "    Parameter(""LoadLimit"") = iProperties.Value(CarComponent, ""Custom"", ""LoadLimit"")" & vbCrLf &
        "    Parameter(""LightWeight"") = iProperties.MassOfComponent(CarComponent)" & vbCrLf &
        "    Parameter(""FixtureWeight"") = iProperties.Mass - (iProperties.MassOfComponent(LoadComponent) + Parameter(""LightWeight""))" & vbCrLf &
        "    Parameter(""Axles"") = iProperties.Value(CarComponent, ""Custom"", ""Axles"")" & vbCrLf &
        "    iProperties.Value(""Custom"", ""PercentDifference"") = CStr(Round((Abs(Parameter(""TruckReactionLeft"") - Parameter(""TruckReactionRight"")) / iProperties.Mass) * 100, 1)) & ""%""" & vbCrLf &
        "    iProperties.Value(""Custom"", ""AxleLoadsLeft"") = CStr(Round((Abs(Parameter(""TruckReactionLeft"")) / Parameter(""Axles"") * 2) / 1000, 0)) & ""kip""" & vbCrLf &
        "    iProperties.Value(""Custom"", ""AxleLoadsRight"") = CStr(Round((Abs(Parameter(""TruckReactionRight"")) / Parameter(""Axles"") * 2) / 1000, 0)) & ""kip""" & vbCrLf &
        "End Sub" & vbCrLf &
        "" & vbCrLf &
        "Public Sub GetCustomProperties()" & vbCrLf &
        "    Dim LoadComponent As String" & vbCrLf &
        "    Dim sychronize As Boolean = False" & vbCrLf &
        "    LoadComponent = ""LOAD""" & vbCrLf &
        "    'for each custom iProperty in Load Component determine if car mod has them, and they are the same." & vbCrLf &
        "    compLoad = Component.InventorComponent(LoadComponent)" & vbCrLf &
        "    Dim propSet = compLoad.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(""Inventor User Defined Properties"")" & vbCrLf &
        "    Dim carPropSet = ThisDoc.Document.PropertySets.Item(""Inventor User Defined Properties"")" & vbCrLf &
        "    For Each prop In propSet" & vbCrLf &
        "        Dim propName As String = prop.Name" & vbCrLf &
        "        For Each carProp In carPropSet" & vbCrLf &
        "            If propName = ""FullTitle"" Or propName = ""NextAssembly"" Then Continue For" & vbCrLf &
        "            If carProp.Name = propName Then" & vbCrLf &
        "                'do something magical" & vbCrLf &
        "                If prop.Value <> carprop.Value Then" & vbCrLf &
        "                    If synchronize = False Then" & vbCrLf &
        "                        If MsgBox(""Sync Load Component Properties With This Document?"", MsgBoxStyle.YesNo) = vbYes Then" & vbCrLf &
        "                            synchronize = True" & vbCrLf &
        "                        Else" & vbCrLf &
        "                            Exit Sub" & vbCrLf &
        "                        End If" & vbCrLf &
        "                    End If" & vbCrLf &
        "                    If synchronize = True Then" & vbCrLf &
        "                        Try" & vbCrLf &
        "                            carProp.Value = prop.Value" & vbCrLf &
        "                        Catch" & vbCrLf &
        "                            MsgBox(""Can Not write iProperty "" & propName)" & vbCrLf &
        "                        End Try" & vbCrLf &
        "                    End If" & vbCrLf &
        "                End If" & vbCrLf &
        "            End If" & vbCrLf &
        "        Next" & vbCrLf &
        "    Next" & vbCrLf &
        "End Sub"

        Dim iLogAuto As Object 'Autodesk.iLogic.Interfaces.IiLogicAutomation
        iLogAuto = addin.Automation
        iLogAuto.CallingFromOutside = True
        iLogAuto.EnterDelayedRuleRunningMode()
        iLogAuto.AddRule(ClearanceModel, "ClearanceCalcs", strRuleClearanceCalcs)
        iLogAuto.ExitDelayedRuleRunningMode()
        iLogAuto.RulesOnEventsEnabled = True
        iLogAuto.CallingFromOutside = False
0 Likes
Accepted solutions (1)
1,929 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

I have noticed that the error only displays when the rule is created.  If i go to the post created rule manually and run the rule from the ilogic browser, it does not throw any error.

0 Likes
Message 3 of 10

Owner2229
Advisor
Advisor

Here you go. There've been missing highlighted lines.

 

	Dim ClearanceModel As Document
	ClearanceModel = ThisDoc.Document
	Dim strRuleClearanceCalcs As String = String.Empty
        ''create the ilogic rule below as ClearanceCalcs and add to save event
        strRuleClearanceCalcs = "Sub Main" & vbCrLf &
        "    RunClearanceCalcs()" & vbCrLf &
        "    GetCustomProperties()" & vbCrLf &
        "End Sub" & vbCrLf &
        "" & vbCrLf &
        "Public Sub RunClearanceCalcs()" & vbCrLf &
        "    Dim LoadComponent As String" & vbCrLf &
        "    Dim CarComponent As String" & vbCrLf &
        "    LoadComponent = ""LOAD""" & vbCrLf &
        "    CarComponent = ""CAR""" & vbCrLf &
        "    Parameter(""LoadWeight"") = iProperties.MassOfComponent(LoadComponent)" & vbCrLf &
        "    centerPt = iProperties.CenterOfGravity" & vbCrLf &
        "    Parameter(""CCOG"") = Round(centerPt.y, 1)" & vbCrLf &
        "    truckHalf = iProperties.Value(CarComponent, ""Custom"", ""HalfTruckCenter"")" & vbCrLf &
        "    Parameter(""TruckReactionLeft"") = ((TruckHalf - centerPt.x) / (2 * TruckHalf)) * iProperties.Mass" & vbCrLf &
        "    Parameter(""TruckReactionRight"") = ((TruckHalf + centerPt.x) / (2 * TruckHalf)) * iProperties.Mass" & vbCrLf &
        "    iProperties.Value(""Custom"", ""RailCar"") = iProperties.Value(CarComponent, ""Custom"", ""CarSeries"")" & vbCrLf &
        "    iProperties.Value(""Custom"", ""Specification"") = iProperties.Value(LoadComponent, ""Custom"", ""Specification"")" & vbCrLf &
        "    Parameter(""LoadLimit"") = iProperties.Value(CarComponent, ""Custom"", ""LoadLimit"")" & vbCrLf &
        "    Parameter(""LightWeight"") = iProperties.MassOfComponent(CarComponent)" & vbCrLf &
        "    Parameter(""FixtureWeight"") = iProperties.Mass - (iProperties.MassOfComponent(LoadComponent) + Parameter(""LightWeight""))" & vbCrLf &
        "    Parameter(""Axles"") = iProperties.Value(CarComponent, ""Custom"", ""Axles"")" & vbCrLf &
        "    iProperties.Value(""Custom"", ""PercentDifference"") = CStr(Round((Abs(Parameter(""TruckReactionLeft"") - Parameter(""TruckReactionRight"")) / iProperties.Mass) * 100, 1)) & ""%""" & vbCrLf &
        "    iProperties.Value(""Custom"", ""AxleLoadsLeft"") = CStr(Round((Abs(Parameter(""TruckReactionLeft"")) / Parameter(""Axles"") * 2) / 1000, 0)) & ""kip""" & vbCrLf &
        "    iProperties.Value(""Custom"", ""AxleLoadsRight"") = CStr(Round((Abs(Parameter(""TruckReactionRight"")) / Parameter(""Axles"") * 2) / 1000, 0)) & ""kip""" & vbCrLf &
        "End Sub" & vbCrLf &
        "" & vbCrLf &
        "Public Sub GetCustomProperties()" & vbCrLf &
        "    Dim LoadComponent As String" & vbCrLf &
        "    Dim sychronize As Boolean = False" & vbCrLf &
        "    LoadComponent = ""LOAD""" & vbCrLf &
        "    'for each custom iProperty in Load Component determine if car mod has them, and they are the same." & vbCrLf &
        "    compLoad = Component.InventorComponent(LoadComponent)" & vbCrLf &
        "    Dim propSet = compLoad.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(""Inventor User Defined Properties"")" & vbCrLf &
        "    Dim carPropSet = ThisDoc.Document.PropertySets.Item(""Inventor User Defined Properties"")" & vbCrLf &
        "    For Each prop In propSet" & vbCrLf &
        "        Dim propName As String = prop.Name" & vbCrLf &
        "        For Each carProp In carPropSet" & vbCrLf &
        "            If propName = ""FullTitle"" Or propName = ""NextAssembly"" Then Continue For" & vbCrLf &
        "            If carProp.Name = propName Then" & vbCrLf &
        "                'do something magical" & vbCrLf &
        "                If prop.Value <> carprop.Value Then" & vbCrLf &
        "                    If synchronize = False Then" & vbCrLf &
        "                        If MsgBox(""Sync Load Component Properties With This Document?"", MsgBoxStyle.YesNo) = vbYes Then" & vbCrLf &
        "                            synchronize = True" & vbCrLf &
        "                        Else" & vbCrLf &
        "                            Exit Sub" & vbCrLf &
        "                        End If" & vbCrLf &
        "                    End If" & vbCrLf &
        "                    If synchronize = True Then" & vbCrLf &
        "                        Try" & vbCrLf &
        "                            carProp.Value = prop.Value" & vbCrLf &
        "                        Catch" & vbCrLf &
        "                            MsgBox(""Can Not write iProperty "" & propName)" & vbCrLf &
        "                        End Try" & vbCrLf &
        "                    End If" & vbCrLf &
        "                End If" & vbCrLf &
        "            End If" & vbCrLf &
        "        Next" & vbCrLf &
        "    Next" & vbCrLf &
        "End Sub"
        Dim iLogAuto As Object 'Autodesk.iLogic.Interfaces.IiLogicAutomation
	Dim addIn As Object 'ApplicationAddIn
	addIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
        addIn.Activate
        iLogAuto = addin.Automation
        iLogAuto.CallingFromOutside = True
        iLogAuto.EnterDelayedRuleRunningMode()
        iLogAuto.AddRule(ClearanceModel, "ClearanceCalcs", strRuleClearanceCalcs)
        iLogAuto.ExitDelayedRuleRunningMode()
        iLogAuto.RulesOnEventsEnabled = True
        iLogAuto.CallingFromOutside = False
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 4 of 10

Anonymous
Not applicable
        Dim iLogicAddInGUID As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
        Dim addin As Inventor.ApplicationAddIn = Nothing
        Try
            addin = invApp.ApplicationAddIns.ItemById(iLogicAddInGUID)
        Catch ex As Exception
            MsgBox("Unable to load iLogic Add In")
        End Try
        If Not addin.Activated Then
            addin.Activate()
        End If

yea i already had those lines, and since they were common place, I didn't post them.  So whats the real problem here?

 

0 Likes
Message 5 of 10

Owner2229
Advisor
Advisor

After adding these lines it worked correctly for me, so I have no idea what's the issue.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 6 of 10

Owner2229
Advisor
Advisor

Do you have set the refference to the model as well?

 

Dim ClearanceModel As Document
ClearanceModel = ThisDoc.Document

Try using the code I posted with:

Dim addIn As Object

instead of:

Dim addin As Inventor.ApplicationAddIn

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 10

Anonymous
Not applicable

ClearanceModel is globally defined and set way early in the process when it was first created by this program.  Also this is VB.Net to ThisDoc is not an object i use.

0 Likes
Message 8 of 10

Anonymous
Not applicable

Another interesting development, I took Inventor off of the vault project and put in back into default (as shipped with program, empty) and the error goes away.  This is a bug.  It is directly related to having a vaulted project active (designs.ipj)  I will attach my ipj for the fun of it.  BTW I use Vault Professional 2016 with all updates at build: 21.1.4.0 (Update 1)

0 Likes
Message 9 of 10

wayne.brill
Collaborator
Collaborator

Hi Jamie,

 

Do you have to run the rule when it is created?

 

If not then this could be a work around. The AddRule will create a rule with no text and run it. Then its Text is set to the actual rule text, but the rule is not run. When I try this with a simplified version of your code the error goes away.

 

>> >>

Replace:
        iLogAuto.AddRule(ClearanceModel, "ClearanceCalcs", strRuleClearanceCalcs)

 

with

 

      Dim newRule As Object = iLogAuto.AddRule(ClearanceModel, "ClearanceCalcs", "")
      newRule.Text = strRuleClearanceCalcs
<< <<

 

When I was testing I found that the error would occur just having this code for the rule:

        Dim strRuleClearanceCalcs As String = String.Empty

       strRuleClearanceCalcs = "    Dim LoadComponent As String" & vbCrLf &

           "    LoadComponent = ""LOAD:1""" & vbCrLf &

           "    compLoad = Component.InventorComponent(LoadComponent)"

 

 

Thanks to a colleague in Inventor Engineering for this idea to work around this behavior.

-Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 10 of 10

Anonymous
Not applicable
Accepted solution

Wayne, thank you kindly,

 

I was able to implement your work around successfully, AND to get the code to run itself without error, I put it within an event trigger, here is my final, and feel free to show the world:

 

‘… other setup code (ends at rule string assignment)…then this iLogic rule code:

    Public Sub CreateiLogicRuleClearanceCalcs()
        ‘… other code to create text for rule
        invApp.SilentOperation = True ‘don’t know if this has any real effect here, may not be necessary.
        Dim iLogAuto As Object 'Autodesk.iLogic.Interfaces.IiLogicAutomation
        iLogAuto = addin.Automation
        iLogAuto.CallingFromOutside = True
        iLogAuto.EnterDelayedRuleRunningMode()
        Dim newRule As Object = iLogAuto.AddRule(ClearanceModel, "ClearanceCalcs", "")
        newRule.text = strRuleClearanceCalcs
        iLogAuto.ExitDelayedRuleRunningMode()
        iLogAuto.RulesOnEventsEnabled = True
        'iLogAuto.RunRule(ClearanceModel, "ClearanceCalcs")
        'iLogAuto.CallingFromOutside = False
        AssignRuleToILogicEvent(ClearanceModel, "ClearanceCalcs", "BeforeDocSave0", 700)
        invApp.SilentOperation = False
    End Sub

    Public Sub AssignRuleToILogicEvent(invDoc As Inventor.Document, ruleName As String, strEvent As String, strID As String)
        Dim customiPropSet As PropertySet = Nothing
        For Each propSet As PropertySet In invDoc.PropertySets
            If propSet.Name = "iLogicEventsRules" Then
                customiPropSet = propSet
                Exit For
            End If
            If propSet.Name = "_iLogicEventsRules" Then
                customiPropSet = propSet
                Exit For
            End If
        Next
        If customiPropSet IsNot Nothing Then
            If customiPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
                customiPropSet.Delete()
                customiPropSet = invDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
            End If
        End If
        If customiPropSet Is Nothing Then
            customiPropSet = invDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
        End If
        If customiPropSet Is Nothing Then
            MsgBox("Unable to create event triggers for this file.",, "Event Triggers")
        End If
        If customiPropSet IsNot Nothing Then customiPropSet.Add(ruleName, strEvent, strID)
    End Sub

At the end I call save document and it runs the rule without error.  There have been quite a few looking to consolidate these two routines.  Obviously the code should not be calling a vault error in the first place, but with this work around, where the iLogic is not run by the api, but rather by the save events of the document itself, the problem is resolved. 

 

 

Thanks,

0 Likes