Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
GosponZ
340 Views, 4 Replies

removing special characters

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

 

tyler.warner
in reply to: GosponZ

@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.
Curtis_Waguespack
in reply to: GosponZ

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

 

GosponZ
in reply to: tyler.warner

Thank you works perfect
GosponZ
in reply to: Curtis_Waguespack

thank you it works great