12 Posts
0 Kudos
Registered: ‎08-31-2011
Post 1 of 3

I'm having problems creating the element in DBTEXT BackgroundWorker in VB! HELP?

233 Views, 2 Replies
06-01-2012 10:21 AM

I'm having problems creating the element in DBTEXT BackgroundWorker in VB! Develop a function to create the element dbtext in the current document, when I use this function within <Autodesk.AutoCAD.Runtime.CommandMethod("")> it works perfectly, but when it is used within BackgroundWorker raises the point of different alignment indicated. And the problem is solved when you run the AUDIT command in the project, then the alignment points are corrected. The same problem is occurring for the blocks that have attributes, in this case the alignment points are also displaced the attributes of the standard indicated.


Public Function NewDBText(ByVal InsertPoint As Point3d, ByVal Rotation As Double, ByVal LayerName As String, ByVal ForceColor As String, ByVal AttacPoint As AttachmentPoint, ByVal TextValue As String, ByVal Height As Double) As ObjectId
                Dim DBTextBase As New DBText
                DBTextBase.Rotation = Rotation
                DBTextBase.Layer = LayerName
                DBTextBase.Height = Height
                DBTextBase.TextString = TextValue
                DBTextBase.Annotative = AnnotativeStates.False
                If (ForceColor <> "ByLayer") Then
                    DBTextBase.ColorIndex = ForceColor
                End If
                DBTextBase.Position = InsertPoint
                DBTextBase.Justify = AttacPoint
                DBTextBase.AlignmentPoint = InsertPoint
                Dim WorkDataBase As Database = HostApplicationServices.WorkingDatabase()
                Dim WTransaction As Transaction = WorkDataBase.TransactionManager.StartTransaction()
                Dim BlockTab As BlockTable = WTransaction.GetObject(WorkDataBase.BlockTableId, OpenMode.ForRead)
                Dim ObjectIdBlockTabRec As ObjectId = BlockTab.Item(BlockTableRecord.ModelSpace)
                Dim BlockTabRec As BlockTableRecord = WTransaction.GetObject(ObjectIdBlockTabRec, OpenMode.ForWrite)
                WTransaction.AddNewlyCreatedDBObject(DBTextBase, True)
                Return DBTextBase.ObjectId()
            Catch ex As System.Exception
                My.Application.Log.DefaultFileLogWriter.CustomLocation = My.Application.Info.DirectoryPath & "\Logs"
                My.Application.Log.DefaultFileLogWriter.BaseFileName = "SgmPlusCode"
                My.Application.Log.WriteEntry("Class (AcadGeometricManager) " & DateAndTime.DateString & " " & DateAndTime.TimeString)
                My.Application.Log.WriteException(ex, TraceEventType.Error, "Method (NewDBText)")
                Return Nothing
            End Try
        End Function


Distinguished Contributor
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 2 of 3

Re: I'm having problems creating the element in DBTEXT BackgroundWorker in VB! H

06-02-2012 10:08 PM in reply to: prmgame
I assume when you mention BackgroundWorker that you are talking about multi-threading. Multi-threading with the API is limited because AutoCAD runs on a single thread. I suggest you watch the Autodesk University online class titled "Parallel Programming in an AutoCAD Application" for some background and possible workarounds on this: http://au.autodesk.com/?nd=class&session_id=8975
12 Posts
0 Kudos
Registered: ‎08-31-2011
Post 3 of 3

Re: I'm having problems creating the element in DBTEXT BackgroundWorker in VB! H

06-03-2012 02:13 PM in reply to: Artvegas

Yes I mean Multithreading, the strange thing is that with the other objects everything works perfectly, (MTEXT, POLYLINE, LINE, CIRCLE), these problems do not present but the element is DBTEXT with the alignment point wrong.  I study the oversized video for you and see if I get a solution, because without the job done in AutoCAD Multithreading no longer responds, and indicates (NOTRESPONDING).

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!