Author Topic: QR code sample error  (Read 2713 times)

0 Members and 1 Guest are viewing this topic.

sigster

  • Newt
  • Posts: 31
QR code sample error
« on: November 08, 2023, 03:36:31 AM »


Hi
I was trying to use QR code sample from Kean Walmsley
https://www.keanw.com/2010/08/attaching-an-upright-raster-image-at-a-user-specified-location-in-an-autocad-drawing-using-net.html

But the error I get is this ,  any Solution how I can fix this

Autodesk.AutoCAD.Runtime.Exception: eFileAccessErr
line 96  =  rid.SourceFileName = rootUrl & message


Code: [Select]
   <CommandMethod("QR")>
        Public Shared Sub QRCode()
            Const recBase As String = "ADNP_QR"
            Const rootUrl As String = "http://chart.apis.google.com/chart?cht=qr&chs=500x500&chl="
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Dim pr As PromptResult = ed.GetString(vbLf & "Enter email address to encode: ")
            If pr.Status <> PromptStatus.OK Then Return
            Dim message As String = "mailto%3A" & pr.StringResult.Replace("@", "%40")
            Dim tr As Transaction = doc.TransactionManager.StartTransaction()

            Using tr
                Dim dictId As ObjectId = RasterImageDef.GetImageDictionary(db)

                If dictId.IsNull Then
                    dictId = RasterImageDef.CreateImageDictionary(db)
                End If

                Dim dict As DBDictionary = CType(tr.GetObject(dictId, OpenMode.ForRead), DBDictionary)
                Dim i As Integer = 0
                Dim recName As String = recBase & i.ToString()

                While dict.Contains(recName)
                    i += 1
                    recName = recBase & i.ToString()
                End While

                Dim rid As RasterImageDef = New RasterImageDef()
                rid.SourceFileName = rootUrl & message
                rid.Load()
                dict.UpgradeOpen()
                Dim defId As ObjectId = dict.SetAt(recName, rid)
                tr.AddNewlyCreatedDBObject(rid, True)
                Dim ppr As PromptPointResult = ed.GetPoint(vbLf & "First corner of QR Code: ")
                If ppr.Status <> PromptStatus.OK Then Return
                Dim start As Point3d = ppr.Value
                ppr = ed.GetCorner(vbLf & "Second corner of QR Code: ", start)
                If ppr.Status <> PromptStatus.OK Then Return
                Dim diff As Vector3d = ppr.Value - start
                Dim size As Double = Math.Min(Math.Abs(diff.X), Math.Abs(diff.Y))
                If size < Tolerance.[Global].EqualPoint Then Return
                Dim orig As Point3d
                Dim xAxis As Vector3d = New Vector3d(size, 0, 0)
                Dim yAxis As Vector3d = New Vector3d(0, size, 0)

                If diff.X > 0 AndAlso diff.Y > 0 Then
                    orig = start
                ElseIf diff.X < 0 AndAlso diff.Y > 0 Then
                    orig = start + New Vector3d(-size, 0, 0)
                ElseIf diff.X > 0 AndAlso diff.Y < 0 Then
                    orig = start + New Vector3d(0, -size, 0)
                Else
                    orig = start - New Vector3d(size, size, 0)
                End If

                Dim ri As RasterImage = New RasterImage()
                ri.ImageDefId = defId
                ri.ShowImage = True
                Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem
                ri.Orientation = New CoordinateSystem3d(orig.TransformBy(ucs), xAxis.TransformBy(ucs), yAxis.TransformBy(ucs))
                Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                Dim btr As BlockTableRecord = CType(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                btr.AppendEntity(ri)
                tr.AddNewlyCreatedDBObject(ri, True)
                RasterImage.EnableReactors(True)
                ri.AssociateRasterDef(rid)
                AddRegAppTableRecord("ADNP_QR")
                Dim rb As ResultBuffer = New ResultBuffer(New TypedValue(1001, "ADNP_QR"), New TypedValue(1000, message))
                ri.XData = rb
                rb.Dispose()
                tr.Commit()
            End Using
        End Sub

        Private Shared Sub AddRegAppTableRecord(ByVal regAppName As String)
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim tr As Transaction = doc.TransactionManager.StartTransaction()

            Using tr
                Dim rat As RegAppTable = CType(tr.GetObject(db.RegAppTableId, OpenMode.ForRead, False), RegAppTable)

                If Not rat.Has(regAppName) Then
                    rat.UpgradeOpen()
                    Dim ratr As RegAppTableRecord = New RegAppTableRecord()
                    ratr.Name = regAppName
                    rat.Add(ratr)
                    tr.AddNewlyCreatedDBObject(ratr, True)
                End If

                tr.Commit()
            End Using
        End Sub

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8586
  • AKA Daniel
Re: QR code sample error
« Reply #1 on: November 08, 2023, 03:42:32 AM »
isn't QR code built-in now? or maybe it's in the app store?