special characters

special characters

GosponZ
Collaborator Collaborator
385 Views
4 Replies
Message 1 of 5

special characters

GosponZ
Collaborator
Collaborator

I'm using this rule to fill browser in idw and is working good, but now in another company we using special characters in material description. Would be possible to remove special characters. 


oDoc = ThisDoc.Document

oSheets = oDoc.Sheets

For Each oSheet In oSheets

oSheet.activate

oView = oSheet.DrawingViews.Item(1)

modelName = oView.ReferencedDocumentDescriptor.ReferencedDocument

If modelName.DocumentType = DocumentTypeEnum.kPartDocumentObject 'Only set property based name for part views

oProp = modelName.PropertySets.Item("Design Tracking Properties")
ocProp = modelName.PropertySets.Item("Inventor User Defined Properties") 'Custom property set

ActiveSheet.Sheet.Name = oProp.Item("Material").Value & " " & " " & oProp.Item("Part Number").Value & " " & oProp.Item("Description").Value

End If
Next

oSheets(1).activate

 

 

0 Likes
Accepted solutions (1)
386 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Here is a function to remove special characters, function source from stack overflow

Sub Main
	
	Dim Name As String = "Hello?!#"
	
	'Replacement string for name having ilegal Characters.
	Dim replace_with As String = ""

	'Function to remove ilegal characters from Style Name before saving file
	Dim NewName As String = clean_filename(Name, replace_with)
	MessageBox.Show(NewName, "Title")

End Sub	
Function clean_filename(Name As String, replace_with As String)
    Dim inv_chars As String
    Dim cpos As Long

    invchars = "'!""#¤%&/()=?`^*>;:@£${[]}|~\,.'¨´+-"
    For cpos = 1 To Len(invchars)
        Name = Replace(Name, Mid(invchars, cpos, 1), replace_with)
    Next
    clean_filename = Name
End Function
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 5

GosponZ
Collaborator
Collaborator
I'm not sure this one will work for me. I have that rule.
The thing is when i run rule i post above it supposed to write in browser tree material, but since material has in description / and " it will not run. I need description in browser to show material w/o quotes and back slash. If that can happen would be great.
Thank you for response
0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor
Accepted solution

See if this will work. If it doesn't can you post the errors your seeing?

Sub Main
	oDoc = ThisDoc.Document
	
	oSheets = oDoc.Sheets

	For Each oSheet In oSheets

		oSheet.activate

		oView = oSheet.DrawingViews.Item(1)

		modelName = oView.ReferencedDocumentDescriptor.ReferencedDocument

		If modelName.DocumentType = DocumentTypeEnum.kPartDocumentObject 'Only set property based name for part views

		oProp = modelName.PropertySets.Item("Design Tracking Properties")
		ocProp = modelName.PropertySets.Item("Inventor User Defined Properties") 'Custom property set
		
		Dim OldMaterialName As String = oProp.Item("Material").Value
		
		'Replacement string for name having ilegal Characters.
		Dim replace_with As String = ""

		'Function to remove ilegal characters from Style Name before saving file.
		Dim MaterialName As String = clean_filename(OldMaterialName, replace_with)

		ActiveSheet.Sheet.Name = MaterialName & " " & " " & oProp.Item("Part Number").Value & " " & oProp.Item("Description").Value

		End If
	Next

	oSheets(1).activate
	
End Sub	
Function clean_filename(Name As String, replace_with As String)
    Dim inv_chars As String
    Dim cpos As Long

    invchars = "'!""#¤%&/()=?`^*>;:@£${[]}|~\,.'¨´+-"
    For cpos = 1 To Len(invchars)
        Name = Replace(Name, Mid(invchars, cpos, 1), replace_with)
    Next
    clean_filename = Name
End Function

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 5

GosponZ
Collaborator
Collaborator
No error, this is what i need. Thank you so much
0 Likes