run all rule from macro

run all rule from macro

ac69
Participant Participant
1,783 Views
3 Replies
Message 1 of 4

run all rule from macro

ac69
Participant
Participant

Hi,

 

I'm trying to open each ipt file in a folder and run all iLogicRules.

I' m getting the following error: Object variable or With block variable not set.

 

See code below:

 

'Get iLogic addins

Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
        End If
    Next

 

'detect full path to current opened file

File_Name = ThisApplication.ActiveEditObject.ComponentDefinition.Document.FullFileName
myobject.Close

 

'detect current directory

Directory = Left(File_Name, InStrRev(File_Name, "\") - 1)

 

'look for all files in the current directory, open, rebuilt and update
 
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Directory)
Set fc = f.Files

For Each fl In fc
       
    If ((InStr(fl, "kelet") <> 0 Or InStr(fl, "param") <> 0) And InStr(fl, ".ipt") <> 0) Then
                Set pDoc = ThisApplication.Documents.Open(fl)
                Set pDoc = ThisApplication.ActiveDocument
               
                'RunAllRules (pDoc)
                Dim rules As Object
                rules = iLogicAuto.rules(pDoc)
                Stop
                 If Not (rules Is Nothing) Then
                    For Each rule In rules
                       iLogicAuto.RunRuleDirect (rule)
                    Next
                End If

                pDoc.Update
                pDoc.Rebuild
                On Error GoTo 10
                pDoc.Save
                pDoc.Close
    End If
   
 Next

 

Any help is much appreciated. Thanks.

 

Gus

0 Likes
Accepted solutions (1)
1,784 Views
3 Replies
Replies (3)
Message 2 of 4

ac69
Participant
Participant

Sorry,

for some reason, on my initial post, the part were all the declarations were is missing.

See below again, the full code:

Dim Part_No As String
Dim Part_Name As String
Dim Part_Rev As String
Dim MyFileDirectory
Dim Directory As String
Dim DocType As String


Dim myobject As Document
Dim pDoc As Document
Dim File_Name As String
Dim allModels As Document
Dim fs, f, fl, fc, s

'Get iLogic addins

Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
        End If
    Next

 

'detect full path to current opened file

File_Name = ThisApplication.ActiveEditObject.ComponentDefinition.Document.FullFileName
myobject.Close

 

'detect current directory

Directory = Left(File_Name, InStrRev(File_Name, "\") - 1)

 

'look for all files in the current directory, open, rebuilt and update
 
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Directory)
Set fc = f.Files

For Each fl In fc
      
    If ((InStr(fl, "kelet") <> 0 Or InStr(fl, "param") <> 0) And InStr(fl, ".ipt") <> 0) Then
                Set pDoc = ThisApplication.Documents.Open(fl)
                Set pDoc = ThisApplication.ActiveDocument
              
                'RunAllRules (pDoc)
                Dim rules As Object
                rules = iLogicAuto.rules(pDoc)
                Stop
                 If Not (rules Is Nothing) Then
                    For Each rule In rules
                       iLogicAuto.RunRuleDirect (rule)
                    Next
                End If

                pDoc.Update
                pDoc.Rebuild
                On Error GoTo 10
                pDoc.Save
                pDoc.Close
    End If
  
 Next

0 Likes
Message 3 of 4

MjDeck
Autodesk
Autodesk
Accepted solution

I found two problems in the code.  The first one is this line:

myobject.Close

At that point you haven't assigned anything to myobject. You should delete that line.

 

The second one is the line:

rules = iLogicAuto.rules(doc)

rules is an Object.  So you need the Set keyword:

Set rules = iLogicAuto.rules(doc)

 

I would recommend not running rules that are suppressed.  This gives you a way to disable individual rules without deleting them.  Here's a modified version of your code:

   For Each rule In rules
      If (rule.IsActive) Then
         iLogicAuto.RunRuleDirect (rule)
      End If
   Next

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 4 of 4

ac69
Participant
Participant

Hi Mike,

 

It works now.

Thanks for solution.

 

ac

0 Likes