.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

2 REPLIES 2
Reply
Message 1 of 3
prmgame
496 Views, 2 Replies

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

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
            Try
                Dim DBTextBase As New DBText
                DBTextBase.Rotation = Rotation
                DBTextBase.Layer = LayerName
                DBTextBase.Height = Height
                DBTextBase.TextString = TextValue
                DBTextBase.SetFromStyle()
                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)
                DBTextBase.SetDatabaseDefaults()
                BlockTabRec.AppendEntity(DBTextBase)
                WTransaction.AddNewlyCreatedDBObject(DBTextBase, True)
                WTransaction.Commit()
                BlockTabRec.Dispose()
                BlockTab.Dispose()
                WTransaction.Dispose()
                WorkDataBase.Dispose()
                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)")
                GC.Collect()
                Return Nothing
            End Try
        End Function

 

2 REPLIES 2
Message 2 of 3
Artvegas
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
Message 3 of 3
prmgame
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).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost