Ilogic Multi value list

Ilogic Multi value list

JorisSteurs1246
Advocate Advocate
9,585 Views
6 Replies
Message 1 of 7

Ilogic Multi value list

JorisSteurs1246
Advocate
Advocate

I try to get my part names in a MultiValue list,

 

I got stuck in my last line of teh code  where I try to get an array into the parameter.

 

Code as follows:

 

SyntaxEditor Code Snippet

    'check this file is an assembly
        Dim doc As Document = ThisApplication.ActiveDocument
        If doc.DocumentType = kPartDocumentObject Then
            MessageBox.Show("This rule can only be run in an assembly file!", "ERROR")
            Return
        End If
    
    
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
        oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
        oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
        oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 
        
    Dim NameList As New ArrayList()

    ' Iterate through the occurrences and collect the name. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
    NameList.add(oOcc.Name )
         
    Next 
    oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
'Setting an userParameter as text parameter
    Try
            otester = oMyParameter.Item("AwesomeParameter")
    Catch
   oInsulationType=oMyParameter.AddByValue("AwesomeParameter", "", kTextUnits) 

End Try
        
    MultiValue.List("AwesomeParameter") = NameList
0 Likes
Accepted solutions (1)
9,586 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi JorisSteurs1246 ,

 

Here is an example that should show one way to do this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'check this file is an assembly
Dim doc As Document = ThisApplication.ActiveDocument
If doc.DocumentType = kPartDocumentObject Then
    MessageBox.Show("This rule can only be run in an assembly file!", "ERROR")
    Return
End If    

' Get the active assembly. 
Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument 

' Get the assembly component definition. 
Dim oAsmDef As AssemblyComponentDefinition 
    oAsmDef = oAsmDoc.ComponentDefinition 

' Get all of the leaf occurrences of the assembly. 
Dim oLeafOccs As ComponentOccurrencesEnumerator 
    oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 
    
Dim NameList As New ArrayList()

' Iterate through the occurrences and collect the name. 
Dim oOcc As ComponentOccurrence 
For Each oOcc In oLeafOccs 
	NameList.add(oOcc.Name )     
Next 
	oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	'Setting an userParameter as text parameter
Try
	otester = oMyParameter.Item("AwesomeParameter")
Catch
	oInsulationType=oMyParameter.AddByValue("AwesomeParameter", "", UnitsTypeEnum.kTextUnits) 
	'make parameter a multivalue list parameter
	MultiValue.SetList("AwesomeParameter", "ListValue1", "ListValue2", "ListValue3")
End Try

'set list parameter to use array list    
MultiValue.List("AwesomeParameter") = NameList

'get user input
oSelection = InputListBox("Select one:", MultiValue.List("AwesomeParameter"), _
Parameter("AwesomeParameter"),  "iLogic", "List of Component Occurrences:")

'catch null selection
If oSelection = "" Then
	Return 'exit rule
Else
	'set parameter value 
	Parameter("AwesomeParameter") = oSelection
End If

'provide user feedback
MessageBox.Show("You selected: " & oSelection, "iLogic")

EESignature

Message 3 of 7

JorisSteurs1246
Advocate
Advocate

Hi Curtis,

 

Thank you so much, this works very well Smiley Happy  I could now also see where I made my mistake.

Thanks for the listbox extension you provided, this will come in handy as well. One problem I found with the listbox is that I can't drag the width of the box.

This would mean that in most of my designs the names will be only half readable. Is there, by any change, a way I can control the width of the box?

 

Thanks again 

 

Joris

0 Likes
Message 4 of 7

Curtis_Waguespack
Consultant
Consultant

Hi JorisSteurs1246,

 

Unfortunately, there is not a way to resize the input list box. But you could use an iLogic form and add the list parameter to it.

 

http://help.autodesk.com/view/INVNTOR/2015/ENU/?guid=GUID-6BE90A26-3CEB-481C-873C-4D85853375C6

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2016...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

EESignature

0 Likes
Message 5 of 7

JorisSteurs1246
Advocate
Advocate

Yes I'm working with forms a lot, but I was afraid that the multi value list parameter wouldn't update, so tested it but this works fine.

