Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Use pick-method to acces sub-occurrence

JhoelForshav
Mentor

Use pick-method to acces sub-occurrence

JhoelForshav
Mentor
Mentor

Hi,

I'm wondering if anybody knows of a way to use the pick-method (CommandManager.Pick) to access a sub assembly two levels deep.

With kAssemblyOccurrenceFilter i can only get the first level sub assemblies. I would like to pick an assembly within a subassembly. With this selectionfilter i can't even "rightclick > select other" to accomplish this.

 

My hopes are that there should be a way to make the function ignore phantom occurrences or something like that.

 

Thanks in advance.

/Jhoel

0 Likes
Reply
951 Views
13 Replies
Replies (13)

tdant
Collaborator
Collaborator

One simple way to address your problem is to double click into the assembly above your target assembly before running the macro.

JhoelForshav
Mentor
Mentor

Hi @tdant 

Thank you for taking the time to answear. This is actually the way I do it right now and it works ok. The only thing is that it highlights parts when hovering over them and it could be a bit confusing for the end user...

I havn't been able to find a better soulution though, and I doubt that there even is one so I'll accept your answear as a solution :slightly_smiling_face:

0 Likes

JhoelForshav
Mentor
Mentor

You seem to have edited your answear to something completley different now...

That won't work for me as I want to be able to pick sub assemblies from different higher level sub assemblies...

I ended up doing a workaround where i build a Listbox containing the names of all selectable sub assemblies. Once an item in this listbox is selected i add the occurrenceproxy of that sub assembly to a highlightset to show the user which component will be selected. Then the selection is confirmed by klicking an OK-button.

 

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@JhoelForshav ,

 

You can also filter the occurrences in the OnSelect event.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

JhoelForshav
Mentor
Mentor

@chandra.shekar.g , Do you mean there are other filter options there? Can you provide an example of using the OnSelect event? :slightly_smiling_face:

/Jhoel

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@JhoelForshav ,

 

Try below iLogic code to access sub occurrence from selected object.

 

Sub Main()
 Dim oInteraction  As InteractionEvents 
 oInteraction = ThisApplication.CommandManager.CreateInteractionEvents

 Dim oSelect As SelectEvents
 oSelect = oInteraction.SelectEvents 
  
 AddHandler oSelect.OnSelect, AddressOf oSelectEvents_OnSelect

 oInteraction.Start

 
End Sub

Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As Inventor.View)
     Dim obj As Object 
	 For Each obj In JustSelectedEntities 
	 	MessageBox.Show(obj.Type)
	 Next
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



JhoelForshav
Mentor
Mentor

Hi @chandra.shekar.g,

Thank you :slightly_smiling_face:

When running this code however i only get like a couple of seconds to do my selection, and even then it behaves just like if i would have used the pick method with kAllEntitiesFilter...

 

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@JhoelForshav,

 

Yes, both pick and Onselect event are serving same purpose.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

mcloughlin_b
Enthusiast
Enthusiast
Hi Joel
This is exactly what I am looking for and have been battling for a while with the selection filters.. Are you able to share your code? Much appreciated

Bryan
0 Likes

WCrihfield
Mentor
Mentor

Hi @mcloughlin_b.  This sounds like you should be able to use SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, instead of SelectionFilterEnum.kAssemblyOccurrenceFilter.  However, that one usually just wants to focus on part type components, so it is challenging, if not impossible in certain situations to use on the regular model screen for selecting a sub-sub assembly.  In some quick testing, I was able to select a sub-sub assembly using either of those two selection filters, when I selected the browser node for it, from the model browser tree, instead of selecting it on the model screen.  That is one fairly painless workaround.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

J-Camper
Advisor
Advisor

@mcloughlin_b,

 

Another option is to "dig" into sub assemblies until you get to the occurrence you are actually looking for, then return once it is selected.  Here is a simple example:

Sub Main
	Dim aDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)
	If IsNothing(aDoc) Then Logger.Debug("ActiveDocument type is not: " & CType(aDoc.Type, ObjectTypeEnum).ToString)
	
	Dim targetOccurrence As ComponentOccurrence = DigTillPickCorrectly()
	If Not ThisApplication.ActiveEditDocument Is aDoc Then aDoc.ComponentDefinition.ActiveOccurrence.ExitEdit(ExitTypeEnum.kExitToTop)
	If IsNothing(targetOccurrence) Then Logger.Debug("Nothing Selected") : Exit Sub
		
	MessageBox.Show("Selected Occurrence: " & targetOccurrence.Name, "Result")

End Sub

Function DigTillPickCorrectly() As ComponentOccurrence
	Pick :
	Dim PickOccurrence As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select An Occurrence")
	If IsNothing(PickOccurrence) Then Return Nothing ' If nothing gets selected then we're done
	If PickOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Answer = MessageBox.Show("Selected Occurrence: " & PickOccurrence.Name & " is an Assembly, would you like to pick an occurrence within this Assembly? ", "Dig Deeper?",MessageBoxButtons.YesNo)
		If Answer = vbYes Then PickOccurrence.Edit() : GoTo Pick
	End If
	Return PickOccurrence
End Function

 

Let me know if you have any questions.

mcloughlin_b
Enthusiast
Enthusiast

hi JCamper

That's some nifty code and works really well.

I was more looking for presenting the user with a dialogue (Input list box)populated with all assemblies in the model and then highlighting on screen the model file currently selected in the dialogue. truth be told I am not even sure this is possible to change the highlighted selection in real time as the user scrolls through the list.

 

Scratching my head over this one for sure.

 

Cheers

 

Bryan

0 Likes

WCrihfield
Mentor
Mentor

Hi @mcloughlin_b.  What you described does sound possible, but it would be pretty complicated to create a code to do that.  You would have to design your own Windows Form within the code, not just use an InputListBox, and not just a simple iLogic Form.  When you create the form yourself, within the rule, you will be able to control it, and get feedback from it, when specific events happen.  You would need for this form to be 'Modal' (stays open while other stuff happens), and would needs this ability to get 'live' feedback from the form when the selection changes, without needing to click an Apply button or something like that.  But I really do not see the point in going through that much complexity and work to create something like that when the model browser pane is pretty much already a list of the components in your assembly, which you can choose one and it will be highlighted.  Why not just use the model browser pane instead.  With that you can select any level sub-component you want, in a very similar way.

But just in case you still want to pursue that direction anyways, below is a link to an article I write a few years ago which shows you an example of creating your own Windows Form within an iLogic rule.  That link will only be good for a few more days though, since Autodesk will be destroying all user submitted articles like this on March 8th.  I will also attach a PDF of that same content here, so it can live on after that point.

https://knowledge.autodesk.com/community/article/328361 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes