Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Remove leading characters for each item in an array

1 REPLY 1
Reply
Message 1 of 2
phil_ellerbrock
134 Views, 1 Reply

Remove leading characters for each item in an array

We are developing code to allow our users to setup drawings with sheet formats. We currently have code pulling the list of all sheet formats present and providing a multi-list selection window. Further in the process, we are using leading characters in the format name to add specific names to the individual sheets being added. 

 

Is there a way to trim the first few characters from the array automatically, so the identifiers are not visible in the selection window?

 

Our code for the array list:

 

Dim MyArrayList As New ArrayList

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheetformats As SheetFormats
oSheetformats = oDoc.SheetFormats

Dim oSheetFormat As SheetFormat
'place each sheet format into the list
For Each oSheetFormat In oSheetformats
    MyArrayList.Add(oSheetFormat.Name)
Next

 

Example of a sheet format name we are using:
1: Sheet Format A
1: Sheet Format B
2: Sheet Format C
Sheet format names may share the first character. 

1 REPLY 1
Message 2 of 2

Hi @phil_ellerbrock.  There are lots of ways to manipulate String type data, so the example below is just one possible way to get a list of all available SheetFormat names in a drawing, with specific characters 'trimmed' from the start of each name, if they are present.  In this example, I am specifying an array of Char objects (characters) that should be trimmed from the start of each String, if they are present there, before it encounters any other character.  That array includes all the base numerical characters, plus the ":" (colon) and empty space characters.

 

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSFs As SheetFormats = oDDoc.SheetFormats
	Dim oSFNames As New List(Of String)
	Dim oTrimChars() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", " " }
	For Each oSF As SheetFormat In oSFs
		Dim sTrimmedName As String = oSF.Name.TrimStart(oTrimChars)
		oSFNames.Add(sTrimmedName)
	Next oSF
	Dim sSFName As String = InputListBox("Choose one.", oSFNames)
End Sub

 

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)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report