ilogic replace component with multiple different components

ilogic replace component with multiple different components

Ben-Cornelius
Collaborator Collaborator
15,085 Views
32 Replies
Message 1 of 33

ilogic replace component with multiple different components

Ben-Cornelius
Collaborator
Collaborator

So I have been going round and round in circles on this one iam trying to use replace component within ilogic which is fine with switching one part for another but I want a drop down of parts so it replaces which ever one is active the problem I am having is establishing which one is active. So below is what I have so far but the problem is you cant seem to reference a part that is not in the assembly so I keep getting the error

The component named "Flange 1" was not found for example. Any ideas? I just need a way of establishing which one is currently in the assembly but with out referencing components that are not there.

 

 

 

If Component.IsActive("Flange 1")=True Then current = 1

If Component.IsActive("Flange 2")=True Then current = 2

If Component.IsActive("Flange 3")=True Then current = 3

 

If part = 1 And current = 2 Then Component.Replace("flange 2", "Flange 1.ipt", True) End If

If part = 1 And current = 3 Then Component.Replace("flange 3", "Flange 1.ipt", True) End If

If part = 2 And current = 1 Then Component.Replace("flange 1", "Flange 2.ipt", True) End If

If part = 2 And current = 3 Then Component.Replace("flange 3", "Flange 2.ipt", True) End If

If part = 3 And current = 1 Then Component.Replace("flange 1", "Flange 3.ipt", True) End If

If part = 3 And current = 2 Then Component.Replace("flange 2", "Flange 3.ipt", True) End If

Accepted solutions (1)
15,086 Views
32 Replies
Replies (32)
Message 2 of 33

pcrawley
Advisor
Advisor

Put all the parts in the assembly - then suppress the ones you don't want using iLogic.

The iLogic suppression is different to the Inventor LOD suppression in that it effectively removes the part from the BOM - so an iLogic suppression becomes really useful.

Peter
0 Likes
Message 3 of 33

Ben-Cornelius
Collaborator
Collaborator

Yeah i know you can do that and also using iparts but I would like the option to do this way and to know if this is even possible

0 Likes
Message 4 of 33

Anonymous
Not applicable
Hi,
Do check out the below link
https://grabcad.com/library/ilogic-place-replace-remove-component-in-assembly-1

Do check out the video to understand the ilogic program....
hope the assembly file with ilogic code in my Grabcad site answers your requirement.....
0 Likes
Message 5 of 33

Ben-Cornelius
Collaborator
Collaborator
Accepted solution

thanks but not really what I wanted but I have now figured it out so for anyone fustrated trying to do this here is the code. So the first line gets the components name based on its browser location so that can't change.

 

My_Variable2 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(2).Name
 


If flange = 1 Then
Component.Replace(My_Variable2, "Flange 1.ipt", True)

End If

If flange = 2 Then
Component.Replace(My_Variable2, "Flange 2.ipt", True)

End If

If flange = 3 Then
Component.Replace(My_Variable2, "Flange 3.ipt", True)


End If

 

 

and so on.......

Message 6 of 33

Anonymous
Not applicable

Hello,

I was wondering do you happen to know how to add rules to replace the ipart component? If there is any example for that? Thank you!

0 Likes
Message 7 of 33

Ben-Cornelius
Collaborator
Collaborator

well normally you would just change the row of the ipart so iPart.ChangeRow("iComponentName:1", "RowMemberName"). Are you referring to that or do you want to completely replace this with another component or ipart?

0 Likes
Message 8 of 33

Anonymous
Not applicable
Yes, this answered my question! Thank you very much!
0 Likes
Message 9 of 33

P_Korgaonkar
Advocate
Advocate

Hello There,

 

Thanks for your post,

 

I am trying to do the same.

I have an assembly where I have 20,30,35 or 40 mm bearing.

I need to replace bearing to suit correct size.

I have started with 25 mm bearing, and able to change 25 mm to suit other sizes.

But once I have changed size, I am not able to change it to suit other size, as 25 mm bearing does not exsist in assembly.

 

 

If Bearing_DIA_D=35 Then

Component.Replace("FB205 (25):1", "FB207 (35).ipt", True)

Else If Bearing_DIA_D=30 Then

Component.Replace("FB205 (25):1", "FB206 (30).ipt", True)

Else If Bearing_DIA_D=40 Then

Component.Replace("FB205 (25):1", "FB208 (40).ipt", True)

End If



InventorVb.DocumentUpdate()

 

Your code seems the solution for my problem, but as I do not have programming background, got a bit confused on how to use it.

Can you please help by giving explainaton of each line in code and each function?

 

Regards

Paarg

Message 10 of 33

Ben-Cornelius
Collaborator
Collaborator

Hi

 

So what this is doing is getting the name based upon the browser location so you will have to change the item number based on where the part is that you want to change

 

My_Variable2 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(2).Name

 

If Bearing_DIA_D=35 Then

Component.Replace(My_Variable2, "FB207 (35).ipt", True)

Else If Bearing_DIA_D=30 Then

Component.Replace(My_Variable2, "FB206 (30).ipt", True)

Else If Bearing_DIA_D=40 Then

Component.Replace(My_Variable2, "FB208 (40).ipt", True)

End If



InventorVb.DocumentUpdate()

0 Likes
Message 11 of 33

P_Korgaonkar
Advocate
Advocate

Hello Bendesign04 (Sorry not sure what your name is!)

 

 

New to this site, didnot get email about your reply,

