ilogic replace component with multiple different components

ilogic replace component with multiple different components

Ben-Cornelius
Collaborator Collaborator
15,113 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,114 Views
32 Replies
Replies (32)
Message 21 of 33

Anonymous
Not applicable

yeah, as per your idea works fine in normal assemblies. but when doing a pattern, it goes out of scope

0 Likes
Message 22 of 33

Anonymous
Not applicable

Hi all,

 

This thread has saved me a lot of headaches, thanks for all the advice from everyone here.

 

In my case, I will be repeatedly placing my subassembly into another assembly as an ilogic component.

 

I have 2 issues that I am desperate for help on:

 

1.

Because I am generating new parts when I place the subassembly as an ilogic component, my generated parts have the added extension "... -01, -02, -03, etc"

Here is my code:

 

SyntaxEditor Code Snippet

If ProfileType = "Open" Then
Component.Replace("Top Horizontal", "FA001H.ipt", True)
Component.Replace("Bot Horizontal", "FA001H.ipt", True)
Component.Replace("Left Vertical", "FA001V.ipt", True)
Component.Replace("Right Vertical", "FA001V.ipt", True)

iLogicVb.RunRule("Linked Parameters")

End If

If ProfileType = "Open Dual" Then
Component.Replace("Top Horizontal", "FA002H.ipt", True)
Component.Replace("Bot Horizontal", "FA002H.ipt", True)
Component.Replace("Left Vertical", "FA002V.ipt", True)
Component.Replace("Right Vertical", "FA002V.ipt", True)

iLogicVb.RunRule("Linked Parameters")
End If

 How can I account for the added "-01, -02, -03, etc" that is added onto my part file in the rule?

I.e., my generated part files are "FA001H-01.ipt", "FA002H-01.ipt", etc

 

I appreciate any guidance.

 

0 Likes
Message 23 of 33

Anonymous
Not applicable

Ben, I have two follow up questions to component.replace . Does the active component and the desired component need to exist in the same folder path? Or is there a way to reference a new folder path?

 

Also, will constraints transfer over to the desired component? Or will they be free when they are brought in?

 

I am currently using component.isactive to suppress and unsuppress several variations of parts in an assembly based on parameters pulled from an excel spreadsheet.  All of the parts are modeled in the same orientation, so if I have the components constrained based on the origin axes there should be no issue, correct?

 

Thank you!

0 Likes
Message 24 of 33

Ben-Cornelius
Collaborator
Collaborator

No you can specify the file path. The constraints will transfer if for example if its a copy of a part but it also depends on how you are constraining it. If you are using traditional constrains for example face to face you may have issues if the size of the component is different. I personally hate traditional constrains so in the case of project based components I am modelling this in correct coordinate space so skeleton modelling then flushing the planes to the origin of the assembly or in the case of reused components or library base components I am constraining to the skeleton place inside the assembly with workfeatures and geometry from the derived skeleton within the part (this is to avoid constraining to the solid body of the part where features could change and fail). This avoids the domino effect of multiple dependencies that can change instead pull it back to one dependent the assembly origin which is fixed can not change and can not be deleted or in the case of the skeleton the parts will move with the skeleton as the skeleton is changed. Which means parts have no constraint dependents to other parts making your assembly robust and reliable as possible. So if do a replace it will not effect anything else and constraints will not blow up. 

0 Likes
Message 25 of 33

Anonymous
Not applicable

Thank you for the explanation! I may try this on my next model to save the hassle of overloading the browser with components.

0 Likes
Message 26 of 33

chayman
Enthusiast
Enthusiast

Hi Ben -

 

I believe I am having the same issue as you were.

I am somewhat new to iLogic so can you please explain to me a little more about the first line?

 

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

 

What is Item(2)?

 

Here is my code (I get an error saying "P24 - Blade:1" not found) and I believe your solution will be mine but I don't know how to make it work.

 

SyntaxEditor Code Snippet

If Model = "P22" Then
Component.Replace("P24 - Blade:1", "C:\Users\dgauthier\Desktop\Inventor Templates\Plug Fans\Fans\AF Wheels\NEW\Blades\P22 - Blade.ipt", True)

Else If Model = "P24" Then
Component.Replace("P27 - Blade:1", "C:\Users\dgauthier\Desktop\Inventor Templates\Plug Fans\Fans\AF Wheels\NEW\Blades\P24 - Blade.ipt", True) 

Else If Model = "P27" Then
Component.Replace("P24 - Blade:1", "C:\Users\dgauthier\Desktop\Inventor Templates\Plug Fans\Fans\AF Wheels\NEW\Blades\P27 - Blade.ipt", True)

End If

 

0 Likes
Message 27 of 33

chayman
Enthusiast
Enthusiast

Nevermind! I figured it out.

 

Thanks for posting your solution, Ben.

0 Likes
Message 28 of 33

Anonymous
Not applicable

hi

i am trying to  do the same for replacing hardware in my assembly these hardware are kept in project folder 

here i want to change/replace the  same from fx parameter list,

please ref. attached pdf where i explained the complete scenario.

 for over view please find the code

  SyntaxEditor Code Snippet

If END_ROD_SIZE = "M16" Then
Component.Replace("PLAIN WASHER M20:1", "PLAIN WASHER M16.ipt", True)
Component.Replace("PLAIN WASHER M24:1", "PLAIN WASHER M16.ipt", True) 
Component.Replace("PLAIN WASHER M30:1", "PLAIN WASHER M16.ipt", True) 
Component.Replace("HEX NUT M20:1", "HEX NUT M16.ipt", True)
Component.Replace("HEX NUT M24:1", "HEX NUT M16.ipt", True) 
Component.Replace("HEX NUT M30:1", "HEX NUT M16.ipt", True) 
Component.Replace("HEX LOCK NUT M20:1", "HEX LOCK NUT M16.ipt", True)
Component.Replace("HEX LOCK NUT M24:1", "HEX LOCK NUT M16.ipt", True)
Component.Replace("HEX LOCK NUT M30:1", "HEX LOCK NUT M16.ipt", True)
End If

 

 

0 Likes
Message 29 of 33

pcrawley
Advisor
Advisor

@Anonymous - You've put a lot of work into that model, and I understand your frustration having reached a point where it really should work... but it just won't!

 

The error message says: Error in rule: END ROD HARDWARE M20

Then it goes on to say:  The component named "PLAIN WASHER M24:1" was not found.

 

Unfortunately, we can't see the model browser from any of your screenshots, so can't confirm the part exists at the time you run the rule.  I suspect you may be coming to this M20 configuration from a configuration where the PLAIN WASHER M24:1 doesn't already exist.

 

There is a process called "normalising" which makes dealing with this type of scenario much easier.  It's covered very well here: https://designandmotion.net/autodesk/inventor/ilogic-assemblies-its-wise-to-normalise/

 

Hope this helps.

Peter
Message 30 of 33

Anonymous
Not applicable

@pcrawley can i put any logic like 

else

M20, M24 , M30 will change to M16 

M16, M24 , M30 will change to M20.

 

 

0 Likes
Message 31 of 33

pcrawley
Advisor
Advisor

@Anonymous Ok, it sounds as though your logic works as expected - but the error remains -The component named "PLAIN WASHER M24:1" was not found.  

 

Are you able to check that PLAIN WASHER M24:1 does exist? 

Is it possible the part is actually called PLAIN WASHER M24:?

 

This is where the normalising process helps because you are not worrying about instance numbers for component identification.

Peter
Message 32 of 33

P_Korgaonkar
Advocate
Advocate

Hello Vaman,

Once you normalize the assembly as per link given above. It should work fine.

The code will become a lot easier too.

If still issues, upload assembly with parts, I can give it a try.

 

Regards

Parag

Message 33 of 33

Anonymous
Not applicable

hi @P_Korgaonkar  @pcrawley @Ben-Cornelius

it works fine after normalize the components, code is more simple now 

thanks & appreciate your support

 

is their any rule to constant the occurrence nos. like 2,3,4,5....

right now whenever i change my inputs(variables) it has changed as per below image.

or this is fine with this change

 

 

TREE.JPG

 

@pcrawley  : thanks for the video link

 

 

0 Likes