Custom Browser: Selected object is unselected when editing iProperty

Custom Browser: Selected object is unselected when editing iProperty

Jef_E
Collaborator Collaborator
1,376 Views
8 Replies
Message 1 of 9

Custom Browser: Selected object is unselected when editing iProperty

Jef_E
Collaborator
Collaborator

Hi,

 

I made a custom browser object that displays some extra information on hand that we use frequently. The information that is shown are iProperty values of the selected component.

 

Problem: when I change a iProperty value of a selected component the component is automatic deselected. What is causing this? What can I do about it?

I use the textbox.LostFocus event to edit the iProperty value to the value entered in the textbox

 

See video for clarifications.

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Accepted solutions (1)
1,377 Views
8 Replies
Replies (8)
Message 2 of 9

MechMachineMan
Advisor
Advisor

Can I ask how your made the stuff inside the browser? I'm assuming it's just an active x object, but could you help a guy out and provide some more detail on what that entails? I'm looking at doing something similar.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 9

ekinsb
Alumni
Alumni

This is expected behavior.  Selections in Inventor are very temporary and any changes to data in Inventor will clear the current selection.  A workaround would be to save the entities that are currently selected in an array, make whatever changes you need to, (which is edit the iProperty value in your case) and then re-select the entities.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 4 of 9

Jef_E
Collaborator
Collaborator

@ekinsb What is the easiest way to do so? Loop the entire select set into a array and then loop the array into the selectset? Or is there a specific method I can use? (But as I read the API there is not?) Document.SelectSet cannot be converted to array.

 

 

Dim oSelectedObjectsArray as Object()

For each oObject as Object in oDoc.SelectSet
    oSelectedObjectsArray.Add(oObject)
Next

' Update the property

For each oObject as Object in oSelectedObjectsArray 
    oDoc.SelectSet.Select(oObject)
Next

 

@MechMachineMan I create a UserControl in Visual Studio for my AddIn and added into a dockable window as subscribed in the programming help (see sample below) only thing that changed is the HWND value this must be set to the UserControl.Handle to load the control into the dockable window.

 

 

Dockable window API Sample

 

Description

This sample demonstrates creating a dockable window and adding a dialog into it.

 

 

VBA Sample Code

You need to create the (modeless) dialog and set the hwnd of the dialog in the code below.

Sub DockableWindow()
    Dim oUserInterfaceMgr As UserInterfaceManager
    Set oUserInterfaceMgr = ThisApplication.UserInterfaceManager

    ' Create a new dockable window
    Dim oWindow As DockableWindow
    Set oWindow = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "TestWindowInternalName", "Test Window")

    ' Get the hwnd of the dialog to be added as a child
    ' CHANGE THIS VALUE!
    Dim hwnd As Long
    hwnd = 4851096

    ' Add the dialog as a child to the dockable window
    Call oWindow.AddChild(hwnd)

    ' Don't allow docking to top and bottom
    oWindow.DisabledDockingStates = kDockTop + kDockBottom

    ' Make the window visible
    oWindow.Visible = True
End Sub

 

 

My code

 

Is placed in the UserControl Class

 

    Public Sub New(ByVal Application As Inventor.Application)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set reference to the Inventor application and store it local
        _InvApp = Application

        ' Set reference to the Application events and store it local
        _ApplicationEvents = _InvApp.ApplicationEvents

        ' Set reference to the user input events and store it local
        _UserInputEvents = _InvApp.CommandManager.UserInputEvents

        ' Add a event handlers to catch the user selection changes
        AddHandler _ApplicationEvents.OnActivateDocument, AddressOf Document_Activated
        AddHandler _UserInputEvents.OnSelect, AddressOf UserSelect
        AddHandler _UserInputEvents.OnUnSelect, AddressOf UserUnSelect

        ' Set reference to the user interface manager
        Dim oUserInterfaceMgr As UserInterfaceManager _
            = _InvApp.UserInterfaceManager

        ' Create a new dockable window
        _Browser = oUserInterfaceMgr.DockableWindows.Add("SampleClientId", "DDCIntName", "Ellimetal DDC")

        ' Add control to the dockable window
        _Browser.AddChild(Me.Handle)

        ' Dock the window to the right
        _Browser.DockingState = DockingStateEnum.kDockRight

        ' Show the title bar
        _Browser.ShowTitleBar = True

        ' Set the dockable window visible
        _Browser.Visible = True

        ' Set the window width
        _Browser.Width = 220

    End Sub

 

Problem: Even if I state the the browser.width = 220 this does not work for me. I made a post about this but haven't got any use full feedback. If you manage to size the browser as you like please let me know.

 