Just logged in to check and got your reply, checked it straight away.

 

Thank you,

That worked.

 

Much appriciate your support and help.

 

Regards

Parag

0 Likes
Message 12 of 33

P_Korgaonkar
Advocate
Advocate

Hello All,

 

Once again I have run in to issue.

 

When I replcae part using following code, it is replacing all parts rather than only one instance.

 

I have Cover (206):1 in position 4

and

Cover (206):2 in position 6.

 

I want to change only one of them depending on statement/condition.

 

but code i have written below replaces both covers.

 

I tied additional 0 and 1 after last comma, but made no differnce. any suggessitons?

 

SyntaxEditor Code Snippet

My_Variable3 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(3).Name
My_Variable4 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(4).Name
My_Variable5 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(5).Name
My_Variable6 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(6).Name



If Bearing_DA=30 And SIDE_NO = 1 ul Then

Component.Replace(My_Variable3, "FB206 (30).ipt", True, 0)
Component.Replace (My_Variable4, "Cover (206).ipt" , True, 0)
Component.Replace(My_Variable6, "Cover Closed (206).ipt", True, 0)

Else If Bearing_DA=30 And SIDE_NO = 0 ul Then

Component.Replace(My_Variable3, "FB206 (30).ipt", True, 0)
Component.Replace (My_Variable4, "Cover Closed (206).ipt" , True, 0)
Component.Replace(My_Variable6, "Cover (206).ipt", True, 0)

End If

 

 

0 Likes
Message 13 of 33

Curtis_Waguespack
Consultant
Consultant

Hi parag,

 

To replace just one instance of the component change the variable after the component name, from True to False as shown:

 

ComponentOccurrence.Replace( FileName As String, ReplaceAll As Boolean )

True = ReplaceAll 

 

Component.Replace("My_Part_File.ipt", False)

 

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

Message 14 of 33

P_Korgaonkar
Advocate
Advocate
Thanks Curtis,
It worked.

My work colleague mentioned your name yesterday, I searched for you on google and visited your blog
Great work,
Thanks a ton for your contribution to CAD community.

Is there any online resource which explains every possible command in Ilogic with its sub options like this one you explained.

thanks once again

Regards
Parag
0 Likes
Message 15 of 33

Curtis_Waguespack
Consultant
Consultant

Hi parag,

 

You can find the Inventor API Help files and Example code by going to the Help link within in Inventor (top right corner) as shown here:

 

Autodesk Inventor Programming Example Help.png

 

Autodesk Inventor Programming Example Help2.png

 

 

Autodesk Inventor Programming Example Help3.PNG

 

 

And here are some other links:

http://usa.autodesk.com/adsk/servlet/index?id=1079044&siteID=123112

http://inventortrenches.blogspot.com/2013/10/ilogic-how-to-learn-inventors.html

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 16 of 33

P_Korgaonkar
Advocate
Advocate

Thanks Curtis,

 

Very useful inormation.

 

Regards

Parag

0 Likes
Message 17 of 33

Anonymous
Not applicable

While what Ben has told you is a completely viable option, it can be done in a simpler manner.

 

Instead of basing your code on the item location, simply "stabilize" the item name. This way it will not change after your iLogic script runs.

In your browser double-click (slow click) on your component. Change it to something such as "Bearing". Your code would then look like this:

 

 

If Bearing_DIA_D=35 Then

Component.Replace("Bearing", "FB207 (35).ipt", True)

Else If Bearing_DIA_D=30 Then

Component.Replace("Bearing", "FB206 (30).ipt", True)

Else If Bearing_DIA_D=40 Then

Component.Replace("Bearing", "FB208 (40).ipt", True)

End If

 

0 Likes
Message 18 of 33

P_Korgaonkar
Advocate
Advocate

Thanks Andrew,

 

Yes what you say is right, but it brings along limitations.

You can change that part once only, once the part is replaced, the name changes, and you cant replace it anymore because of different name.

 

 

Unless you can guide me to replace the name of part after it is placed in to assembly to be same as before replacement, in this case "Bearimg"

is ther a way to do it?

so after the replacement, next line of code would change that name to become Bearing again!

 

Regards

Parag

0 Likes
Message 19 of 33

Anonymous
Not applicable

The code SyntaxEditor Code Snippet

ThisDoc.Document.ComponentDefinition.Occurrences.Item(2).Name

will return the part name in this top level assembly. but what should I use if I need one from a sub assembly?

0 Likes
Message 20 of 33

P_Korgaonkar
Advocate
Advocate

Hello sharathsb721

 

with my limited knowledge and experience,

this is what I have done.

 

I have named every instance of component I may replace.

 

Capture.PNG

 

and in code I have given instance name.

 

It works for me.

 

Haven't tried in sub assembly level.

 

as an option you ,may run code from sub assembly.

Or some one will suggest code for sub assembly.

 

SyntaxEditor Code Snippet

'[
If Bearing_DA=20 And SIDE_NO = 1 ul Then 'Side A when bearing is inside
Component.Replace("Bearing DA" , "FB204 (20).ipt", False)
Component.Replace ("Cover DA", "Cover (204).ipt" , False)


Else If Bearing_DA=20 And SIDE_NO = 0 ul Then 'Side B when bearing is inside
Component.Replace("Bearing DA", "FB204 (20).ipt", False)
Component.Replace ("Cover DA", "Cover Closed (204).ipt" , False)

End If
']

all the best

regards

parag

 

0 Likes