Import leader text to excel: Upgrade of current code

Import leader text to excel: Upgrade of current code

Anonymous
Not applicable
465 Views
2 Replies
Message 1 of 3

Import leader text to excel: Upgrade of current code

Anonymous
Not applicable

A user here on the board, was kind enough to provide me with the following code. The code extracts the value from leader texts to excel.

 

But i have some wishes for improvement of this code, for our daily use.

 

1. The code should only extract leader text with $ in front of it

2. I'd like to have a predefined text in the spreadsheet, for A1 and B1 (ie A1 = Current Value / B1 = New Value)

 

3. All cells are set to "Standard"

 

4. This would probably have to be separate code, but a code that can import the new value from the spreadsheet back into inventor and replace the current value leader text with the new value.

 

Example:

- I export to excel

- Value in A2 is $123

- I enter 555 in B2 as the new value

- Click save in excel

- Run import rule in Inventor

- And the leader text that had previously said $123, now gets replaced by 555 (info: we expect to have multiple leader texts on our drawing)

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim OFullName As String = oDoc.FullFileName
'Remove file extension 
Dim oExcelName As String = Left(OFullName, (InStrRev(OFullName, ".", - 1, vbTextCompare) - 1)) & ".xlsx"

Dim row As Integer = 2  ''' Indicate from which row the read of excel values will begin
xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlWorkbook = xlApp.Workbooks.Add
xlWorksheet = xlWorkbook.Worksheets.Item(1)

For Each oLeaderNote As LeaderNote In oDoc.ActiveSheet.DrawingNotes.LeaderNotes
	oValue = oLeaderNote.Text
	xlWorksheet.Range("A" & row).Value = oValue
	row = row + 1 
Next    

'set all of the columns to autofit
xlWorksheet.Columns.AutoFit   
'save the file
xlWorkbook.SaveAs(oExcelName)
'xlWorkbook.Close
'xlApp.Quit
'xlApp = Nothing
0 Likes
466 Views
2 Replies
Replies (2)
Message 2 of 3

clutsa
Collaborator
Collaborator

1. Are you OK with the note changing while you update the spreadsheet? Like can "$234" be changed to "RowValue4Here" until the sheet is updated?

2. Will the notes that start with "$" have text behind the note or only the amount? Like will it ever be "$234 each" or only ever "$234"?

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 3

Anonymous
Not applicable

1. Are you OK with the note changing while you update the spreadsheet? Like can "$234" be changed to "RowValue4Here" until the sheet is updated?

So if I run the export rule the leader text changes until i import it again. Is that correct understood?

 

 

2. Will the notes that start with "$" have text behind the note or only the amount? Like will it ever be "$234 each" or only ever "$234"?

Yes they will have different text

 

0 Likes