Ilogic get parameter name from a selected sketch dimension

Ilogic get parameter name from a selected sketch dimension

acanx21
Enthusiast Enthusiast
1,225 Views
3 Replies
Message 1 of 4

Ilogic get parameter name from a selected sketch dimension

acanx21
Enthusiast
Enthusiast

I am trying to make a code that reads in the parameter name of a dimension that a user selects. 

 

The code I have right now is to create a spacing between two points with the on center dimension between each point being equidistant. The code I have that works (HoleSpacingType.txt) works with the user typing in the dimension between the two points. Then the code makes two parameters called pilot# and spacing# that can be used in a pattern feature to make the holes.

 

I want to change it though so a user can just select that dimension instead. I thought I had it working with (HoleSpacingSelect.txt) but the name of the parameter the code returns is not the same as the one selected by the user. (Only works on reference dimensions)

 

Is there a way of modifying the code below so that it returns a selected parameter name instead of a selected component name?

 

SyntaxEditor Code Snippet

Dim oOccurrence As ComponentOccurrence
Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

 

0 Likes
1,226 Views
3 Replies
Replies (3)
Message 2 of 4

JamieVJohnson2
Collaborator
Collaborator

I thought I'd give this a meddling try...

Selection set - you got this, but it contains more than just component occurrence, it should contain dimension objects, if the user selected a dimension (or more directly a dimension constraint object).  Try filtering for object by type, here is some pseudo code (per vb.Net standard).

for each ssObject in ….SelectionSet

If typeof ssobject is inventor.dimension then

   'here you begin to process on that dimension object.

   dim selDim as inventor.Dimension = ssObject

   'now what to do to get your parameter and names...

'exit for loop here if you only want to process one.

End if

next

 

I once wrote a program that looked through the sketch's list of DimensionContraints, in order to find some dimensions by name keywords (ATR and WIDE), it went like this:

        If osketch IsNot Nothing Then
            For Each dc As Inventor.DimensionConstraint In osketch.DimensionConstraints
                If dc.Parameter.Name.Contains("ATR") Then
                    If Not dc.Parameter.Name = "ATRD" Then dcATRs.Add(dc)
                ElseIf dc.Parameter.Name.Contains("WIDE") Then
                    If Not dc.Parameter.Name = "WIDED" Then dcWides.Add(dc)
                End If
            Next
        Else
            MsgBox("Can not find sketch named 'Clearance Profile'")
        End If

Notice from the DimensionConstraint object I have direct access to its linked Parameter, and then Name.  I think this is your missing link.

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

acanx21
Enthusiast
Enthusiast

I ended up getting to work using this:

 

SyntaxEditor Code Snippet

Dim oParameter As Object
Try
  oParameter = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

Dim oName As String
oName = oParameter.Parameter().Name

MessageBox.Show(oName, "Title")
0 Likes
Message 4 of 4

JamieVJohnson2
Collaborator
Collaborator

Yea, I bet if you did a 'get type' on that 'object' it would return DimensionConstraint.

 

Glad it works. 

 

Keep in mind, you are making the code 'assume' the user is selecting a DimensionConstraint by not qualifying it.  Potentially, the user could select a 3D face or something totally unexpected and when the code got down to object.Parameter().Name it would throw an error.  That's where the try block comes in, but also when making large numbers of loops, try blocks really slow down a program, so not a good practice when you could use an if/then statement in its place.

 

Examples here:

if ThisDoc.Document.SelectSet.Count > 0 Then  … that removes the first try block (or you could say = 1 to make sure user only selected one item)

If typeof ThisDoc.Document.SelectSet(1) is DimensionConstraint then … that prevents need for the second try block

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes