.NET

Reply
Contributor
prmgame
Posts: 12
Registered: ‎08-31-2011
Message 1 of 3 (198 Views)

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

198 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
            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

 

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 2 of 3 (168 Views)

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
Contributor
prmgame
Posts: 12
Registered: ‎08-31-2011
Message 3 of 3 (151 Views)

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).

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community