https://forums.autodesk.com/t5/inventor-customization/api-dockable-window-width-not-working/td-p/642...



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 9

Owner2229
Advisor
Advisor

Hey, here's the re-select code:

 

'Get the current selection (somewhere at the start of your code)
Dim oDoc As Document = ThisApplication.ActiveDocument Dim oSelection As SelectSet = oDoc.SelectSet
If oSelection Is Nothing Then Exit Sub 'Nothing is selected, so quit Dim oItems As ObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection For Each Item As Object In oSelection oItems.Add(Item) Next ' Your code here
'Reselect the previous selection (somewhere at the end of your code) oDoc.SelectSet.SelectMultiple(oItems)

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 9

Jef_E
Collaborator
Collaborator
Accepted solution

If oSelection Is Nothing Then Exit Sub 'Nothing is selected, so quit

 This line is invalid oSelection is not nothing when there is no item selected. The selectset object exists even if nothing is selected, you should check the selectset.count of you want to check if something is selected I think.

 

 

 

Dim oItems As ObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection

Also oItems must be declared as objectcollection. ObjectsEnumerator does not have a Add method. And SelectSet.SelectMultiple requires a objectcollection to select.

 

 

 

Here is my code. It may seem odd to read because I made a class object called _DispayedDocument that manages the property values thats why no oDoc.PropertySets.Item("xxxx").item("xxxxx").Value is in my code.

 

    Private Sub tbSubject_LostFocus(sender As Object, e As EventArgs) Handles tbSubject.LostFocus

        ' Write the title to the document property
        If tbSubject.Text <> _DisplayDocument.Subject Then

            ' Get the selected items to be able to reselect them after
            ' changes to the property is made.
            Dim oSelectedItems As ObjectCollection = SelectSetCollection(_DisplayDocument.ReferencedDocument)

            ' Update the subject property value
            _DisplayDocument.Subject = tbSubject.Text

            ' Update the document description
            UpdateDescription()

            ' Reselect the items if there were any selected, if there 
            ' were none selected the objectcollection Is nothing.
            If Not oSelectedItems Is Nothing Then
                _DisplayDocument.ReferencedDocument.SelectSet.SelectMultiple(oSelectedItems)
            End If

        End If

    End Sub

    Private Function SelectSetCollection(ByVal oDoc As Document) As ObjectCollection

        ' Get the current document select set
        Dim oSelectSet As SelectSet = oDoc.SelectSet

        ' Check if there are are objects selected
        If oSelectSet.Count = 0 Then

            ' Return a null value
            SelectSetCollection = Nothing

        Else

            ' Create a new object collection to store the selected objects
            Dim oSelectedItems As ObjectCollection = _InvApp.TransientObjects.CreateObjectCollection

            ' Loop the select set to add the items into the selection
            For Each oSelectedItem As Object In oSelectSet

                ' Add the item to the list
                oSelectedItems.Add(oSelectedItem)

            Next

            ' Return the selected items
            SelectSetCollection = oSelectedItems

        End If

    End Function


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 7 of 9

Jef_E
Collaborator
Collaborator

Nevermind bad assumption.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 8 of 9

AlexFielder
Advisor
Advisor

This is pretty slick:

 

_DisplayDocument.Subject = "Some text"

I currently have this:

 

iProperties.GetorSetStandardiProperty(AddinGlobal.InventorApp.ActiveDocument, PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties, "", "")

Which is a lot more work...

0 Likes
Message 9 of 9

Jef_E
Collaborator
Collaborator

I don't really know if it more work @AlexFielder

 

Let me explain:

My browser displays some properties that are dear to us, instead of going to the iProperties and editing them, we can edit them in the browser. The browser will show the active document or the selected occurrence definition document (if only one is selected) it's properties.

 

So I created a class object called displayeddocument which has the variables as local and public property defined. So when I create a new displayeddocument I point my variables to the document properties and let a Getter and Setter do the work.

 

Class DisplayedDocument

    Private _Title As [Property]
    Public Property Title As String
        Get
            Title = _Title.Value
        End Get
        Set(value As String)
            _Title.Value = value
        End Set
    End Property


    Public Sub New(Byval oDoc As Inventor.Document)

        _Title = oDoc.PropertySets.Item("Inventor Summary Information").Item("Title")

End Sub End Class

Apparently I'm using string where there should not be any.. Is there also a enumerator for the property set? Or only for the property itself? On the other hand this makes the code a bit longer..

 

PropertiesForDesignTrackingPropertiesEnum.kPartNumberDesignTrackingProperties

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes