add trigger to select existing parts

add trigger to select existing parts

cadman777
Advisor Advisor
408 Views
5 Replies
Message 1 of 6

add trigger to select existing parts

cadman777
Advisor
Advisor

Hello Everyone,

I need to add a trigger for a simple ilogic rule to all the frame generator members in a top level assembly (has many subassemblies in separate folders on the drive).

Cant' find how to do it in this forum or online.

Last year I read about a couple guys doing it, but can't find the links.

Does anybody have any simple method/code for doing this?
I'm novice or worse at this coding, so any help is appreciated.

Need to add the rule to 400+ parts, and I know my wrists can't take that many mousings/keyings!

Thanx ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
409 Views
5 Replies
Replies (5)
Message 2 of 6

cadman777
Advisor
Advisor

Never mind, I found the link:

https://forums.autodesk.com/t5/inventor-customization/adding-an-ilogic-rule-to-an-event-trigger-with...

If anybody has anything newer that'll work with IV2010, I'd be very grateful.

This code only works with IV2011 and newer.

Bummer!

RSI here we come!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

What kind of trigger do you need?

What kind of event do you want to trigger some code to run?

Would an external iLogic rule that, when ran, creates and injects a local iLogic rule into another document (or series of other documents, such as your top level assembly components) work for you?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

cadman777
Advisor
Advisor

I need the BOM to report the exact length of the cut and trimmed FG member.

jtyler gave me a piece of code that I had to slightly modify to get to work, and it works like a charm!

However, there were so many parts to change (b/c the models were already done) that it nearly killed my wrists and eyes!

So it's done for now.

Hopefully I'll never have to go through THAT again!

(I'm adding the code to my CC parts for future use, b/c that stupid built-in dimension isn't worth a s**t).

Thanx for asking ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

I don't know if it's much help at this point, but maybe it could save you some trouple in the future.

Below is a simple example of some iLogic code you can use in an external iLogic rule, that will inject a local rule into every reference document of your active assembly document.  This example is just adding a little automation into each part file, that causes it to do a document update, then Home the view (same as clicking the home icon above the view cube) after every time the "CUT_LENGTH" parameter changes within that part.

 

You can replace all the oRuleText with other content as needed for your situation, though.

Instead of looping through each ComponentOccurrence, it only loops through each actual Document being referenced by the assembly.  Then it checks to see if this rule already exists within that document.  If it does, it asks you if you want to replace its contents with the new contents (oRuleText).  If it doesn't exist, it creates it for you.

 

I put a bunch of extra quoted out lines in there to help explain what is being done.

Dim oRuleName As String = "Update Doc & Home View"
Dim oRuleText As String
oRuleText = _
"oDV = CUT_LENGTH" & vbCrLf &
"InventorVb.DocumentUpdate()" & vbCrLf &
"'Return view to Home View" & vbCrLf &
"ThisApplication.CommandManager.ControlDefinitions.Item(""AppViewCubeHomeCmd"").Execute"

'oDV (above) is just a 'dummy variable', which isn't used for anything.
'It's value though is the name of a Parameter, which is local to that Document,
'so it will trigger the local rule to run any time that specific parameter changes.
'No need to add this rule to an Event Trigger to make this work.


Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim iLogicAuto = iLogicVb.Automation
'Dim oRules As IEnumerable
Dim oRule As iLogicRule
Dim oRuleExists As Boolean = False
Dim oRefDoc As Document
For Each oRefDoc In oADoc.AllReferencedDocuments
	Try
		oRule = iLogicAuto.GetRule(oRefDoc, oRuleName)
		oAns = MsgBox("A Rule named '" & oRuleName & "' already exists." & vbCrLf &
		"Its Text = " & vbCrLf &
		oRule.Text & vbCrLf &
		"Do you want to replace its text?", vbYesNo + vbQuestion,"")
		If oAns = vbNo Then Return
	Catch
		oRule = iLogicAuto.AddRule(oRefDoc, oRuleName, "")
	End Try
	'Setting the rule's text at this point, instead of above,
	'causes the rule to not run as soon as it is created.
	'If you want the rule to run as soon as it is created,
	'put oRuleText where the empty quotes are in the Catch line above.
	oRule.Text = oRuleText
	iLogicVb.DocumentUpdate
	oRefDoc.Save
Next

 

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Create Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

cadman777
Advisor
Advisor

Hey, thanx for volunteering this code!

When I get a break from 'real busy', I'll give it a try.

 

How good are you at writing code?
I need some macros that, if you're good at it, I would be willing to pay you a reasonable fee to do them for me, if you're interested, and  if you can do what I want.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes