Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A Macro that updates\runs all ilogic in a drawing.
Solved! Go to Solution.
A Macro that updates\runs all ilogic in a drawing.
Solved! Go to 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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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
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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
It updates the ilogic in the drawing but it bypasses the update of the 3D model.
I don't understand what you mean? are you talking about the iLogic rules in the iPart-factory? Like we did here?:
Because the code you posted earlier in this thread is not the same...
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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
Jhoel Forshav Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
@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).