Need help on how to ignore running ilogic code on part number field for files that start with certain characters

Need help on how to ignore running ilogic code on part number field for files that start with certain characters

kwilson_design
Collaborator Collaborator
376 Views
4 Replies
Message 1 of 5

Need help on how to ignore running ilogic code on part number field for files that start with certain characters

kwilson_design
Collaborator
Collaborator

Hey everyone. How can I tell my ilogic code to ignore running this snippet if my part number value begins with "FS" or "U"? Basically we have multiple naming schemes for old and new CAD files. Our old legacy part number schemes used FS or U at the beginning of the part number (FS123-456789 or U123-456789 for example). For those legacy files, I need them to ignore using the global rule snippet shown below....

 

iProperties.Value("Custom", "-G Finished part number") = iProperties.Value("Project", "Part Number") & "-G"
iProperties.Value("Custom", "-N Finished part number") = iProperties.Value("Project", "Part Number") & "-N"

 

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
0 Likes
Accepted solutions (1)
377 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

If we were sticking with using the iProperties.Value() snippet, then you could simply format the rule similar to this:

Dim sPN As String = iProperties.Value("Project", "Part Number")
If sPN.StartsWith("FS") = False And sPN.StartsWith("U") = False Then
	iProperties.Value("Custom", "-G Finished part number") = sPN & "-G"
	iProperties.Value("Custom", "-N Finished part number") = sPN & "-N"
End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

And here is an API equivalent of that, which does not use that iLogic snippet, but uses the 'ThisDoc.Document' reference to identify the document for it to target.

Dim oDoc As Document = ThisDoc.Document
Dim sPN As String = oDoc.PropertySets.Item(3).Item("Part Number").Value
Dim oCProps As Inventor.PropertySet = oDoc.PropertySets.Item(4)
If sPN.StartsWith("FS") = False And sPN.StartsWith("U") = False Then
	Dim oCProp1 As Inventor.Property = Nothing
	Try
		oCProp1 = oCProps.Item("-G Finished part number")
	Catch
		oCProp1 = oCProps.Add(sPN & "-G", "-G Finished part number")
	End Try
	If oCProp1 IsNot Nothing AndAlso oCProp1.Value <> sPN & "-G" Then
		Try : oCProp1.Value = sPN & "-G" : Catch : End Try
	End If
	
	Dim oCProp2 As Inventor.Property = Nothing
	Try
		oCProp2 = oCProps.Item("-N Finished part number")
	Catch
		oCProp2 = oCProps.Add(sPN & "-N", "-N Finished part number")
	End Try
	If oCProp2 IsNot Nothing AndAlso oCProp2.Value <> sPN & "-N" Then
		Try : oCProp2.Value = sPN & "-N" : Catch : End Try
	End If
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

kwilson_design
Collaborator
Collaborator

Thanks for the help @WCrihfield ! That works. Now what if I wanted it to replace the custom -G and -N iproperty fields with the part number iproperty if it contains FS or U? Tried editing it for a true or false but ran into an error "Error on Line 7 : Local variable 'sPN' is already declared in the current block.". Basically if there is an FS or U part number iproperty, then I need it to also copy that value into the -G and -N custom iproperty while also ignoring to add the -G or -N suffix to the end like your snippet did.

 

Dim sPN As String = iProperties.Value("Project", "Part Number")
If sPN.StartsWith("FS") = True And sPN.StartsWith("U") = True Then
	iProperties.Value("Custom", "-G Finished part number") = sPN
	iProperties.Value("Custom", "-N Finished part number") = sPN
End If

Dim sPN As String = iProperties.Value("Project", "Part Number")
If sPN.StartsWith("FS") = False And sPN.StartsWith("U") = False Then
	iProperties.Value("Custom", "-G Finished part number") = sPN & "-G"
	iProperties.Value("Custom", "-N Finished part number") = sPN & "-N"
End If
 

 

Regards,
Kenny
If this post solved your issue please mark "Accept as Solution". It helps everyone...really!
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

I think you can just change Line 7 like this, to prevent 'declaring' that variable again.  This line is simply setting a new value to the already existing variable, without re-creating it.

 

sPN = iProperties.Value("Project", "Part Number")

Edit:  And also in line 2, change 'And' to 'Or'.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes