How to close the Measure window using the API?

How to close the Measure window using the API?

filat
Advisor Advisor
626 Views
10 Replies
Message 1 of 11

How to close the Measure window using the API?

filat
Advisor
Advisor

I have an open Measure window (Application.CommandManager.ControlDefinitions.Item("AppMeasureDistanceCmd")).

I have an open Measure window I need to be able to close the measurement window using the command.

I've tried using the handle:

 

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongPtr, lparam As Any) As Long

Public Sub My_ContourFlangeClose()
    Dim windowhandle As LongPtr
    Select Case ThisApplication.Locale
        Case Is = 1033, 2057
            windowhandle = FindWindow("#32770", "Measure")
        Case Else
    End Select
    Call SendMessage(windowhandle, &H10, 0, 0)
End Sub

 

but nothing worked.

0 Likes
627 Views
10 Replies
Replies (10)
Message 2 of 11

J-Camper
Advisor
Advisor

I'm not sure what environment you are writing your code, but here is straight iLogic to "Close" the Measure Window, which is a DockableWindow:

Dim oUserInterfaceMgr As UserInterfaceManager = ThisApplication.UserInterfaceManager

Dim measureWindow As DockableWindow = oUserInterfaceMgr.DockableWindows.Item("Measure")
	
measureWindow.Visible = False

 

The DockableWindow never actually gets Opened/Closed, you just change it's visibility state.

 

Let me know if you have any questions, or if this is not working as intended

0 Likes
Message 3 of 11

filat
Advisor
Advisor

Hi!
I am writing code in VBA and VB.
Your code works only the result does not suit me. Yes, I don't see the Measure window anymore, but I can't select anything in the browser window (DockableWindows.Item"Model").
At the start of Inventor, the collection (DockableWindows.Count) contains only 3 elements - there is no measure window in it.
I need to execute Closing the Measure window.

0 Likes
Message 4 of 11

J-Camper
Advisor
Advisor

There is a Delete Method for a DockableWindow Object

 

Here:

Logger.Trace(ThisApplication.UserInterfaceManager.DockableWindows.Count & " before")
ThisApplication.UserInterfaceManager.DockableWindows.Item("Measure").Delete
Logger.Trace(ThisApplication.UserInterfaceManager.DockableWindows.Count & " after")

 

It throws an error if the window is not open, so you would have to handle that.

0 Likes
Message 5 of 11

WCrihfield
Mentor
Mentor

You're right about it not being present yet when Inventor first starts.  Especially if you just start the application directly, rather than attempting to directly open a document.  In that case there aren't even any documents open, and therefore the model tree, iLogic tree window, iLogic log window, etc. are all not being shown yet.  Once you open documents, some of them start to show up.  And I don't think the measure window shows up in the list until you've opened or used it the first time.  Then it's always there, in the background, until you close it or Inventor.  I believe it has to be initialized that first time before it will be present in the collection.  Just like some add-ins that may add a dock-able window at specific times for specific purposes.  You could loop through them or use a Try..Catch block in an attempt to find it if needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 11

filat
Advisor
Advisor

I work in AI2019 and there is no Delete method in Help for DockableWindows.
I ported to write the Delete program in the code - the Measurements window was closed, but then a fatal error occurred.

0 Likes
Message 7 of 11

WCrihfield
Mentor
Mentor

These dockable windows have a property called VisibilityControl, which returns a ControlDefinition.  That ControlDefinition is the command that toggles whether that dockable window will be shown in the UI or not.  The InternalName of the ControlDefinition that toggles the dockable window for the measure to is simply called "measure", so it's not the same command that launches the tool to actively measure something.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 11

WCrihfield
Mentor
Mentor

That's odd, because the online help page for the DockableWindow.Delete method says that it was created in the 2011 release of Inventor.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 11

J-Camper
Advisor
Advisor

@WCrihfield,

 

I'm sure the VisibilityControl Definiton would operate similar to my first post, where you simply toggle the visibility off, but it still exists in the Collection:

