iLogic isn't waiting for DrawingBaseViewCmd to finish running

iLogic isn't waiting for DrawingBaseViewCmd to finish running

matt_jlt
Collaborator Collaborator
1,888 Views
12 Replies
Message 1 of 13

iLogic isn't waiting for DrawingBaseViewCmd to finish running

matt_jlt
Collaborator
Collaborator

I have an issue where the ilogic script isn't waiting for the view place command to complete before it continues if i try to do anything after running the script. For example, if it's right before the end of the sub it works file. If there is code doing something after it it closes.

So looking at the below snippet, if i ran it twice, it would just flash up for a split second and skip then run the second one like normal. I have tried the other options such as ".Execute" & ".Execute2(True)" but they both just place the view automatically without the user getting to interface with the view place / edit dialog.

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, strFilename)
ThisApplication.CommandManager.ControlDefinitions.Item("DrawingBaseViewCmd").Execute2(False) 

I have tried putting it in a loop so for each filename in a list it is meant to run the view place command, wait for user to select then continue to the next one. it just skips to the last one and doesn't wait for the user. 

 

Does anyone have any ideas because i can't work it out.

Thanks, Matt.

 

Currently testing it on Inventor 2019 / iLogic.

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

A.Acheson
Mentor
Mentor

@matt_jlt 

 

Is the manual placing of the view part of the view place command routine? If you run the command on its own will it put the view on the end of the cursor? 

I came across this skipping the user input scenario  when using a select occurance code.

 

I solved it elegantly? By placing a self cancelling message box which was enough to stop and allow the user pick up the occurances. 


https://forums.autodesk.com/autodesk/attachments/autodesk/120/118325/2/T%26P_%20Run%20Constraint%20M...

Can you try it with just a message box does it allow the user to finish the view placement.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 13

matt_jlt
Collaborator
Collaborator

Hi Alan, thanks for your sugestion but it didn't seem to work.

 

Thanks, Matt.

0 Likes
Message 4 of 13

matt_jlt
Collaborator
Collaborator

Just to clarify, If i change the code to "Execute(True)" and it is run  on a button click and no form closing events are triggered, it waits for the code to finish. But if it is triggered after a form closing event which is what i actually wanted, If just places the view on the sheet with no user input and continues.

 

Seems like a weird bug maybe tied to events?

0 Likes
Message 5 of 13

moveworkforward
Contributor
Contributor

Hi @matt_jlt ,

maybe this will help you. I have an AddIn (written in VB) with multiple extra functions I need. When developing I faced a similar issue. I had to implement an automatic centerlines placing to each new view added. So I resolved the problem by running the Sub AddCenterLines (see the code snippets) in the new thread. See the lines: 

Dim thread As New Thread(AddressOf AddCenteLines)
thread.Start()

 Note that  in  AddCenterLines I check for the view to finish an update:

Do While oView.IsUpdateComplete = False
g_inventorApplication.UserInterfaceManager.DoEvents()
Loop

 

So the full two subs are:

Private Sub DrawingUserInputEvents_OnTerminateCommand(CommandName As String, Context As NameValueMap) Handles DrawingUserInputEvents.OnTerminateCommand
    Try
        If CommandName = "DrawingBaseViewCmd" Or CommandName = "DrawingProjectedViewCmd" _
        Or CommandName = "DrawingSectionViewCmd" Or CommandName = "DrawingDetailViewCmd" _
        Or CommandName = "DrawingAuxiliaryViewCmd" Or CommandName = "DrawingBreakOutViewCmd" Then
            Dim oDrawDoc As DrawingDocument = g_inventorApplication.ActiveDocument
            Dim thread As New Thread(AddressOf AddCenteLines)
            thread.Start()
        End If
    Catch
    End Try
End Sub
Private Sub AddCenteLines()
    Try
        Dim oDrawDoc As DrawingDocument = g_inventorApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oView As DrawingView : oView = oSheet.DrawingViews.Item(oSheet.DrawingViews.Count)
        If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            If My.Settings.AssemblyCenterLines = False Then Exit Sub
        ElseIf oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject Then
            If My.Settings.PartCenterLines = False Then Exit Sub
        Else Exit Sub
        End If
        Do While oView.IsUpdateComplete = False
            g_inventorApplication.UserInterfaceManager.DoEvents()
        Loop
        Dim oCenterline As AutomatedCenterlineSettings = Nothing
        oView.GetAutomatedCenterlineSettings(oCenterline)
        oCenterline.ApplyToHoles = True
        oCenterline.ProjectionParallelAxis = True
        oView.SetAutomatedCenterlineSettings(oCenterline)
    Catch
    End Try
End Sub  

 Probably there are better solutions to this problem but this one works for me.

Message 6 of 13

moveworkforward
Contributor
Contributor

This works in ilogic. Do While Loop pauses the further code execution until view is placed.

Dim strFilename As String = "Your part file full path"
If Dir(strFilename) <> "" Then
	ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, strFilename)
	ThisApplication.CommandManager.ControlDefinitions.Item("DrawingBaseViewCmd").Execute

	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet = oDrawDoc.ActiveSheet
	Dim oView As DrawingView = oSheet.DrawingViews.Item(oSheet.DrawingViews.Count)

	Do While oView.IsUpdateComplete = False
	     Call  ThisApplication.UserInterfaceManager.DoEvents
	Loop

	Dim oCenterline As AutomatedCenterlineSettings = Nothing
	Call oView.GetAutomatedCenterlineSettings(oCenterline)
	oCenterline.ApplyToHoles = True
	oCenterline.ProjectionParallelAxis = True
	Call oView.SetAutomatedCenterlineSettings(oCenterline)
Else
	MessageBox.Show("Specified file does not exist.")
