removing special characters

removing special characters

GosponZ
Collaborator Collaborator
385 Views
4 Replies
Message 1 of 5

removing special characters

GosponZ
Collaborator
Collaborator

This rule is making browser tree with some properties. It is working perfect if there is no special characters in material or description. My question is how to remove special characters like (, :& ) only from browser tree. 

oDoc = ThisDoc.Document

oSheets = oDoc.Sheets

    For Each oSheet In oSheets

        oSheet.activate

        oView = oSheet.DrawingViews.Item(1)

        modelName = oView.ReferencedDocumentDescriptor.ReferencedDocument

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

        ActiveSheet.Sheet.Name = oProp.Item("Part Number").Value & " " & oProp.Item("Description").Value  '_
		'& " " & "QTY" & " " & ocProp.Item("TTL").Value


    Next

oSheets(1).activate

iLogicVb.UpdateWhenDone = True

 

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

tyler.warner
Advocate
Advocate
Accepted solution

@GosponZ you can try something like this. It is a slight modification to your code. It will not error when it finds a page without a view & it will just remove all characters that are not letters or digits except for spaces.

 

 

 

Dim oDoc As Document = ThisDoc.Document
Dim oSheets As Sheets = oDoc.Sheets
For Each oSheet In oSheets
    oSheet.Activate
	Dim oView As DrawingView
	Try
    	oView = oSheet.DrawingViews.Item(1)
	Catch
		'MessageBox.Show("There is no drawing view on " & oSheet.Name)
		Continue For
	End Try
    Dim modelName As Object = oView.ReferencedDocumentDescriptor.ReferencedDocument
    Dim oProp As PropertySet = modelName.PropertySets.Item("Design Tracking Properties")
	'ocProp = modelName.PropertySets.Item("Inventor User Defined Properties") 'Custom property set
	Try
		Dim oSheetName As String = oProp.Item("Part Number").Value & " " & oProp.Item("Description").Value  '_
                '& " " & "QTY" & " " & ocProp.Item("TTL").Value
		Dim oDisplayName As String = ""
		
		For Each letter As Char In oSheetName
			If Char.IsLetterOrDigit(letter) Or Char.IsWhiteSpace(letter) Then
				oDisplayName = oDisplayName & letter
			End If
		Next
		ActiveSheet.Sheet.Name = oDisplayName
	Catch
		'MessageBox.Show("Couldn't change sheet name for " & oSheet.Name)
	End Try
Next
oSheets(1).Activate
iLogicVb.UpdateWhenDone = True

 

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @GosponZ 

 

You can use Regex for this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Imports System.Text.RegularExpressions
oDoc = ThisDoc.Document
oSheets = oDoc.Sheets

    For Each oSheet In oSheets
        oSheet.activate
        oView = oSheet.DrawingViews.Item(1)
        modelName = oView.ReferencedDocumentDescriptor.ReferencedDocument
        oProp = modelName.PropertySets.Item("Design Tracking Properties")
		
		sSpecicals = "[#$%&'()*+,-./\\~:;]"		
		oPN = Regex.Replace(oProp.Item("Part Number").Value, sSpecicals, "")
		oDesc = Regex.Replace(oProp.Item("Description").Value , sSpecicals, "")

        ActiveSheet.Sheet.Name = oPN & " " & oDesc 
    Next

oSheets(1).activate
iLogicVb.UpdateWhenDone = True

 

EESignature

0 Likes
Message 4 of 5

GosponZ
Collaborator
Collaborator
Thank you works perfect
0 Likes
Message 5 of 5

GosponZ
Collaborator
Collaborator
thank you it works great
0 Likes