String doesn't seem recognize numbers

String doesn't seem recognize numbers

hldr
Contributor Contributor
633 Views
13 Replies
Message 1 of 14

String doesn't seem recognize numbers

hldr
Contributor
Contributor

Hi all, 

 

I'm quite new to using iLogic, and I'm looking for some help. I have an idw with an assy with multiple parts. All these parts have some custom properties, for example this one: 

"Bewerking" which is 10, 20, 30, 40, 50 or 60

 

The rule i'm working one contains this part that should create a variable (PartOperation) that depends on the value of "Bewerking". For example, if "Bewerking" = 10, then PartOperation should be "Snijden". The thing is, it seems to be having problems with values of "Bewerking" being numbers. Because this rule working fine as soon as i change the numbers to letters. Can someone tell me what i'm doing wrong here: 

				Dim CustomPropertySet As PropertySet
				CustomPropertySet = oPartDoc.PropertySets.Item("Inventor User Defined Properties")
				
			'determine operation and step 
					Dim PartOperation As String
					
					Dim BewPropterty As String
					BewPropterty = CustomPropertySet.Item("Bewerking").Value
					
					If BewProperty = "10" Then
					PartOperation = "Snijden"

 

 

0 Likes
Accepted solutions (1)
634 Views
13 Replies
Replies (13)
Message 2 of 14

JelteDeJong
Mentor
Mentor

You could try it like this:

Dim BewPropterty As String = iProperties.Value("Custom", "Bewerking")
Dim PartOperation As String = "Onbekend"
Select Case BewPropterty
    Case "10"
        PartOperation = "Snijden"
    Case "20"
        PartOperation = "Ponsen"
    Case Else
		PartOperation = "Onbekende code"
End Select
MsgBox(PartOperation)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 14

WCrihfield
Mentor
Mentor

If the values in your "Bewerking" iProperty are all numerical, then don't pre-define the variable that is to hold that value as a String.  And also don't check a numerical Value with quotes ("") around the value.  If the values in the "Bewerking" are "10","20","30","40" and so on, then they are Strings and what you have should work OK.  But if its values are 10, 20, 30, and so on, they will be returned as Integer type data, so pre-define the variable as an Integer, then don't use quotes around the value when checking it.   

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 14

hldr
Contributor
Contributor

@WCrihfield Thank you for your reply. I've rewritten the code, but it still doesn't seem to work. The iProperty "Bewerking" is all filled in with round numbers without quotes.  Am I missing something or did I misunderstood you?

 

					Dim PartOperation As String
					
					Dim BewPropterty As Integer
					
					BewPropterty = CustomPropertySet.Item("Bewerking").Value
					
					If BewProperty = 10 Then
					PartOperation = "Snijden"
				Else If BewProperty = 20 Then
					PartOperation = "Kanten"
				Else If BewProperty = 30 Then
					PartOperation = "Lassen"
				Else If BewProperty = 40 Then
					PartOperation = "Spuiten"
				Else If BewProperty = 50 Then
					PartOperation = "Samenbouwen"
				Else If BewProperty = 60 Then
					PartOperation = "Verpakken"
				Else PartOperation = "onbekend"

Results keep coming back with "onbekend" even though all "Bewerking"-fields are filled. 

0 Likes
Message 5 of 14

WCrihfield
Mentor
Mentor

The code you posted does not look complete.  Have you created the variable called 'CustomPropertySet' at some point before that code, and set its value to the custom property set?  Also, your 'If' statement doesn't have a 'End If' closing it out at the end.  Also, you can't put more code after 'Else', on the same line as it, when it is on a line of its own.  The code after 'Else' should be on a new line.

Maybe try it like this:

 

CustomPropertySet = ThisDoc.Document.PropertySets.Item(4)
Dim PartOperation As String
Dim BewPropterty As Integer
BewPropterty = CustomPropertySet.Item("Bewerking").Value

If BewProperty = 10 Then
	PartOperation = "Snijden"
ElseIf BewProperty = 20 Then
	PartOperation = "Kanten"
ElseIf BewProperty = 30 Then
	PartOperation = "Lassen"
ElseIf BewProperty = 40 Then
	PartOperation = "Spuiten"
ElseIf BewProperty = 50 Then
	PartOperation = "Samenbouwen"
ElseIf BewProperty = 60 Then
	PartOperation = "Verpakken"
Else
	PartOperation = "onbekend"
End If
MsgBox("PartOperation = " & PartOperation,,"")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 14

jjstr8
Collaborator
Collaborator