Logger.Trace(ThisApplication.UserInterfaceManager.DockableWindows.Count & " before")
ThisApplication.UserInterfaceManager.DockableWindows.Item("Measure").Visible = False
Logger.Trace(ThisApplication.UserInterfaceManager.DockableWindows.Count & " after")

 

@filat,

Can you post any more info about the Ported code?  Did it give an error as straight iLogic? [the way I posted it]  It should if the Window does not exist, but it should not if the window existed before the rule is run.

0 Likes
Message 10 of 11

filat
Advisor
Advisor

Private Sub m_UserInputEvents_OnActivateCommand(ByVal CommandName As String, ByVal Context As Inventor.NameValueMap) Handles m_UserInputEvents.OnActivateCommand
If CommandName = "AppMeasureDistanceCmd" Then
Try

MeasureDistanceDisable = New MeasureDistanceDisable
MeasureDistanceDisable.m_inventorApplication = m_inventorApplication
MeasureDistanceDisable.Show() ' Создает модальное не окно
Catch ex As Exception
End Try
End If
End Sub

 

 

Imports Inventor
Imports System.Windows.Forms
Imports System.Runtime.InteropServices ' для Marshal хуки т т.д.

Public Class MeasureDistanceDisable
' для автоматизации закрытия окна линейки MeasureDistance

Public m_inventorApplication As Inventor.Application
Private WithEvents m_clsMouseHook As MouseHook = New MouseHook ' 11.05.2021

Private Sub MeasureDistanceDisable_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = True
m_clsMouseHook.HookMouse() ' 11.05.2021
End Sub

Private Sub MeasureDistanceDisable_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
m_clsMouseHook.UnhookMouse() ' положить в sub formClose
End Sub

Dim WM_QUIT As UInteger = &H12
Dim WM_CLOSE As UInteger = &H10

Private Sub m_clsMouseHook_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles m_clsMouseHook.MouseDown
Dim oDocWin As DockableWindows ' коллекция браузеров сборки, детали (вертикальный слева)
oDocWin = m_inventorApplication.UserInterfaceManager.DockableWindows ' доступны только Height и Width ( Top и Left - почемуто с минусами)
Dim oLeft As Integer ' начальная точка слева по оси Х
Dim oTop As Integer ' начальная точка сверху по оси Y
If oDocWin.Item(1).Left > 0 And oDocWin.Item(1).Top > 0 Then
oLeft = oDocWin.Item(1).Left
oTop = oDocWin.Item(1).Top
Else
oLeft = m_inventorApplication.Left
oTop = m_inventorApplication.Top + m_inventorApplication.Height - oDocWin.Item(1).Height
End If
If e.X > oLeft And e.X < oLeft + oDocWin.Item(1).Width Then
If e.Y > oTop And e.Y < oTop + oDocWin.Item(1).Height Then
'm_inventorApplication.UserInterfaceManager.DockableWindows.Item("Measure").Delete()
Call SendMessage(m_inventorApplication.UserInterfaceManager.DockableWindows.Item("Measure").HWND, &H10, 0, 0)
Me.Close()
End If
End If
End Sub

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Long, ByVal lParam As Long) As Long

End Class

0 Likes
Message 11 of 11

J-Camper
Advisor
Advisor

I don't work in VBA myself, so I can't just drop this in something i already have to test it.  I will try to help though.

 

So when you tried this line, what error did you get?:

m_inventorApplication.UserInterfaceManager.DockableWindows.Item("Measure").Delete()

If you try using "Call" does it have any different behavior?:

Call m_inventorApplication.UserInterfaceManager.DockableWindows.Item("Measure").Delete()

If neither of those work, maybe try setting up an Object for the DockableWindow and make sure it exists:

Dim measureWindow As DockableWindow
measureWindow = oDocWin.Item("Measure")
If Not IsNothing(measureWindow) Then
	Call measureWindow.Delete()
End If

 Let me know how those suggestions go.

0 Likes