Add selection filter to ilogic code

Add selection filter to ilogic code

Anonymous
Not applicable
4,038 Views
6 Replies
Message 1 of 7

Add selection filter to ilogic code

Anonymous
Not applicable

Hi,

I was kindly given this code below by another user. The code is in a part file and is triggered by an 'form' when you insert the part into an assemble.

 

The assembly default selection filter is "Component priority" but I need it to be "Select faces and edges" while I pre select the edge befo

re running the rule. After I have run the rule I want the selection filter to revert back to "Component priority" 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 10155 StartFragment: 314 EndFragment: 10123 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Dim_Length
Dim oApp As Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

' Get selection set
Dim oSelSet As SelectSet
oSelSet = oDoc.SelectSet

' If no objects are selected, then exit
If oSelSet.Count = 0 Then
MsgBox("You must pre select a line before running this rule",vbOKOnly, "Warning")
Exit Sub
End If


Dim oEdge As Object
' Get Edge or EdgeProxy object (Edge for part environment and EdgeProxy for assembly environment)
oEdge = oSelSet.Item(1)

' If selected object is not of type Edge or EdgeProxy then exit
If (Not TypeOf oEdge Is Edge) And (Not TypeOf oEdge Is EdgeProxy) Then
    Exit Sub
End If

' Get length between endpoints of edge [cm]
Dim dLength As Double
dLength = oApp.MeasureTools.GetMinimumDistance(oEdge.StartVertex, oEdge.StopVertex)*10

' Display length of line
MsgBox(dLength & " mm",vbOKOnly, "Length dim")
End Sub

 

 

 

This is beyond my skill level so any help would be appriecated

thanks

M

0 Likes
Accepted solutions (1)
4,039 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor
Accepted solution
There is no easy way to really set it before (unless you make a 2nd rule or change how this one works), so this will error out the first time you run it, but will change the selection priority so it is correct when you select the parts again. it will change back to component selection when the rule is successfully run.
Sub Dim_Length
Dim oApp As Application
oApp = ThisApplication

Dim oDoc As Document
oDoc = oApp.ActiveDocument

oDoc.SelectionPriority = 67587 'Edge and face
' Get selection set Dim oSelSet As SelectSet oSelSet = oDoc.SelectSet ' If no objects are selected, then exit If oSelSet.Count = 0 Then MsgBox("You must pre select a line before running this rule",vbOKOnly, "Warning") Exit Sub End If Dim oEdge As Object ' Get Edge or EdgeProxy object (Edge for part environment and EdgeProxy for assembly environment) oEdge = oSelSet.Item(1) ' If selected object is not of type Edge or EdgeProxy then exit If (Not TypeOf oEdge Is Edge) And (Not TypeOf oEdge Is EdgeProxy) Then Exit Sub End If ' Get length between endpoints of edge [cm] Dim dLength As Double dLength = oApp.MeasureTools.GetMinimumDistance(oEdge.StartVertex, oEdge.StopVertex)*10
oDoc.SelectionPriority = 67590 'component
' Display length of line
MsgBox(dLength & " mm",vbOKOnly, "Length dim")
End Sub 

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 7

Anonymous
Not applicable

The part is added via "place illogic component" so I have used your code and set an "event trigger" to run the rule on "new document". This works to set the selection filter without having to run the rule twice.

 

Thanks for the help

M

0 Likes
Message 4 of 7

Anonymous
Not applicable

@MechMachineMan Can you post a link to where you found what numbers to use? ie. 67587

 

oDoc.SelectionPriority = 67587 'Edge and face

Thanks!

0 Likes
Message 5 of 7

MechMachineMan
Advisor
Advisor

@Anonymous 

 

There are a few ways. The ones I know of are:

 

Easiest for people new to iLogic:

1a)

 

Sample.JPG

 

1b) (Also found at:)

          C:\Users\Public\Documents\Autodesk\Inventor 2017\Local Help

      - I made a shortcut to this file and keep in on the desktop to use as a quick reference.

 

2) Any VBA editor Object Browser that has "Inventor Object Library" added as a reference.

      -- This can be in Excel VBA editor with the reference added

      -- Can also be directly found through inventor vba editor object browser (Alt + F-11, then F2)

 

From there, it's just a matter of searching within either resource to find it.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 7

Anonymous
Not applicable

I am able to find the SelectionPriorityEnum like kEdgeAndFaceSelectionPriority I've just never see any reference to the numbers you used.

 

EDIT: Never mind I see it at the bottom of the object browser now. Thank you!

0 Likes
Message 7 of 7

MechMachineMan
Advisor
Advisor

@Anonymous 

 

I already took screenshots, so I will post them anyways for anyone who might need them in the future.

 

As in: admapi_21_.chm

Sample2.JPG

 

 

As in VBA Editor:

Sample3.JPG


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type