Get component name from selected part?

Get component name from selected part?

NateLFO
Contributor Contributor
1,416 Views
5 Replies
Message 1 of 6

Get component name from selected part?

NateLFO
Contributor
Contributor

Hello.  I'm just getting into iLogic and I figured I'd try making a rule for setting the length for DIN rails.  What I would like to do is make it so I can select a rail and have it prompt me to specify the length.  I have the part for specifying the length working just fine.

   

iLogicVb.UpdateWhenDone = True
Parameter("DIN Rail:1", "Rail_Length") = InputBox("Set DIN Rail Length")

 

What I am having trouble is finding out how to return the component/document name of the selected item so that I can use a variable in place of "DIN Rail:1".  I'm familiar with VBA, I've been using it in Excel and Visio for years, it's just a matter of finding the appropriate properties and methods to accomplish certain things.

 

Dim oDIN As ICadComponent '??????
oDIN = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select a DIN Rail")

 

I know how to pick the part, but I'm not sure what type of object to set the oDIN variable as to be able to return a name.  I've tried various things and not had much luck.  I even opened the Inventor library in Excel and tried using the object browser to see if I could trace a component name through parents and I wasn't having much luck there either. 

 

Any help you can provide would be greatly appreciated.

0 Likes
Accepted solutions (1)
1,417 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

Do not use this iLogic shortcuts, but full API functions like this

Dim parameterName = "Length"
Dim pick As Object
Do
    pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select occurrence")

    Dim occ As ComponentOccurrence = pick
    Try
        Dim lengthParam As Inventor.Parameter = occ.Definition.Parameters(parameterName)
        Try
            lengthParam.Expression = InputBox("Set " & parameterName, "Set parameter", lengthParam.Expression)
            'occ.Definition.Document.Update
            ThisDoc.Document.Update
        Catch
            MsgBox("Invalid value")
        End Try
    Catch
        MsgBox("Parameter " & parameterName &" not found")
    End Try
Loop While Not pick Is Nothing
Message 3 of 6

NateLFO
Contributor
Contributor

Never mind, I was able to get it to work.  I'm going to leave this up instead of deleting it in case it helps someone else looking for how to get the name of a selected part occurrence. 

 

Now I just need to get it to add a new length parameter unique to each instance, because right now, when I change the value of one, they are all affected.

 

iLogicVb.UpdateWhenDone = True

Dim oPart As ComponentOccurrence

oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component")
	If oPart Is Nothing Then
		Exit Sub
	Else
		Dim oDoc As Document
		oDoc = oPart.Definition.Document
	End If

Parameter(oPart.Name, "Rail_Length") = InputBox("Set DIN Rail Length")

 

0 Likes
Message 4 of 6

NateLFO
Contributor
Contributor

Thanks.  I might give that a try as well.

0 Likes
Message 5 of 6

Michael.Navara
Advisor
Advisor

Create new parameter for each instance is VERY BAD solution. Use some another solution. For example occurrence properties (Inventor 2022)

Message 6 of 6

NateLFO
Contributor
Contributor

Thanks for your reply.  It makes sense not to generate a whole bunch of unique parameters for the same thing on different occurrences of the same base component.  For the time being, I’m using Place iLogic Component so that any occurrences that have a different length end up as a copy of the original part with the new dimensions.  I’m still figuring this out and I’ll have to look into using occurrence properties as a means of driving the length.  Thanks again.

0 Likes