Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic List to check Acceptable Entries

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
GICain
507 Views, 10 Replies

iLogic List to check Acceptable Entries

Greetings everyone,

 

Back again for a little help. Obligatory I code like a toddler preface. 

 

What I'm trying to do is put guard rails in place for a manual BOM entry to designate part finish.

 

Long story short, we've worked on a roundabout way of creating a rule that creates Material_Finish as a multi-value parameter, that then gets transcribed to "Authority" because you can only use Standard iProperties in view label creations.

 

The rules created, are causing issues, so I think it's best to just cut out the middle person and directly populate the Authority property we've chosen to designate finish, with some guards in place.

 

Problem is, the code I attempted works to check a list... but I would like it to just check the list and report back if the specified finish isn't in the list. Currently it does that, but it throws 3 message boxes at you. 

 

I'd simply like to check a list and report back IF the finish ISN'T in the list at all. Also it would be nice if it would check all occurrences in an assembly, currently I think this would only check the active document

 

Code attached below, and many thanks in advance,

Gabe

 

testString = iProperties.Value("Design tracking Properties", "Authority")

Dim List As New ArrayList
List.add("GALV")
List.add("ARTIST")
List.add("RAW")
List.add("POWDER COAT")

Dim Ostring As Object
i = 0
For Each Ostring In List
	If testString.Contains(List.Item(i)) Then
	 'MessageBox.Show(List.Item(i) & ": was found!", "iLogic")
 	Else
			MessageBox.Show("Invalid Finish.", "Finish")
		End If
		i= i+1
		Next

 

Gabe Cain
Structural Designer/Engineering Checker
Labels (3)
10 REPLIES 10
Message 2 of 11
A.Acheson
in reply to: GICain

Here is a rule that should fit the bill for you. Instead of looping through occurrences the rule searches the reference documents of the assembly and checks the iProperty Authority against the supplied list. Regarding the custom iProperty in the view label can you share why that wouldn't work for you? That would be the logical place to put an iProperty like this. 

Sub Main

	FinishList.Add("GALV")
	FinishList.Add("ARTIST")
	FinishList.Add("RAW")
	FinishList.Add("POWDER COAT")

	Dim oAsm As AssemblyDocument = ThisDoc.Document

	For Each oDoc As Document In oAsm.AllReferencedDocuments 'Traverse all referenced documents 
		
		Dim DesignProp As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
		Dim oAut As [Property] = DesignProp.Item("Authority")
		
		Dim Check As Boolean = FinishCheck(oAut.Value)'Function to check iprop against Finish List

		If Check = False Then
	    	If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
				Dim oPartDef As PartComponentDefinition = oDoc.ComponentDefinition
				If Not oPartDef.IsContentMember Then 'Remove content center parts
					
					Dim FileName As String = Left(oDoc.DisplayName, Len(oDoc.DisplayName) -3) 
					Dim FinName As String
					If oAut.Value = Nothing Then
						FinName = "None"
					Else
						FinName = oAut.Value
					End If
					ErrorList.Add( FileName & " With finish of   -  " & FinName)
				End If
			End If
		End If
	Next 

	d0 = InputListBox("Prompt", ErrorList, d0, Title := "Finish Check", ListName := "Unlisted Finish")
End Sub

Dim ErrorList As New ArrayList
Dim FinishList As New ArrayList

Function FinishCheck(testString As String ) As Boolean
	For Each sFinish In FinishList
		If Not FinishList.Contains(testString) Then
			Return False
		Else
			Return True
		End If	
	Next
End Function

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 11
GICain
in reply to: A.Acheson

Thank you @A.Acheson,

 

Code works great, I am getting an occasional error though when using it. Screenshots attached. 

 

This rule will go on an event trigger to run on save. Would it be possible to only show the dialogue box if there is an error?  

 

Regarding the custom iProperty in the view label can you share why that wouldn't work for you? That would be the logical place to put an iProperty like this. 

Screenshot attached. In the standards where the style for the view labels are created, you can only use Standard iProperties. Originally we were creating a parameter on the part, then transcribing it to another custom iProperty on the BOM. Easiest solution for us was to use a Standard iProperty (Authority) that we didn't foresee using for anything else in the future. 

Gabe Cain
Structural Designer/Engineering Checker
Message 4 of 11
A.Acheson
in reply to: GICain

Line 40 looks to be the function and I'm not sure why that error is coming up. Maybe declare sFinish to always be a string before the loop begins.

Dim sFinish As String

 To only bring up the inputlist box of error parts you can surround the input list box with and if statement and use the count of error array >0 as the condition. 

 

Ok I see where your setting the view label. You can set all of that afterwards but it is extra code instead of setting it in one place.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 11
GICain
in reply to: A.Acheson

@A.Acheson 

This seems to have worked, thanks again for all the help.

Dim sFinish As String

 I'm trying to do like you said with the surrounding If statement and having no success. I tried googling around to better understand and throwing things at the wall to see if something sticks, and no luck.

 

I'll have to tinker with this some more later when I have some time to try to get the If statement to work.

 

Thanks again for the help,

Gabe

Gabe Cain
Structural Designer/Engineering Checker
Message 6 of 11
A.Acheson
in reply to: GICain

Ah yes it may not be a straight forward path if you haven't used count before. Count is a function of the arraylist so to find it in the drop down you would have to temporarily declare the array list in the block and then it appears in the drop down . Or just type it straight in. Don't forget to remove the temporary declaration as it will contradict the global one used to work with the function.

 

AAcheson_0-1657206748894.png

AAcheson_2-1657206901898.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 11
GICain
in reply to: A.Acheson

@A.Acheson,

 

Apologies, I seem to have missed your response.

 

I seem to be having some trouble still creating your steps.

 

I added this (line 1 & 2 of snippet)

	Dim ErrorList As ArrayList
	ErrorList.
	d0 = InputListBox("Prompt", ErrorList, d0, Title := "Finish Check", ListName := "Unlisted Finish")

 Renamed the ArrayList to ArrayListGlobal to trick the other I assume? 

Dim ErrorList As New ArrayListGlobal
Dim FinishList As New ArrayList

 

Added in the .count, got a dropdown, tabbed it in.

	Dim ErrorList As ArrayList
	ErrorList.Count
	d0 = InputListBox("Prompt", ErrorList, d0, Title := "Finish Check", ListName := "Unlisted Finish")

Removed the global from the other lines

Dim ErrorList As New ArrayList
Dim FinishList As New ArrayList

 

Ran the rule and get the errors shown in screenshots. Final code screenshot also added.

 

Thanks again for your help. 

 

Gabe Cain
Structural Designer/Engineering Checker
Message 8 of 11
A.Acheson
in reply to: GICain

So the two error message are as follows.

1. The main rule has two declarations of the same object. Remove the one in the main rule as the global version is what is required to communicate between the main sub and the function. An alternate way to do this is to declare the object in the main sub and then pass it in as an argument just like teststring is set up. 

2. You get a count of the arraylist but do nothing  with it. Place this in an if statement to bypass the listbox if count is zero. 

 

Optional:

As an additional observation I originally used an arraylist but I have since learned that this is an old method of getting a list and can have performance issues due to the way it operates. Here is the official documentation on the arraylist. It doesn't care the type of object added to it be it string or double etc.

 

So you can replace "New Arraylist"

With "New List(Of String)"

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 9 of 11
GICain
in reply to: A.Acheson

@A.Acheson 

 

I think I got it to work. For some reason I feel like I tried this and was unsuccessful. 

	Next 

		If ErrorList.Count>0 Then
			d0 = InputListBox("Prompt", ErrorList, d0, Title := "Finish Check", ListName := "Unlisted Finish")
		End If

	End Sub

 However, I have a new problem. I need to check the AUTHORITY of the assemblies as well as the parts. 

 

Looks like I would need to do something here to change the kPart to... kAsssembly? Sorry I'm not very good at this stuff.

	    	If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
				Dim oPartDef As PartComponentDefinition = oDoc.ComponentDefinition

 

Gabe Cain
Structural Designer/Engineering Checker
Message 10 of 11
A.Acheson
in reply to: GICain

Just change the DocumentTypeEnum to check for AssemblyDocumentObject. You don't need the definition reference and the check for content center part file as you are only dealing with an assembly. So remove that piece but everything else is a copy of the part file check. 

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	'Do something with the part document
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	'Do something with the assembly document
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 11 of 11
GICain
in reply to: A.Acheson

@A.Acheson,

 

With your help, I got it to work! 

 

Thanks for all the help!

Gabe Cain
Structural Designer/Engineering Checker

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report