Thanks for pointing to that.

 

Joris

 

0 Likes
Message 6 of 7

ricksmithYGQR7
Participant
Participant

Hello,

I'm Trying to do something similar to this for drafting support. I need a script that will allow a user to select from a list of values and pull from an if statement the corresponding file to apply a title block from the selected file to a target drawing file.

I am working with an existing script that was working at one time when we had only 1 drawing template. 

We now want to maintain 4 templates for parts, sheet metal, assemblies and weldments. Each with styles and tolerances applied to the title block. So, I think I need to add a multi-value param and test it against a selected value.

But I haven't done this stuff in some time so any help would be appreciated.

 

'replace title block with 1 of 4 title blocks dependent on template type part, assembly, sheetmental or weldment

Sub Main()
'Check if the document is drawing
	If ThisApplication.ActiveDocument Is Nothing Or ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
	    MsgBox ("Please run this from a drawing.")
	    Exit Sub
	End If
    Dim oDrawingDoc As Inventor.DrawingDocument: oDrawingDoc = ThisApplication.ActiveDocument
    Dim SheetNumber As Integer
	
'        'Transfer Prompted Text
			iLogicVb.RunExternalRule("Xfer Prompted Text")
		
		'Add Custom iProps
			iLogicVb.RunExternalRule("Add Custom iProps")
			
    'Clear out the old Titleblocks
    For SheetNumber = 1 To oDrawingDoc.Sheets.Count
        oDrawingDoc.Sheets(SheetNumber).Activate
		If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
        oDrawingDoc.ActiveSheet.TitleBlock.Delete
	    End If
    Next SheetNumber
    
		DeleteTitleBlocks(oDrawingDoc) 'CALLING SUBROUTINE
		'create list to select from and call the title block selected to place in target drawing.
		'----------------------------------------------------------

		'----------------------------------------
		
		'MultiValue.SetList("TemplateType", ), As String, ParamArray args As Object()(Part, Assembly, Sheet_Metal, Weldment)))
		'test selection and apply file title block below.
		If "TemplateType" =Part Then
		ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\part.idw"
	Else If "TemplateType" = Assembly Then 
		ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\assembly.idw"
	Else If "TemplateType" = Sheet_Metal Then 
		ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\sheetmetal.idw"
	Else If "TemplateType" = Weldment Then 
		ThisDrawing.ResourceFileName = "C:\_Vault\CAD Stds\Inventor\Templates\weldment.idw"
	End If
	
        ThisDrawing.KeepExtraResources = False
            
				For Each oSheet In oDrawingDoc.Sheets
				oSheet.Activate

					ActiveSheet.TitleBlock = "MVPTLBLOCK"
					ActiveSheet.Border = "MVP BORDER"
				Next
				
		'Change Line Weight
			Dim oDrawDoc As DrawingDocument
			oDrawDoc = ThisApplication.ActiveDocument
			
			For Each oLayer In oDrawDoc.StylesManager.Layers
			oLayer.LineWeight = 0.007 / 0.393701
			Next
          
          
        iLogicVb.UpdateWhenDone = True
        ThisApplication.ActiveDocument.Sheets(1).Activate()
        ThisApplication.ActiveView.Fit
		        ThisApplication.ActiveView.Fit
		oModelBP = oDrawDoc.BrowserPanes.Item("DlHierarchy")
			For Each oNode In oModelBP.TopNode.BrowserNodes
				oNode.Expanded = False
			Next
 
End Sub

'Subroutine
Sub DeleteTitleBlocks(oActiveDoc As Inventor.DrawingDocument)
'Iterate through the collection deleting any titleblocks that are not referenced by the drawing object
Dim oTitle As TitleBlockDefinition
    For Each oTitle In oActiveDoc.TitleBlockDefinitions
        If oTitle.IsReferenced = False Then
        oTitle.Delete
        End If
    Next
End Sub

 

0 Likes
Message 7 of 7

ricksmithYGQR7
Participant
Participant

Looking at the accepted solutions provided some ideas, but I think that because they are targeted for part or assembly environment, I have to change how they are collecting information.

0 Likes