Weird behavior: running through Inventor works correctly, but when run through a C# application, it doesn't work.

Weird behavior: running through Inventor works correctly, but when run through a C# application, it doesn't work.

m_baczewski
Advocate Advocate
176 Views
1 Reply
Message 1 of 2

Weird behavior: running through Inventor works correctly, but when run through a C# application, it doesn't work.

m_baczewski
Advocate
Advocate

Hello,

 

I have a very strange issue. I've written rules in iLogic that, based on user-provided parameters, create a new model, generate drawings, replace the reference model in the drawings, and then check in the model and drawings into the vault.

 

The problem is that if I run the rules through Inventor, it works correctly. However, if I run these rules through my WPF application in C#, Inventor doesn't wait for the completion of the check-in process, i.e., until the check-in progress window closes. Instead, while the check-in window is still open, Inventor proceeds to open the next drawing.

 

This window is open when next drawing is opening:

m_baczewski_0-1708606498834.png

 

 

I should mention that if I run the rule manually in Inventor, it properly waits for the check-in window to close before opening the next drawing. Do you know why this is happening?

 

I just send only part of my rules code:

 

        DrawingOpenSaveAndChangeReferencedDocument(LuftDrawingPath, luftName, iamExtension, idwExtension)
	DrawingOpenSaveAndChangeReferencedDocument(L1BlachaDrawingPath, L1BlachaSavePathWithoutExtension, iptExtension, idwExtension)
	DrawingOpenSaveAndChangeReferencedDocument(L2BlachaDrawingPath, L2BlachaSavePathWithoutExtension, iptExtension, idwExtension)
	DrawingOpenSaveAndChangeReferencedDocument(L3BlachaDrawingPath, L3BlachaSavePathWithoutExtension, iptExtension,idwExtension)
	
	If countReferencedDocuments = 4
		DrawingOpenSaveAndChangeReferencedDocument(L4BlachaDrawingPath, L4BlachaSavePathWithoutExtension, iptExtension, idwExtension)
	End If 	
	
	ThisApplication.Documents.Open(currentPath, True)
	oDoc.Close()
	
End Sub

Public Sub DrawingOpenSaveAndChangeReferencedDocument(drawingPath As String, newDrawingPath As String, extension As String, idwExtension As String)

	Dim oDrawToCopy As DrawingDocument
	Dim oDraw As DrawingDocument
	
	oDrawToCopy = ThisApplication.Documents.Open(drawingPath, False)
	oDrawToCopy.SaveAs(newDrawingPath + idwExtension, True)
	oDrawToCopy.Close(True)
	oDraw =ThisApplication.Documents.Open(newDrawingPath + idwExtension, True) 
	oDraw.ReferencedDocumentDescriptors.Item(1).ReferencedFileDescriptor.ReplaceReference(newDrawingPath & extension)
	oDraw.Save()
	oDraw.Save()
	
	Dim oControlDef As Inventor.ControlDefinition
	oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop")
	oControlDef.Execute2(False)
	System.Windows.Forms.SendKeys.SendWait("" & Chr(9) & vbCrLf)
	
'	PublishPDF(oDraw,newDrawingPath)
'	oDraw.Close()
	
End Sub

 

My app looks like:

m_baczewski_1-1708606630776.pngm_baczewski_2-1708606651488.png

 

It seems like Inventor has started to work asynchronously.

0 Likes
177 Views
1 Reply
Reply (1)
Message 2 of 2

mslosar
Advisor
Advisor

You can always through in something like Thread.Sleep(30000) to pause the code 30 seconds to allow the checkin to complete if you think that's what the issue is.

 

I'd also try to step it through line by line with the debugger.  Break it on the first like then just go to each line. Pause to make sure things complete before doing the next line, etc. That'll tell you if it's getting ahead of itself or not.

0 Likes