- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
//Jesper
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.