- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear ACAD and VBA Pros,
This is my first entry in this forum, looking forward for your help.
I am using AUTOCAD 2020.
My problem is the following:
I would like to integrate a barcode in my drawing (.dwg). I choose to build a block with an attribute and give that one my barcode font. Works out so far.
The next step is to integrate the value of this attribute from a specific .TXT file (Barcode.txt), located in my project folder. Within this .txt file I got one line which should be my attribute value. I managed that.
The problem is, that this .txt file contains some special charcters like “ËÌ!!#”, as it is a calculated value to shorten the length of the barcode. As soon as I load those characters into my VBA variable, they change to some completely other characters. So the content I set my attribute is wrong, and therefore the barcode is too.
Exampel: .txt content"Ë#!!4(*Ì" changes to "Ë#!!4(*ÃŒ" in vba and autocad.
It works if I manually copy-paste my .txt file content into my attribute.
Anyone have some experience with this?
I have never used LISP, maybe someone has a solution for my problem using LISP.
Here is what I got so far.
Sub Change_it()
''GET BARCODE CONTENT
Dim dokpath, barpath, filecont As String
Dim pathpos As Long
Dim iFile As Integer: iFile = FreeFile
Dim oData As New DataObject
dokpath = Application.ActiveDocument.Path
pathpos = InStr(1, dokpath, "MyDrawingfolderWithinTheProjectfolder")
barpath = Left(dokpath, pathpos - 1) & "Barcode.txt" ''file in my Projectfolder
Open barpath For Input As #1
Do Until EOF(1)
Line Input #1, filecont
Loop
Close #1
''FILL ATRIBUTE WITH CONTENT
Dim obj As AcadBlockReference
Dim inspt As Variant
ThisDrawing.Utility.GetEntity obj, inspt, "Select object:"
' Checks if you selected a block.
If obj.ObjectName = "AcDbBlockReference" Then
' Check for attributes.
If obj.HasAttributes Then
Dim AttList As Variant
' Build a list of attributes for the current block.
AttList = obj.GetAttributes
' Cycle throught the list of attributes.
For i = LBound(AttList) To UBound(AttList)
' Check for the correct attribute tag.
If AttList(i).TagString = "BARCODE" Then
AttList(i).TextString = filecont
End If
Next
End If
Else
MsgBox "You did not select a block."
End If
End Sub
Solved! Go to Solution.