I'm not sure why it's behaving this way, but this will work with your original question.

...
Dim BewPropterty As [Property]
BewPropterty = CustomPropertySet("Bewerking")   'Item is implied
If BewProperty.Value.ToString() = "10" Then
...
Message 7 of 14

hldr
Contributor
Contributor

Hi all, thanks for your help. Unfortunately I still don't have a solution. The code was a bit too long that's why i didn't post it in whole. But since I'm still struggling i've tried to leave all irrelevant code out. Also I've replaced the numbers to letters, to check if that would help. Unfortunately that didn't work either :(. So I've attached all files that i'm testing with. The code is in the drawing file. 

0 Likes
Message 8 of 14

nedeljko.sovljanski
Advocate
Advocate

Hi,

I don't see code in drawing file.

0 Likes
Message 9 of 14

hldr
Contributor
Contributor

Hi, oh that's weird. Well, here it is in text: 

 

 

Imports System.IO.Path
Imports System.IO
Imports System.Collections

Sub Main()
oDoc = ThisApplication.ActiveDocument

If oDoc.SubType <> "{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
MessageBox.Show("Please run this rule in a Worklist","Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

ProjectNumber = "12345" 'oSymbol.GetResultText(oTextBox)
WorklistNumber = "w01" 'oSymbol.GetResultText(oTextBox)
'
'active drawing document
Dim oDrawDoc As DrawingDocument = oDoc

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument

'Check if there are more then one views used and if they have the same reference
For Each oSheet As Sheet In oDrawDoc.Sheets
For Each oView As DrawingView In oSheet.DrawingViews
oAsmDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Next
Next

'Define assembly component deffinition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

'look at the files referenced by the Assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'Define and Start Progress Bar
Dim PrgFull As Integer = 0
For Each oRefDoc In oRefDocs
PrgFull = PrgFull + 1
Next

'set assembly name
Dim oAsmName As String
If Right(oAsmDoc.DisplayName, 4) = ".ipt" Or Right(oAsmDoc.DisplayName, 4) = ".iam" Or Right(oAsmDoc.DisplayName, 4) = ".idw" Or Right(oAsmDoc.DisplayName, 4) = ".ipn" Then
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) - 4)
Else
oAsmName = oAsmDoc.DisplayName
End If

'Get part description and filter text
Dim DescriptAssy As String
Try
DescriptAssy = CleanString(oAsmDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value)
Catch
DescriptAssy = "0"
End Try

'Occurance counter
Dim OccCounter As Integer

Dim sFileName As String
sFileName = ProjectNumber & WorklistNumber

'Set the XML file location
Dim listname As String
listname = "C:\Users\hilder\Desktop\" & sFileName & ".xml"

'Create batch file
oWrite = System.IO.File.CreateText(listname)

'Dim array needed for piping pieces
Dim FileList As New List(Of String)
Dim MissingFiles As New List(Of String)

Dim i As Integer = 1

'Start For Loop
For Each oRefDoc In oRefDocs
' 'Sheet metal 'part 'assembly 'design element 'weldment
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Or oRefDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Or oRefDoc.SubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Or oRefDoc.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then

Dim oPartDoc As Document
oPartDoc = oRefDoc

'Check if part is purchased part

Dim CustomPropertySet As PropertySet
CustomPropertySet = oPartDoc.PropertySets.Item("Inventor User Defined Properties")

Dim ActieProperty As String
ActieProperty = CustomPropertySet.Item("Actie").Value

If ActieProperty = "INK" Then
Else

'determine operation and step
Dim PartOperation As String

Dim BewPropterty As String
BewPropterty = CustomPropertySet.Item("Bewerking").Value


If BewProperty = "A" Then
PartOperation = "Snijden"
Else If BewProperty = "B" Then
PartOperation = "Kanten"
Else If BewProperty= "C" Then
PartOperation = "Lassen"
Else If BewProperty = "D" Then
PartOperation = "Spuiten"
Else If BewProperty = "E" Then
PartOperation = "Samenbouwen"
Else If BewProperty = "F" Then
PartOperation = "Verpakken"
Else PartOperation = "Onbekend"
End If

'Display name .ipt check
Dim ExportName As String
If Right(oRefDoc.DisplayName, 4) = ".ipt" Or Right(oRefDoc.DisplayName, 4) = ".iam" Then
ExportName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4)
Else
ExportName = oRefDoc.DisplayName
End If

'Project number in name check
Dim ExportSubFolder As String

