iLogic export txt file with ASCII (ANSI) fomatting

iLogic export txt file with ASCII (ANSI) fomatting

Anonymous
Not applicable
1,227 Views
5 Replies
Message 1 of 6

iLogic export txt file with ASCII (ANSI) fomatting

Anonymous
Not applicable

I have a problem with an iLogic exported txt file.

I need to have it formatted as ASCII (ANSI) and not UTF because charts like Å,Ä,Ö,Ø gets like Ã¶Ã¶Ã¤Ã¤ when import the txt file to ERP system.

 

iLogic code:

 

'check that the active document is an drawing file
If ThisApplication.ActiveDocument.DocumentType  <>  kDrawingDocumentObject Then
	MessageBox.Show("Detta script fungerar endast på ritningsfil" & vbCrLf & "Öppna ritning och kör därifrån", "Varning")
	Exit Sub
End If

oFolder = "C:\WF\Pyramid Importfiler\"
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
oWrite = System.IO.File.CreateText(oFolder & ThisDoc.FileName(False) &"-PRODUKT.txt")

sweTitle = InputBox("Ange svensk benämning","Ange svensk benämning", iProperties.Value(ThisDoc.FileName(False)+".iam", "Project", "Description"))

pyrArtType = InputBox(	"Exempel enligt nedan:" & vbCrLf &
						" " & vbCrLf &
						"810 ­ Legotillverkad prod mek" & vbCrLf & 
						"820 ­ Egentillverkad prod mek" & vbCrLf & 
						"830 ­ Legomonterad prod mek" & vbCrLf &
						"840 ­ Egenmonterad prod mek","Ange artikeltyp, OBS! Endast nummer", "840")
						
pyrKalkType = InputBox(	"Exempel enligt nedan:" & vbCrLf & 
						" " & vbCrLf &
						"TB08 - Reservdelar" & vbCrLf & 
						"TB99 - Övrigt" & vbCrLf & 
						"TB02 - Tillbehör lyftare","Ange kalkyltyp, OBS! Endast nummer", "TB08")
						
pyrOpType = InputBox(	"Exempel enligt nedan:" & vbCrLf & 
						" " & vbCrLf &
						"730662 - Svetsning" & vbCrLf & 
						"730663 - Maskinbearbetning" & vbCrLf & 
						"730666 - Montering mekanisk" & vbCrLf & 
						"741766 - Lego PMA","Ange operation i produkt, OBS! Endast nummer", "730666")
						
pyrOpTime = InputBox(	"Ange kalkylerade timmar för operation" & vbCrLf,"Ange kalkylerade timmar för operation, OBS! Endast nummer", "1")						

pyrZink = InputRadioBox("Elförzinkning", "Ja", "Nej", pyrZink, Title := "Ska operation för elförzining läggas till?")


						
oWrite.WriteLine("01" & ThisDoc.FileName(False))
'Produktbenämning
oWrite.WriteLine("#12302;" & sweTitle)
'Artikelbenämning
oWrite.WriteLine("#12421;" & sweTitle)
'Artikelbenämning 2
oWrite.WriteLine("#12422;" & iProperties.Value(ThisDoc.FileName(False)+".iam", "Project", "Description"))
'Enhet (styck)
oWrite.WriteLine("#12431;S")
'Kategori
oWrite.WriteLine("#12415;1")
'Artikeltyp
oWrite.WriteLine("#12471;" & pyrArtType)
'Kalkyltyp
oWrite.WriteLine("#12475;" & pyrKalkType)
'Operation
oWrite.WriteLine("11" & pyrOpType & "										" & pyrOpTime)
	
	Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oPartList As PartsList
    oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
    Dim i As Long
    For i = 1 To oPartList.PartsListRows.Count
        Dim oRow As PartsListRow
        oRow = oPartList.PartsListRows.Item(i)
        
		Dim oCell As PartsListCell
        oCell = oRow.Item("Mod no./Dim.")
        sCell = oCell.Value
		 
		Dim oCell2 As PartsListCell
        oCell2 = oRow.Item("Qty")
        sCell2 = oCell2.Value
		 
	Dim Result = oWrite.WriteLine("11" & sCell & "										" & sCell2)
				 oWrite.WriteLine("#12428;10")
        Next

'Elförzinkning
If pyrZink = True
oWrite.WriteLine("11741750" & "										" & "1")
Else
End If

oWrite.Close()
'open the file

 

0 Likes
1,228 Views
5 Replies
Replies (5)
Message 2 of 6

Mark.Lancaster
Consultant
Consultant

@Anonymous

 

Programming needs, issues, and questions for Inventor should be posted in the Inventor Customization forum for best results. 

 

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

 

I will have the moderator relocate your posting there to best suit your needs.

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 3 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

Welcome to the forums.

 

As mentioned you can search and ask programming questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

As for your question, I think you would want to use something like this.

 

 

oFolder = "C:\TEMP2\"
oFile = oFolder & "Test_File.txt"
oEncoding = System.Text.Encoding.ascii
Dim oApend As Boolean = True

'Ensure folder is present
If Not System.IO.Directory.Exists(oFolder) Then
	'create folder 
	System.IO.Directory.CreateDirectory(oFolder)
End If

'create (or use existing) text file
Using oSW As System.IO.StreamWriter = New System.IO.StreamWriter (oFile, oApend, oEncoding)
End Using


'append to the existing text file
oAppend = IO.File.AppendText(oFile)
oAppend.WriteLine("Hello World, " & Now())
oAppend.Flush()
oAppend.Close()

 

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

EESignature

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hello. Thank you for reply. Unfortunatelly the file was witten in UTF and when "translating" it to ANSI i get the same results for ÅÄÖ

1.png2.png

0 Likes
Message 5 of 6

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

My apologies, I must have fooled myself when looking at the output file earlier when I posted the example, I now see the same results as you.

 

I'm not sure I have a solution, but you might search Google for "vb.net system.io.streamwriter ascii" to see if you can find an example.

 

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

EESignature

0 Likes
Message 6 of 6

Anonymous
Not applicable

@Curtis_Waguespack I´ve tried google a solution but with no big sucsess.

Thank you anyway. Is there anyone that can have a solution for this?