Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am writing code to test a multitude situations. This code gets a parameter that will be changed; then pick a random number to put in that parameter; then run the ilogic rules in the assembly to process the new parameter value. I hope I didn't leave anything out and more importantly that, that made sense. The part that keeps failing is when I try and set up ilogic automation. It's a piecemeal from a couple of other posts that I can't figure out. The section of code I am struggling with is in region:"establish doc rules" under comment:"define ilogic automation vehicle".
Can you help?!?
P.S. I am aware that the loops are infinite, this is by design.
Imports System
Imports System.Type
Imports System.Activator
Imports SysInter = System.Runtime.InteropServices
Imports System.IO
Imports Inv = Inventor
Imports iLogic = Autodesk.iLogic
Imports Excel = Microsoft.Office.Interop.Excel
Public Sub RunStiffeners()
'get inventor session
Dim InvApp As Inv.Application = SysInter.Marshal.GetActiveObject("Inventor.Application")
Dim InvDoc As Inv.AssemblyDocument = InvApp.ActiveDocument
'Dim InvDoc As Inv.AssemblyDocument = Thisdoc.Document
'Get the part user parameters
Dim AssyUserParameters As Inv.UserParameters = InvDoc.ComponentDefinition.Parameters.UserParameters
Dim AssyModelParameters As Inv.ModelParameters = InvDoc.ComponentDefinition.Parameters.ModelParameters
Console.Write("Got Paramters" & vbNewLine & "User Parameter qty: " & AssyUserParameters.Count & vbNewLine & "Model Parameter qty: " & AssyModelParameters.Count & vbNewLine)
Console.Write(vbNewLine)
#Region "Define UOM"
'Inventor stores background units in metric, need this to convert back to SI
Dim UoM As Inv.UnitsOfMeasure = InvDoc.UnitsOfMeasure
#End Region
#Region "User Parameters"
Dim StiffFBQty As Inv.UserParameter = Nothing
For Each RParam As Inv.UserParameter In AssyUserParameters
If RParam.Name = "STIFF_EXT_F_B_QTY" Then
StiffFBQty = RParam
Console.Write(StiffFBQty.Name & " : " & StiffFBQty.Expression & vbNewLine)
End If
Next
Console.Write(vbNewLine)
#End Region
#Region "Establish document rules"
'iLogic rule names
Dim iLPushParam As String = "Push Parameters to Components"
Dim iLStiffs As String = "Stiffeners"
'Define iLogic Automation vehicle
Dim addinGUID As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
Dim addin As Inv.ApplicationAddIn = InvApp.ApplicationAddIns.ItemById(addinGUID)
Dim iLogicAuto As iLogic.Automation.iLogicAutomation
If addin IsNot Nothing Then
addin.Activate()
iLogicAuto = addin.Automation
End If
'Establish the ilogic rules
Dim iLRulePushParam As iLogic.Interfaces.iLogicRule = iLogicAuto.GetRule(InvDoc, iLPushParam)
Dim iLRuleStiffs As iLogic.Interfaces.iLogicRule = iLogicAuto.GetRule(InvDoc, iLStiffs)
#End Region
#Region "Change Qty and run rules"
Dim SleepValue As Integer = 15000
Do While 0 < 3
'randomly select a numnber from the stiff qty list and change the qty parameter
Do While 0 < 3 : Dim RandomNum As New Random : Dim NewStiffQty As Integer = RandomNum.Next(0, 10) : Select Case NewStiffQty : Case 0, 2, 4, 6, 8, 10 : StiffFBQty.Expression = NewStiffQty : Exit Do : End Select : Loop
Console.WriteLine("New Stiffener Qty: " & StiffFBQty.Value)
'Run the rules
iLogicAuto.RunRuleDirect(iLRuleStiffs)
iLogicAuto.RunRuleDirect(iLRulePushParam)
InvDoc.Update()
'pause code to allow the model to finish updating
Threading.Thread.Sleep(SleepValue)
Loop
#End Region
End Sub
Solved! Go to Solution.