Remove characters from an IProperty to fill in another IProperty

Remove characters from an IProperty to fill in another IProperty

gconley
Advocate Advocate
1,278 Views
8 Replies
Message 1 of 9

Remove characters from an IProperty to fill in another IProperty

gconley
Advocate
Advocate

We have an IProperty that is used in our system and I would like to figure out how to strip the IProperty to get the information in the middle of the IProperty.

 

Ex.

Custom, Plant Listing = 100 *JACKSON, MS ^RENDERING

Custom, DESC2 = JACKSON, MS

 

Is it possible to write a code that will populate our Custom IProperty DESC2 from the Plant Listing?  

I have tried, but not able to figure out how to skip the first 5 and the last 11 characters.

Jackson, MS is one of our location and this property could be different lengths.

^Rendering is a process area and could be different lengths as well.

Accepted solutions (1)
1,279 Views
8 Replies
Replies (8)
Message 2 of 9

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Are the chars "*" and "^" always there? If so, you could use Split and Trim function.

iProperties.Value("Custom", "DESC2")=Split(Split(iProperties.Value("Custom", "Plant Listing"),"*",2)(1),"^",2)(0).Trim

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @gconley.  There are many tools for manipulating String type data.  But we might have to know more details about all the ways you expect the value of the first iProperty might possibly change, in order to write code that will do a task like this reliably, without throwing errors every once in a while.  If you know that those two special characters "*" and "^" will always be present within the first iProperty's value, that will certainly help make this task easier to automate.  If you can ensure that the "*" character will always precede the text you want to extract, and you an ensure that the "^" character will always be right after the text you want to extract, then we can use some code similar to what @Ralf_Krieg provided above.  However, if you are not familiar with using the Split function, that code might be a bit confusing to read or edit later, if you need to make any changes or variations.  I would suggest spreading some of that code out a bit, for clarity, and maybe even include some comments to yourself, so you know what is going on later.

Here is another iLogic rule example that will attempt to 'copy' (not remove or strip) the value of the first iProperty, and set that filtered text as the value of the second iProperty, using that same Split tool.  But this code is spread out a bit more, with lines of comments included to help you follow and understand what is going on.

'create a String type variable to hold the value of the first iProperty
Dim oPlantListing As String = ""
oPlantListing = iProperties.Value("Custom", "Plant Listing")
'check to make sure it now contains a value other than ""
If oPlantListing = "" Then
	MsgBox("The 'Plant Listing' iProperty was empty.", vbExclamation, "Empty iProperty")
	Exit Sub
End If
'create a variable to hold the filtered text we are after
Dim oDesc2 As String = ""
'make sure the value we retrieved above contains the "*" character
If oPlantListing.Contains("*") Then
	'split the String into multiple Strings, using "*" as the split tool
	'the immediate result is an Array of String (array elements start at zero, not 1)
	'then get the second item in the resulting Array of String (Item 1 vs Item zero)
	oDesc2 = oPlantListing.Split("*")(1)
Else
	MsgBox("The source iProperty's Value did not contain the '*' character.", vbExclamation, "Character Missing")
	Exit Sub
End If
'oDesc2 should now contain the second half of the original String
'now make sure the remaining text contains the "^" character
If oDesc2.Contains("^") Then
	'use the Split tool again, but this time get the first part (Item zero)
	oDesc2 = oDesc2.Split("^")(0)
Else
	MsgBox("The source iProperty's Value did not contain the '^' character.", vbExclamation, "Character Missing")
	Exit Sub
End If
'just a message showing you the filtered text that will be written to the other iProperty
MsgBox("oDesc2 = " & oDesc2, vbInformation, "")
'write the filtered text to the other iProperty
iProperties.Value("Custom", "DESC2") = oDesc2

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

gconley
Advocate
Advocate

@Ralf_Krieg I appreciate your help, this worked perfectly and was easy to understand.

0 Likes
Message 5 of 9

gconley
Advocate
Advocate

@WCrihfield Thanks for your input.  However I am new to coding and it isn't my main job.  Which is why I probably had a hard time understanding anything you wrote.  I need to dive further into coding to understand what you did.

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

No problem @gconley.  The whole point of my post was to break everything down into smaller, individual steps and help clarify each step, and help explain what the Split function does, how it works, and how to use it, just in case you were not already familiar with it.  There are two main versions of the Split function (String.Split, and Strings.Split) in vb.net, and each main version has multiple possible optional ways you can use them, so it can be a bit confusing at first.   The two links above point you to the source Microsoft web pages where they are defined and documented, just in case you wanted to dig into them any further later.  I likely got carried away and too wordy in my post.  Sometimes I give TMI (too much information), and other times not enough. 😉  Good luck in your future iLogic pursuits.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

kwilson_design
Collaborator
Collaborator

Hello everyone and @WCrihfield . I have a similar need for this but running into snags getting it to work. I'm trying to copy the Part Number iProperty to a custom iProperty named "NUMBER" but I only want to retain the first 10 characters from the Part Number iProperty if it starts with U. I need the same ability if the part number starts with PS but I only want to retain the first 13 characters in that case.

 

See below for what I’m trying to achieve: 

Part Number iProperty = U100-00006R-N

If Part Number iProperty starts with U, then only retain the first 10 characters, and populate to Custom iProperty named “NUMBER”.

NUMBER custom iProperty should look like = U100-00006

 

Part Number iProperty = PS501-BAA0001L-G

If Part Number iProperty starts with PS, then only retain the first 13 characters, and populate to Custom iProperty named “NUMBER”.

NUMBER custom iProperty should look like = PS501-BAA0001

 

I was trying to go this route shown below but rather than remove characters from the end of the part number, I’d rather define what to retain from the beginning of the part number just in case someone accidentally has too many characters or not enough.

 

Dim sPN1 As String = iProperties.Value("Project", "Part Number")

If sPN1.StartsWith("FS") = True And sPN1.StartsWith("U") = True Then

            iProperties.Value("Custom", "NUMBER") = Left(sPN1, Len(sPN1)-1)

            iProperties.Value("Custom", "NUMBER") = Left(sPN1, Len(sPN1)-1)

 

End If

 

Any help would be greatly appreciated!!

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

WCrihfield
Mentor
Mentor

Something like this maybe?

Dim sPN As String = iProperties.Value("Project", "Part Number")
Dim sNumber As String = ""
If sPN.StartsWith("U") Then
	sNumber = Left(sPN, 10)
ElseIf sPN.StartsWith("PS") Then
	sNumber = Left(sPN, 13)
Else
	'other case, or do nothing
End If
iProperties.Value("Custom", "NUMBER") = sNumber

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)

Message 9 of 9

kwilson_design
Collaborator
Collaborator

@WCrihfield brother that's too easy and perfect for what I need. I often find myself making it harder than it needs to be lol. Thanks again, you're a great asset to this forum!!

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