Macro that creates Drawings dosent updeite iLogic

Macro that creates Drawings dosent updeite iLogic

JonnyPot
Advocate Advocate
1,015 Views
12 Replies
Message 1 of 13

Macro that creates Drawings dosent updeite iLogic

JonnyPot
Advocate
Advocate

Hello very one,
With the help of @JhoelForshav i got this Macro that creates drawings for all instances of a iPart from a reference drawing. My issue is that the Logic used in the model seems to not update in the drawings as shown in the pictures.
I attached the model and the drawing with the Macro shown in the screenshots.

3.png

Sub iPartDWG()
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
    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
        Call oDrawing.Update
        Do While oView.IsUpdateComplete = False
            Call ThisApplication.UserInterfaceManager.DoEvents
        Loop
nextView:
    Next
    Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
Next
End If
End Sub

0 Likes
Accepted solutions (1)
1,016 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

Hi @JonnyPot . Try to take a look at the views if there are lighning bolts symbol. You maybe just have to update the model view. lightning bolt.jpg

Message 3 of 13

JonnyPot
Advocate
Advocate

The problem is i am planing to do thousandes of this drawings and it would be very inpractical and time consuming to change the iPart instance, save it, go to drawing and updeit it for all the drawings. i was hoping to updeit the model automaticly wen the drawing are being created.

0 Likes
Message 4 of 13

Anonymous
Not applicable

Try this. Please let me know if it works for you.

Message 5 of 13

JonnyPot
Advocate
Advocate

0 Likes
Message 6 of 13

Anonymous
Not applicable

@JonnyPot  I was supposed to paste the code. 

 

Sub Main ()
	Dim oFileDlg As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Autodesk Inventor Drawings (*.dwg)|*.dwg"
	oFileDlg.DialogTitle = "Select Drawings To Check"
	oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oFileDlg.MultiSelectEnabled =True 
	oFileDlg.FilterIndex = 1
	oFileDlg.CancelError = True
	On Error Resume Next
	oFileDlg.ShowOpen()
	Dim oDrgDoc As DrawingDocument
	If Err.Number <> 0 Then
		MsgBox("File not chosen.",,"Dialog Cancellation")
	ElseIf oFileDlg.FileName <> "" Then
		For Each oFileName As String In oFileDlg.FileName.Split("|")
			oDrgDoc = ThisApplication.Documents.Open(oFileName)
				' Iterate through the sheets
				Dim oSheet As Sheet
				Dim oView As DrawingView
				For Each oSheet In ThisDoc.Document.Sheets
					For Each oView In oViews
						If oView.UpToDate = False Then
							Dim oRefDoc As Document
								For Each oRefDoc In ThisApplication.ActiveDocument.ReferencedDocuments
									Dim oFileName1 As String = oRefDoc.FullFileName
									'MsgBox(oFileName)
									oModelDoc = ThisApplication.Documents.Open(oFileName1, False) 'False = open invisibly
									oModelDoc.Update()
									oModelDoc.Close()
								Next
						End If
					Next
				Next
			oDrgDoc.Update()
			oDrgDoc.Close()
		Next
	End If
End Sub
Message 7 of 13

JonnyPot
Advocate
Advocate

it doesn't really work for me, i think that is because is an iPart.

0 Likes
Message 8 of 13

JhoelForshav
Mentor
Mentor

@JonnyPot 

I believe that the model document has to be updated. I see that @Anonymous had the same idea, but for his code to update the model document the DrawingView.UpToDate must be false, and it isn't necessarily that even though the model document isn't up to date in this case.

Try this and let me know if it works 🙂

Sub iPartDWG()
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 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
    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
        Call oDrawing.Update
        Do While oView.IsUpdateComplete = False
            Call ThisApplication.UserInterfaceManager.DoEvents
        Loop
        Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
        Call oDoc.Update
        Call oDrawing.Update
        
nextView:
    Next
    Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
Next
End If
End Sub

 

0 Likes
Message 9 of 13

JonnyPot
Advocate
Advocate

it doesn't seem to work, i think it has to open the model to update it.

0 Likes
Message 10 of 13

JhoelForshav
Mentor
Mentor

This is a difficult problem actually... The member files of an iPart doesn't contain the iLogic rules. Only the factory part does. So generating new files will not trigger the rules. Actually iParts and iLogic is a combination that often leads to problems... I'll try to find a solution for this but it'll probably take some time if I even manage to come up with something.

Message 11 of 13

JonnyPot
Advocate
Advocate

take your time and thank you

0 Likes
Message 12 of 13

JhoelForshav
Mentor
Mentor
Accepted solution

If we change the default member in the iFactory we'll force the ilogic to run. Then the drawing will want to update (giving the prompt), by setting ThisApplication.SilentOperation to true we can bypass this prompt giving the default answer (which is ok in this case). I've tried this code on your files with successful results. I hope it works for you to 🙂

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
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
    Call oDrawing.SaveAs(oPath & "\" & oRow.MemberName & ".dwg", True)
Next
Call oDoc.Close
ThisApplication.SilentOperation = False
End If
End Sub
Message 13 of 13

JonnyPot
Advocate
Advocate

Everything works very well, thank you.