A Macro that updates\runs all ilogic in a drawing.

A Macro that updates\runs all ilogic in a drawing.

JonnyPot
Advocate Advocate
1,043 Views
8 Replies
Message 1 of 9

A Macro that updates\runs all ilogic in a drawing.

JonnyPot
Advocate
Advocate

A Macro that updates\runs all ilogic in a drawing.

0 Likes
Accepted solutions (3)
1,044 Views
8 Replies
Replies (8)
Message 2 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @JonnyPot 

Are you looking for something like this? 🙂

Sub RunIlogicRules()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
If oDoc.DocumentType = kDrawingDocumentObject Then
Dim iLogicAuto As Object
Dim oAddin As ApplicationAddIn
For Each oAddin In ThisApplication.ApplicationAddIns
    If (oAddin.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
    Exit For
End If
Next
Set iLogicAuto = oAddin.Automation
 
Dim oRules As Object
Set oRules = iLogicAuto.Rules(oDoc)
Dim oRule As Object
For Each oRule In oRules
    Call iLogicAuto.RunRule(oDoc, oRule.Name)
Next
End If
End Sub
Message 3 of 9

JonnyPot
Advocate
Advocate

hello @JhoelForshav. i was going to implement this code in a other Macro that you made, but it seems that it's a bit more complicated than i thoght‌‌ 😅. can you help me with it, thank you.

Macro:

Sub iPart_DWG_STP()
Dim oDrawing As DrawingDocument
Set oDrawing = ThisApplication.ActiveDocument
Dim oPath As String
oPath = "C:\Users\hfljf\Desktop\TestFolder" 'Folder to save the drawings
Dim oView As DrawingView
Dim oDoc As Document
Dim oFactory As iPartFactory
For Each oView In oDrawing.ActiveSheet.DrawingViews
    Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
    On Error GoTo trynext
    Set oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
    Exit For
trynext:
Next
    If oFactory Is Nothing = False Then
    Dim oRow As iPartTableRow
    
    For Each oRow In oFactory.TableRows
        For Each oView In oDrawing.ActiveSheet.DrawingViews
        On Error GoTo nextView
        If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
        Call oDrawing.Update
        Do While oView.IsUpdateComplete = False
            Call ThisApplication.UserInterfaceManager.DoEvents
        Loop
nextView:
    Next
    Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
    Dim oMember As PartDocument
    Set oMember = ThisApplication.Documents.ItemByName(oFactory.MemberCacheDir & "\" & oRow.PartName)
    Call oMember.SaveAs(oPath & "\" & oRow.MemberName & ".stp", True)
Next
End If
End Sub
0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

@JonnyPot 

I'm not able to test the macro right now, but I think something like this should work. Let me know 🙂

Sub iPart_DWG_STP()
Dim oDrawing As DrawingDocument
Set oDrawing = ThisApplication.ActiveDocument
Dim oPath As String
oPath = "C:\Users\hfljf\Desktop\TestFolder" 'Folder to save the drawings
Dim oView As DrawingView
Dim oDoc As Document
Dim oFactory As iPartFactory
Dim oSheet As Sheet
Set oSheet = oDrawing.ActiveSheet


Dim iLogicAuto As Object
Dim oAddin As ApplicationAddIn
For Each oAddin In ThisApplication.ApplicationAddIns
    If (oAddin.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
    Exit For
End If
Next
Set iLogicAuto = oAddin.Automation
 
Dim oRules As Object
Set oRules = iLogicAuto.Rules(oDrawing)
Dim oRule As Object

For Each oView In oSheet.DrawingViews
    Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
    On Error GoTo trynext
    Set oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
    Exit For
trynext:
Next
    If oFactory Is Nothing = False Then
    Dim oRow As iPartTableRow
    
    For Each oRow In oFactory.TableRows
        For Each oView In oDrawing.ActiveSheet.DrawingViews
        On Error GoTo nextView
        If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
        Call oDrawing.Update
        Do While oView.IsUpdateComplete = False
            Call ThisApplication.UserInterfaceManager.DoEvents
        Loop
nextView:
    Next
    

For Each oRule In oRules
    Call iLogicAuto.RunRule(oDrawing, oRule.Name)
Next
    
Call ThisApplication.UserInterfaceManager.DoEvents
    
Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
Dim oMember As PartDocument
Set oMember = ThisApplication.Documents.ItemByName(oFactory.MemberCacheDir & "\" & oRow.PartName)
Call oMember.SaveAs(oPath & "\" & oRow.MemberName & ".stp", True)
Next
End If
End Sub
Message 5 of 9

JonnyPot
Advocate
Advocate

@JhoelForshav 

It updates the ilogic in the drawing but it bypasses the update of the 3D model.

0 Likes
Message 6 of 9

JhoelForshav
Mentor
Mentor

@JonnyPot 

I don't understand what you mean? are you talking about the iLogic rules in the iPart-factory? Like we did here?:

https://forums.autodesk.com/t5/inventor-customization/macro-that-creates-drawings-dosent-updeite-ilo...

Because the code you posted earlier in this thread is not the same...

 

0 Likes
Message 7 of 9

JonnyPot
Advocate
Advocate

yes, i am very sorry 😐, is it posseble to change the other one?

0 Likes
Message 8 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

@JonnyPot 

Again, I havn't tried it but this should work - It's basically the same macro

Sub iPartDWG()
ThisApplication.SilentOperation = True
Dim oDrawing As DrawingDocument
Set oDrawing = ThisApplication.ActiveDocument
Dim oPath As String
oPath = "C:\VaultWorkingFolder\Designs\Temp\Jhoel\iPartTest\Drawings" 'Folder to save the drawings
Dim oView As DrawingView
Dim oDoc As PartDocument
Dim oFactory As iPartFactory

Dim iLogicAuto As Object
Dim oAddin As ApplicationAddIn
For Each oAddin In ThisApplication.ApplicationAddIns
    If (oAddin.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
    Exit For
End If
Next
Set iLogicAuto = oAddin.Automation
 
Dim oRules As Object
Set oRules = iLogicAuto.Rules(oDrawing)
Dim oRule As Object


For Each oView In oDrawing.ActiveSheet.DrawingViews
Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
On Error GoTo trynext
    
    
Set oFactory = oDoc.ComponentDefinition.iPartMember.ParentFactory
Set oDoc = ThisApplication.Documents.Open(oFactory.Parent.FullFileName)
Exit For
trynext:
Next
If oFactory Is Nothing = False Then
Dim oRow As iPartTableRow
On Error GoTo nextView
For Each oRow In oFactory.TableRows

For Each oView In oDrawing.ActiveSheet.DrawingViews
If oView.ActiveMemberName <> oRow.MemberName Then oView.ActiveMemberName = oRow.MemberName
oDoc.ComponentDefinition.iPartFactory.DefaultRow = oRow
Call ThisApplication.UserInterfaceManager.DoEvents
Call oDoc.Update
Call oDoc.Save
        
Call oDrawing.Update2
Do While oView.IsUpdateComplete = False
Call ThisApplication.UserInterfaceManager.DoEvents
Loop
        
nextView:
Next
    
For Each oRule In oRules
Call iLogicAuto.RunRule(oDrawing, oRule.Name)
Next
    
Call ThisApplication.UserInterfaceManager.DoEvents

Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
Next
Call oDoc.Close
ThisApplication.SilentOperation = False
End If
End Sub

 

Message 9 of 9

JonnyPot
Advocate
Advocate

@JhoelForshav 

Thank you it works very well. 
In another note i noticed this very weird bug that after a few drawings it rights the previous drawing description, as shown in the print screen (witch is determined by the parameters of the iPart).

0 Likes