End If

 

0 Likes
Message 7 of 13

matt_jlt
Collaborator
Collaborator

Thanks for your efforts, It does not seem to solve my problem. When i run your example ilogic code exactly as is but swapping out the filename, inventor automatically places the view in the bottom left hand corner of the sheet every time (I assume this is location 0,0 for the sheet coordinates).

 

I suspect that if it is working for you then the problem i am experiencing is more likely the version of inventor on the machine i am testing it on which is inventor 2019.

 

Can i ask if you are running inventor 2019 or the more recent versions 2020/2021.

0 Likes
Message 8 of 13

moveworkforward
Contributor
Contributor
Accepted solution

Hi @matt_jlt 

That piece of code does exactly what you said. My point was just to show how to pause an Ilogic code execution.

Anyway try the code below. I hope it helps solving your problem.

Please first fill out 3 full file names at the top of the code.

 

After you run it the ilogic waits for you to click somewhere at the drawing space to get the position for the new drawing view. Than it places the view and offers you to edit the view orientation and so on.  When you are done it repeats all these steps for other files in the list. 

 

Public Class ThisRule
	
Public strFilename1 As String = "Add here your assembly or part file path"
Public strFilename2 As String = "Add here our assembly or part file path"
Public strFilename3 As String = "Add here your assembly or part file path"
	
Public oPosition As Point2d
Public oInteraction As InteractionEvents 
Public oMouse As MouseEvents
Private mouseClicked As Boolean

Sub Main
	 oInteraction = ThisApplication.CommandManager.CreateInteractionEvents
	 oMouse = oInteraction.MouseEvents
	 AddHandler oMouse.OnMouseClick  ,AddressOf oMouse_OnMouseDown 
	
	Dim nameList() As String = {strFilename1,strFilename2,strFilename3}
	
	For i = 0 To nameList.Length - 1
		oInteraction.Start
		AddDrawingView(nameList(i))
	Next
End Sub

Sub AddDrawingView(name As String)
	Dim oDoc As Document = ThisApplication.Documents.Open(name, False)
	
	Do While mouseClicked = False
	     ThisApplication.UserInterfaceManager.DoEvents
	Loop

	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
		
	Dim Scale As Double = 1/2
	Call oDrawDoc.ActiveSheet.DrawingViews.AddBaseView(oDoc, oPosition, Scale, _
									ViewOrientationTypeEnum.kDefaultViewOrientation, _
						DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , )

	oDoc.Close
	
	Dim oCommandMgr As CommandManager = ThisApplication.CommandManager 

	Dim oControlDef As ControlDefinition 
	Dim lastViewIndex As Integer = oDrawDoc.ActiveSheet.DrawingViews.Count
	oDrawDoc.SelectSet.Select(oDrawDoc.ActiveSheet.DrawingViews(lastViewIndex))

	oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingViewEditCtxCmd")  
	oControlDef.Execute2(True)
	  
	Dim oView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews(oDrawDoc.ActiveSheet.DrawingViews.Count)
	  
	Do While oView.IsUpdateComplete = False
	     Call  ThisApplication.UserInterfaceManager.DoEvents
	Loop
	
	Call AddCenterLines(oView)
	
	mouseClicked = False
End Sub
	
Sub AddCenterLines(oView As DrawingView)
	Dim oCenterline As AutomatedCenterlineSettings = Nothing
	Call oView.GetAutomatedCenterlineSettings(oCenterline)
	oCenterline.ApplyToHoles = True
	oCenterline.ProjectionParallelAxis = True
	Call oView.SetAutomatedCenterlineSettings(oCenterline)
End Sub

 Sub oMouse_OnMouseDown(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, _
 						ModelPosition As Point, ViewPosition As Point2d, View As Inventor.View)
  oPosition = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
  mouseClicked = True
End Sub 
End Class

 

Message 9 of 13

matt_jlt
Collaborator
Collaborator

While i still have the same bug, Your last example is definitely a good workaround with the exception of the inability for the user to select sheet metal placement which is something i definitely need to have. I marked your answer as the solution as it seems like i will have to wait for the company i am working for to upgrade to a newer version without the bug.

 

I didn't even think of approaching it that way. And you inadvertently helped with with another problem i had with something else with implementing user interaction events.

 

I will implement your code into my example with a few tweaks. I really appreciate your help.

 

The main reason i am trying to do this all in ilogic is so i can share all my code / snippets with everyone on github once i tidy it all up a bit.

 

 

Thanks again.

 

0 Likes
Message 10 of 13

moveworkforward
Contributor
Contributor

I am not sure what you mean about the bug.. Does the the code I sent run smoothly for you? Because I use Inventor 2018 and it runs without problems...

As for the sheet metal issue. If I need to place a sheet metal flat pattern then I use an extra options for adding view:

 

Dim oBaseViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Call oBaseViewOptions.Add("SheetMetalFoldedModel", False)
Call oDrawDoc.ActiveSheet.DrawingViews.AddBaseView(oDoc, oPosition, Scale, _
			ViewOrientationTypeEnum.kDefaultViewOrientation, _
			DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , ,oBaseViewOptions )

 

0 Likes
Message 11 of 13

moveworkforward
Contributor
Contributor

Ok now see what you mean. You refer to the original PostPrivateEvent problem. In 2018 version I have the same issue.

0 Likes
Message 12 of 13

matt_jlt
Collaborator
Collaborator

Yeah, that's what i am referring to. I think i was having two issues. the initial bug as well as the not waiting for the view to update.

 

Thanks again.

0 Likes
Message 13 of 13

JMGunnar
Collaborator
Collaborator

Is there different if you check this options on/off ? 

 

Enable background updates.PNG

0 Likes