Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

select 1 occurrence from multiple

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Burnit87
533 Views, 8 Replies

select 1 occurrence from multiple

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
8 REPLIES 8
Message 2 of 9
mrattray
in reply to: Burnit87

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

Message 3 of 9
alyssaweaver
in reply to: mrattray

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/

 

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 4 of 9
Burnit87
in reply to: alyssaweaver

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
Message 5 of 9
Burnit87
in reply to: Burnit87

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
Message 6 of 9
alyssaweaver
in reply to: Burnit87

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?

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 7 of 9
Burnit87
in reply to: alyssaweaver

**** 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
in reply to: Burnit87

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
Message 9 of 9
Burnit87
in reply to: Burnit87

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums