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: 

ilogic replace component with multiple different components

32 REPLIES 32
SOLVED
Reply
Message 1 of 33
Ben-Cornelius
14259 Views, 32 Replies

ilogic replace component with multiple different components

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

32 REPLIES 32
Message 21 of 33
Anonymous
in reply to: P_Korgaonkar

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

Message 22 of 33
Anonymous
in reply to: Anonymous

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.

 

Message 23 of 33
Anonymous
in reply to: Ben-Cornelius

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!

Message 24 of 33
Ben-Cornelius
in reply to: Anonymous

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. 

Message 25 of 33
Anonymous
in reply to: Ben-Cornelius

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

Message 26 of 33
chayman
in reply to: Ben-Cornelius

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

 

Message 27 of 33
chayman
in reply to: chayman

Nevermind! I figured it out.

 

Thanks for posting your solution, Ben.

Message 28 of 33
Anonymous
in reply to: Ben-Cornelius

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

 

 

Message 29 of 33
pcrawley
in reply to: Anonymous

@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
in reply to: pcrawley

@pcrawley can i put any logic like 

else

M20, M24 , M30 will change to M16 

M16, M24 , M30 will change to M20.

 

 

Message 31 of 33
pcrawley
in reply to: Anonymous

@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
in reply to: pcrawley

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

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

 

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report