Create a Ribbon Button to run iLogic

Create a Ribbon Button to run iLogic

InventorMan1
Participant Participant
3,447 Views
8 Replies
Message 1 of 9

Create a Ribbon Button to run iLogic

InventorMan1
Participant
Participant

Hi,

 

I'm not too familiar with VBA but I have been using iLogic in order to set up some basic data on some part/assembly-files. I cannot create myself a different template, as my company restricts this.

 

Thing I need:
 - New custom iProperties. I've been using iProperties.Value-snippet.

 - New parameters, with certain formatting. For this i have used iLogic, shown below:

 

doc = ThisDoc.Document 'Defining document and providing access to parameters on different levels.

Dim oPartCompDef As PartComponentDefinition = doc.ComponentDefinition

Dim oParams As Parameters = oPartCompDef.Parameters

Dim oUserParams As UserParameters = oParams.UserParameters

 

oUserParams.AddByValue(“XXX_LENGTH”, 0, “mm”) 'Creating needed XXX-parameters.

 

oLength = Parameter.Param("XXX_LENGTH") 'Defining Custom Properties for parameter

oLength.ExposedAsProperty = True

oFormat=oLength.CustomPropertyFormat

oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType

oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision

 

My question is, how could I create a button to my Inventor ribbon, that could run these kind of iLogic codes?

 

-Ossi

0 Likes
Accepted solutions (1)
3,448 Views
8 Replies
Replies (8)
Message 2 of 9

JamieVJohnson2
Collaborator
Collaborator

iLogic's only easy method is the iLogic browser which is not ribbon based, but it is a nifty dockable palette.  However, iLogic editor allows you to write VB.Net code, from there you can write a command that can edit the ribbon, and add one or many CommandControls.  If your going that far, you could write a complete add-in using straight up vb.net and visual studio, that autoloads every time Inventor opens (next level stuff = learning curve).

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 3 of 9

Jesper_S
Collaborator
Collaborator

Hi.

If the iLogic rules are placed in the documents, use this VBA code.

Add it to a Module in the VBA editor.

 

Public Sub LaunchMyRule1   '<--- This is what you would tie to a button in a toolbar.
  RuniLogic "MyRule1"      '<--- Name of your iLogic rule
End sub
 
Public Sub LaunchMyRule2   '<--- This is what you would tie to a button in a toolbar.
  RuniLogic "MyRule2"      '<--- Name of your iLogic rule
End sub

Public Sub RuniLogic(ByVal RuleName As String)
  Dim iLogicAuto As Object
  Dim oDoc As Document
  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If
  Set iLogicAuto = GetiLogicAddin(ThisApplication)
  If (iLogicAuto Is Nothing) Then Exit Sub
  iLogicAuto.RunRule oDoc, RuleName
End Sub
 
Public Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function

Then just add it to your ribbon.

Ribbon.JPG

 


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 4 of 9

InventorMan1
Participant
Participant

Is it possible to do a iLogic Browser rule, that is always in the application, no matter what part-file is open?

 

So, that when I'm creating a new file, I could just run the rule and get the properties updated?

 

-Ossi

0 Likes
Message 5 of 9

InventorMan1
Participant
Participant

Hi,

 

Thanks for the code. Unfortunately, when I create a new file, the rule is not in place in the file. That is the root problem.

 

Currently I just create a new rule, copy-paste the code from word-file and run the rule. Code itself includes line, that removes the rule. So situation is quite decent, but it's always nice, when you can reduce the amount of clicks.

 

-Ossi

0 Likes
Message 6 of 9

Jesper_S
Collaborator
Collaborator
Accepted solution

Hi.

 

Either you place the Rule in your Templates so it's always there.

Or you place your Rule as an External Rule in Inventor.

 

Why do you remove the code?

 

Can't you add the parameters and iProperty to your Templates?


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 7 of 9

InventorMan1
Participant
Participant

Hi,

 

That's the problem, I cannot modify the templates as our company overviews them. I delete the rule as later on the model will be used by people, who are not familiar with iLogic and it is not necessary. Kind of cleaning the model.

 

But the idea of external rule is perfect! I don't know why I didn't figure it out by myself 😄 But this will work on my case, thanks !

 

-Ossi

 

 

0 Likes
Message 8 of 9

Jesper_S
Collaborator
Collaborator

Create an External rule.

Then add this to VBA instead.

Public Sub LaunchMyRule1()
RuniLogic ("MyRule1")
End Sub
Public Sub LaunchMyRule2() RuniLogic ("MyRule2") End Sub
Public Sub RuniLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document Set oDoc = ThisApplication.ActiveEditDocument If oDoc Is Nothing Then MsgBox "Missing Inventor Document" Exit Sub End If Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub iLogicAuto.RunExternalRule oDoc, RuleName End Sub Public Function GetiLogicAddin(oApplication As Inventor.Application) As Object Dim addIn As ApplicationAddIn On Error GoTo NotFound Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") If (addIn Is Nothing) Then Exit Function addIn.Activate Set GetiLogicAddin = addIn.Automation Exit Function NotFound: End Function

Same thing but this works with External rules.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 9 of 9

Anonymous
Not applicable

Works fantastic! I just had to change the module name, and presto!

 

Thank you.

0 Likes