'Setting counter to 0 and the counting occurances
OccCounter = 0
For Each oOccurrence As ComponentOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)
If oOccurrence.Name.StartsWith(ExportName) Then
'Check for mirrors
If InStr(oOccurrence.Name, "_MIR") > 0 And Not InStr(ExportName, "_MIR") <> 0 Then
Else If InStr(oOccurrence.Name, "_Mir") > 0 And Not InStr(ExportName, "_Mir") <> 0 Then
Else
OccCounter = OccCounter + 1
End If
End If
Next

'If there are no occurencens of the refferenced part, the refference is derived and does not need to be exported
If Not OccCounter = 0 Then

'Get Part number
Dim Part_Number As String
Part_Number = oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

'Extract Porject or worklistnumber from file name to use as classification
Dim IconNumber As String
If InStr(Part_Number, ".") > 2 Then
IconNumber = Left(Part_Number, 5)
Else If InStr(Part_Number, ".") = 0 Then
IconNumber = "Manual"
Else
IconNumber = Mid(Part_Number, 3, 2)
End If

'Get part description and filter text
Dim Descript As String
Try
Descript = CleanString(oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value)
Catch
Descript = "0"
End Try

oWrite.WriteLine(Chr(34) & Part_Number & Chr(34))

oWrite.WriteLine("<Operation>" & PartOperation & "</Operation>")
oWrite.WriteLine("<Step>" & BewPropterty & "</Step>")
'
i = i + 1
End If
End If
'Else 'else for purchase addition
End If
' End If

Next


'Close Document
oWrite.Close()


End Sub

Sub NameReset(oOccs As ComponentOccurrences)
For Each oOcc As ComponentOccurrence In oOccs
Try
oOcc.Name = ""
NameReset(oOcc.SubOccurrences)
Catch
End Try
Next
End Sub

Function CleanString(PrtDesc As String) As String
Dim output As String
Dim c As Object 'since char & variant type does not exist in vba, we have to use object type.
For j = 1 To Len(PrtDesc)
c = Mid(PrtDesc, j, 1) 'Select the character at the j position
If (c >= "a" And c <= "z") Or (c >= "0" And c <= "9") Or (c >= "A" And c <= "Z") Then
output = output & c 'add the character to your output.
Else
output = output & " " 'add the replacement character (space) to your output
End If
Next
CleanString = output

End Function

 

0 Likes
Message 10 of 14

nedeljko.sovljanski
Advocate
Advocate

I am so sorry, I didn't notice you are talking about iLogic. Code is inside. I will check it.

0 Likes
Message 11 of 14

nedeljko.sovljanski
Advocate
Advocate

I have run your iLogic i have got this output

"CCtest - 60 - verpakken.1"
<Operation>Onbekend</Operation>
<Step>F</Step>
"CCtest - 40 - spuiten.1"
<Operation>Onbekend</Operation>
<Step>D</Step>
"CCtest - 30 - lassen.1"
<Operation>Onbekend</Operation>
<Step>C</Step>

but I see you changed 10 into A, 20 into B,...

Generally, If you want to use custom property as Number you need to select that property in

nedeljkosovljanski_0-1643021811662.png

If you choose text as type then 10 will be interpreted as "10".

0 Likes
Message 12 of 14

hldr
Contributor
Contributor

@nedeljko.sovljanski thank you for checking 

 

Yes, I have the same output. But the expected output would be:


"CCtest - 60 - verpakken.1"
<Operation>Verpakken</Operation>
<Step>F</Step>
"CCtest - 40 - spuiten.1"
<Operation>Spuiten</Operation>
<Step>D</Step>
"CCtest - 30 - lassen.1"
<Operation>Lassen</Operation>
<Step>C</Step>

 

So it would be great if someone can find out why the output isn't as expected. 

 

 

Also I see I forgot to erase an "else" here.

If ActieProperty = "INK" Then
else

But that doesn't matter in this case. It does change the output but the output here still doesn't have the correct operation text 

 

Replacing the data type of the iproperty to number and use numbers instead of letters, gave me the same result as using letters. 

 

 

0 Likes
Message 13 of 14

nedeljko.sovljanski
Advocate
Advocate
Accepted solution

🙂

Now you will see why I don't like (hate) iLogic editor.

 

Dim BewPropterty As String
BewPropterty = CustomPropertySet.Item("Bewerking").Value

 

You have misspell.

 

Message 14 of 14

hldr
Contributor
Contributor
OMG. i hate it too now. haha. Thank you very much for helping me out.