iLogic skip if iProperty doesn't exist

iLogic skip if iProperty doesn't exist

Cosmin_V
Advocate Advocate
740 Views
3 Replies
Message 1 of 4

iLogic skip if iProperty doesn't exist

Cosmin_V
Advocate
Advocate

Hello everyone,

 

I'm trying to make an external rule that doesn't allow saving a part until the material and treatment have been set.

The problem is that I want to avoid this happening in some cases...

If it has "Bosch Profile" in the description

If iProperties.Value("Custom", "IsPurchased") = True

 

But the problem is that some older parts do not have "iProperties.Value("Custom", "IsPurchased") "
and I would like this parts to be excluded as well, how can I do that?

 

That is what I have done so far.

Dim oDoc As Document = ThisDoc.Document
oNr = iProperties.Value("Project", "Part Number")

If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	If Left(iProperties.Value("Project", "Description"), 13) = "Bosch Profile" 
	
		Else If iProperties.Value("Custom", "IsPurchased") = False 
		again :
'[''''''''''''''''''''''''''''''''''''''MATERIAL'''''''''''''''''''''''''''''	
			If iProperties.Material = "" Or iProperties.Material = "-"
			Dim oValueList1 As New ArrayList
			oValueList1.Add("Aluminium - EN AW-2007/2011")
			oValueList1.Add("Aluminium - EN AW-5005 - Natural Anodised")
			oValueList1.Add("Aluminium - EN AW-6082")
			oValueList1.Add("Brass")
			oValueList1.Add("Bronze")
			oValueList1.Add("Copper")
			oValueList1.Add("Generic")
			oValueList1.Add("POM-C - Black (Ertacetal)")
			oValueList1.Add("POM-C - Nature (Ertacetal)")
			oValueList1.Add("Stainless Steel - AISI 304")
			oValueList1.Add("Stainless Steel - AISI 316 (EN 1.4404)")
			Dim oValue1 As String = InputListBox(oNr & " Material it is MANDATORY", oValueList1)
				If String.IsNullOrEmpty(oValue1) Then
					GoTo again
				End If
			iProperties.Material= oValue1
			End If
']		
'[''''''''''''''''''''''''''ADD iProperties if does not exist''''''''''''''''		
			Dim Doc As Document= ThisApplication.ActiveDocument
			Dim oTreatment As PropertySet = Doc.PropertySets.Item("Inventor User Defined Properties")	
			' Attempt to get an existing custom property named "Treatment".
			On Error Resume Next
			Dim Part_Treatment As PropertySet = oTreatment.Item("Treatment")
				If Err.Number <> 0 Then
				' Property does not exist -> Add the property.
				Dim textValue As String
				textValue = "Treatment"
				Call oTreatment.Add(textValue, "")
				End If	
']	
'[''''''''''''''''''''''''''''''''''''TREATMENT''''''''''''''''''''''''''''''	
			If iProperties.Value("Custom", "Treatment") = "" Or iProperties.Value("Custom", "Treatment") = "-" 
			Dim oValueList1 As New ArrayList
			'oValueList1.Add("-")
			oValueList1.Add("None")
			oValueList1.Add("Anodizing - Hard")
			oValueList1.Add("Anodizing - Precision")
			oValueList1.Add("Assembled before painting")
			oValueList1.Add("Browning")
			oValueList1.Add("Welding Part")
			Dim oValue1 As String = InputListBox(oNr & " Treatment it is MANDATORY", oValueList1)
				If String.IsNullOrEmpty(oValue1) Then
					GoTo again
				End If
			iProperties.Value("Custom", "Treatment")= oValue1
			End If
	End If
End If

 

0 Likes
Accepted solutions (1)
741 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @Cosmin_V.  I'm not sure if this is exactly what you had in mind, but when an iProperty may not exist, but you need to check its value, you have two main options for checking that.  The traditional route would be to loop through the custom iProperties, checking for one with that name, and if found record its value to a variable that was created before the loop.  The second option would be to enclose the code that is trying to access that iProperty within a Try...Catch block of code, which will allow you to 'handle' the error without it crashing/stopping the code, and possibly give yourself some feedback about the issue.  Below is an example using the Try...Catch block route, just for the initial testing of those iProperties.

Dim oDesc As String = iProperties.Value("Project", "Description")
Dim oIsPurchased As Boolean = False 'False by default anyways
Try
	oIsPurchased = iProperties.Value("Custom", "IsPurchased")
Catch
	Logger.Debug("Custom iProperty 'IsPurchased' was not found.")
End Try
If oDesc.Contains("Bosch Profile") Or oIsPurchased = True Then Return

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Cosmin_V
Advocate
Advocate

Thanks, @WCrihfield 

It still does not work

 

What I want is to assign material and treatment if it is a part, and if, iProperties.Value("Custom", "IsPurchased") = False.


If, iProperties.Value("Custom", "IsPurchased") does not exist, or iProperties.Value("Custom", "IsPurchased") exist but is = True or If Left(iProperties.Value("Project", "Description"), 13 ) = "Bosch Profile". Then I want the rest of the code to be ignored

 

Thanks a lot

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor
Accepted solution

@Cosmin_V.  OK.  I originally did not understand correctly then.

Try this bit of code at the start then:

Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Return
If Left(iProperties.Value("Project", "Description"), 13) = "Bosch Profile" Then Return
Try
	If iProperties.Value("Custom", "IsPurchased") = True Then Return
Catch
	Return 'failed to find that iProperty
End Try
oNr = iProperties.Value("Project", "Part Number")

...then the rest of your code...minus the last two End If's.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)