Component replace in two Cycles (subassembly then component inside subassembly)

Component replace in two Cycles (subassembly then component inside subassembly)

Tatiana_S
Participant Participant
567 Views
6 Replies
Message 1 of 7

Component replace in two Cycles (subassembly then component inside subassembly)

Tatiana_S
Participant
Participant
Component replace in two Cycles 
 

I’m currently using the code of the inventor customization link shown below to replace sub assemblies of a top level assembly, it works good.  It is set up to run a rule when a copy of the assembly opens then some sub-assemblies are replaced with new copies.

 

 http://forums.autodesk.com/t5/inventor-customization/assembly-save-as-incl-some-parts-with-ilogic-or...

 

the problem I have is trying to replace a component inside the sub assembly that has been replaced in the first cycle,

I tried to set up events to run the replace component rule when assembly opens kind of two cycles of the same rule but it doesn't work unless I open and close the assembly several times.

 

first i need to replace a sub assembly and then a part inside that sub assembly.

 

the Objective is to have a top level template assembly that will replace sub assemblies and parts inside the new sub assemblies automatically when a copy of this top level assembly is created.

 

Any ideas about how to do this with one Rule or consecutive rules rather than events to trigger the rules when the assembly opens which forces to open and close the assembly several times and is confusing for the users that work with these assemblies.

 

Thanks I appreciate your help.

 

 

Tatiana S
Design Engineer

0 Likes
568 Views
6 Replies
Replies (6)
Message 2 of 7

b_sharanraj
Advocate
Advocate

Hi @Tatiana_S 

 

Why can't you try Assembly Rebuild Option & Regenerate iLogic Code Option together in Master Assembly...

 

Add a New Rule with below Code and try once

 

For Assembly Rebuild

 Dim doc as AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument)
 If (doc Is Nothing) Then Return
 	
 Dim controlDef as ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyRebuildAllCmd")
 controlDef.Execute2(True)

 

For ILogic Regeneration 

Dim controlDef as ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.RegenAllRules")
controlDef.Execute2(True)

 

Regards

B.Sharan Raj

0 Likes
Message 3 of 7

Tatiana_S
Participant
Participant

Thanks for your help I will test it and let you know how it goes 

0 Likes
Message 4 of 7

Tatiana_S
Participant
Participant

Is there any way to regen only one Rule?, if l regen all the rules it triggers a form that we only need when the user clicks on the i-trigger command.

 

Thanks for your help 

0 Likes
Message 5 of 7

b_sharanraj
Advocate
Advocate

For Executing Specific Rule in Master Assembly

 

iLogicVb.RunRule(“Rule0”)

 

For Executing Specific Rules of a Component / Sub Assembly from Master Assembly

 

iLogicVb.RunRule("PartA:1", "Rule0")

Regards

B.Sharan Raj

0 Likes
Message 6 of 7

Anonymous
Not applicable

Hi, I share a very similar issue to yours, in fact I have raised it as an idea on this forum, perhaps you could give it a vote?

https://forums.autodesk.com/t5/inventor-ideas/ilogic-rules-trigger-on-component-replace/idc-p/704676...

 

I have a workaround for now:

 

I attached an external rule. Here is a sample rule to use it:

 

AddVbFile "RunAllRulesUnderDocument.txt"

 

Dim ruleRunner = New RunAllRulesUnderDocument(iLogicVb, Component, "") ' only need to call this once

Dim doc = ThisDoc.Document ' This is required (indirectly) by the external rule so that it can use Inventor objects.

 

If ComponentChoice = 0 Then

Component.Replace("PartX:1", "PartXdA.ipt", True)

Else

Component.Replace("PartX:1", "SubAssemRa.iam", True)

End If

ruleRunner.RunAllRules("PartX:1")

 

The New statement constructs an object. You can call RunAllRules on that object any number of times in your rule. I run it directly after my component replace function. This will only run rules in the newly-loaded documents, rather than in all open documents, which is the problem you are having when regenerating all the rules.

 

Let me know if it works for you.

0 Likes
Message 7 of 7

Tatiana_S
Participant
Participant
Thanks for your help I will try and let you how it goes




0 Likes