select 1 occurrence from multiple

select 1 occurrence from multiple

Burnit87
Contributor Contributor
759 Views
8 Replies
Message 1 of 9

select 1 occurrence from multiple

Burnit87
Contributor
Contributor

i'm need some help with selecting 1 part from multi select

im building a dxf generator and i can select an entire assembly and it just fishes out the sheet metal, but when i select the same part a couple of times it wil do it  multiple times and thats just a wast of time

so what im basicly looking for is the code that does the opposite of select all occurrences,

so i got a bunch selected and i just want 1 of each parts so part1 1 time , part2 1 time and so on...

tried the ComponentOccurrencesEnumerator, but cant get it to work in a selectset ( so i can count how many times i selected part1)

any ideas someone?

would me very appreciated!!

thanks in advance

Björn

 

BP
0 Likes
Accepted solutions (4)
760 Views
8 Replies
Replies (8)
Message 2 of 9

mrattray
Advisor
Advisor
I'm not sure how to solve your issue, but I believe there is a free add-in available on the app exchange to accomplish this already.
Mike (not Matt) Rattray

0 Likes
Message 3 of 9

Anonymous
Not applicable

I'm not positive this is what you want, but check this out. It allows you to select some occurences rather than all.

 

http://designandmotion.net/autodesk/replace-some-components-in-inventor-2014/

 

 

Message 4 of 9

Burnit87
Contributor
Contributor

ok i tell step by step what i want it to do

- first ill set my selection to part priority

- then select complete assembly

- check for double selection

- take sheet metal parts

- run t he dxf genereator for

 

and the double selection part is where im having troubles, cause if a part is selected 6 times the dxf generator will unfold it 6 times and export it 6 times, wich costs a lot of time, if you got muliple  patterns, and i dont want to hand pick every component.

so basicly i want it to check if a part is being selected multiple occurrences and then deselect all but one.

 

BP
0 Likes
Message 5 of 9

Burnit87
Contributor
Contributor

this is how far i've got, it works sort of but it now keeps de-selecting everything that had more then one selection, im looking for a way to update my selectset

 

'check if the same part is selected multiple times

ForEach prtDocOcc As ComponentOccurrence In SelSet

ForEach prtDocOcc2 As ComponentOccurrence In SelSet

If prtDocOcc.Definition.Document.fullfileName = prtDocOcc2.Definition.Document.fullfileName Then

If prtDocOcc.Name <> prtDocOcc2.Name Then

SelSet.Remove(prtDocOcc2)

'update selectset or it will de-selecting everything that had more then 1 occ selected

EndIf

EndIf

Next

Next



BP
0 Likes
Message 6 of 9

Anonymous
Not applicable
Accepted solution

The code on that link I sent you should allow you to select the single occurrence from the get go. Is that not acceptable for what you want to do?

Message 7 of 9

Burnit87
Contributor
Contributor
Accepted solution

**** missed it,

been searching al day for a solution but i fixed it

thank you a whole lot

 

redo:

'check if the same part is selected multiple times

ForEach prtDocOcc AsComponentOccurrenceIn SelSet

ForEach prtDocOcc2 AsComponentOccurrenceIn SelSet

If prtDocOcc.Definition.Document.fullfileName = prtDocOcc2.Definition.Document.fullfileName Then

If prtDocOcc.Name <> prtDocOcc2.Name Then

SelSet.Remove(prtDocOcc2)

GoTo redo

EndIf

EndIf

Next

Next

BP
Message 8 of 9

Burnit87
Contributor
Contributor
Accepted solution

ran into anthoter problem, when you have  multiple subassemblies you'll need an extra if

 

redo:

'check if the same part is selected multiple times

ForEach prtDocOcc AsComponentOccurrenceIn SelSet

ForEach prtDocOcc2 AsComponentOccurrenceIn SelSet

If prtDocOcc.Definition.Document.fullfileName = prtDocOcc2.Definition.Document.fullfileName Then

If prtDocOcc.Name <> prtDocOcc2.Name Then

SelSet.Remove(prtDocOcc2)

GoTo redo

ElseIf prtDocOcc.Name = prtDocOcc2.Name Then

Try

If prtDocOcc.ParentOccurrence.Name <> prtDocOcc2.ParentOccurrence.Name Then

SelSet.Remove(prtDocOcc2)

GoTo redo

EndIf

Catch ex AsException

EndTry

EndIf

EndIf

Next

Next

BP
0 Likes
Message 9 of 9

Burnit87
Contributor
Contributor
Accepted solution

and worked out another solution for big assemblies, cause the current loop takes 3 to 4 times as long

 

'check if the same part is selected multiple times

Dim firstLoopCounter AsInteger = 1

Dim secondLoopCounter AsInteger = 1

Dim toRemove AsNewCollection

ForEach prtDocOcc AsComponentOccurrenceIn SelSet

secondLoopCounter = 1

ForEach prtDocOcc2 AsComponentOccurrenceIn SelSet

If secondLoopCounter > firstLoopCounter Then

If prtDocOcc.Definition.Document.fullfileName = prtDocOcc2.Definition.Document.fullfileName Then

If prtDocOcc.Name <> prtDocOcc2.Name Then

toRemove.Add(prtDocOcc2)

ElseIf prtDocOcc.Name = prtDocOcc2.Name Then

Try

If prtDocOcc.ParentOccurrence.Name <> prtDocOcc2.ParentOccurrence.Name Then

toRemove.Add(prtDocOcc2)

EndIf

Catch ex AsException

EndTry

EndIf

EndIf

EndIf

secondLoopCounter = secondLoopCounter + 1

Next

firstLoopCounter = firstLoopCounter + 1

Next

ForEach prtDocToRemove AsComponentOccurrenceIn toRemove

SelSet.Remove(prtDocToRemove)

Next

BP