Reload Linetype

Reload Linetype

David_Prontnicki
Collaborator Collaborator
1,580 Views
8 Replies
Message 1 of 9

Reload Linetype

David_Prontnicki
Collaborator
Collaborator

Hi All,

Is it possible to reload a linetype without having to use the send command method. I am familiar with Dev Blogs solution for this but I am curious if it can be done without the send command method. This is what I have so far:

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

Public Class AutocadService
    Implements IAutocadService

    Public Sub LoadLinetype(ByVal selectedLineTypeName As String, ByVal lineTypeFile As String) Implements IAutocadService.LoadLinetype

        Try

            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                Dim acLineTypTbl As LinetypeTable

                acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead)

                If acLineTypTbl.Has(selectedLineTypeName) = True Then

                    'reload linetype somehow

                    Dim frmMessageBox As New frmMessageBox
                    frmMessageBox.lblHeader.Text = "Linetype Loader"
                    frmMessageBox.lblMessageTitle.Text = "Linetype Loaded Successfully!"
                    frmMessageBox.lblMessageBody.Text = "The selected linetype, " & selectedLineTypeName & ", has been re-loaded in the drawing."
                    frmMessageBox.picIcon.Image = My.Resources.msbComplete

                    frmMessageBox.ShowDialog()

                ElseIf acLineTypTbl.Has(selectedLineTypeName) = False Then

                    acCurDb.LoadLineTypeFile(selectedLineTypeName, lineTypeFile)

                    Dim frmMessageBox As New frmMessageBox
                    frmMessageBox.lblHeader.Text = "Linetype Loader"
                    frmMessageBox.lblMessageTitle.Text = "Linetype Loaded Successfully!"
                    frmMessageBox.lblMessageBody.Text = "The selected linetype, " & selectedLineTypeName & ", is now available in the drawing."
                    frmMessageBox.picIcon.Image = My.Resources.msbComplete

                    frmMessageBox.ShowDialog()

                End If

                acTrans.Commit()

            End Using

        Catch ex As Exception

            Dim frmMessageBox As New frmMessageBox
            frmMessageBox.lblHeader.Text = "Linetype Loader"
            frmMessageBox.lblMessageTitle.Text = "Linetype Loading Failed!"
            frmMessageBox.lblMessageBody.Text = "Ensure you are using a proper drawing and/or the existing text styles are loaded."
            frmMessageBox.picIcon.Image = My.Resources.msbError

            frmMessageBox.ShowDialog()

        End Try

    End Sub

End Class

If the line type exists it errors out. I want it to just reload it.

0 Likes
Accepted solutions (2)
1,581 Views
8 Replies
Replies (8)
Message 2 of 9

ambrosl
Autodesk
Autodesk
Accepted solution

I don't have a direct example in VB.NET for this, but it should be similar to the concepts shown in this ObjectARX example (https://adndevblog.typepad.com/autocad/2015/03/reloading-linetype-from-file.html).  That is basically creating a new database and loading the linetype into that database, and then copying the linetype from the new database into the database of the current drawing.

 

An example of copying objects from one database to another database with VB.NET can be found here (https://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-E02A8AAF-61FF-4C72-8960-0AEEBBEC2594).



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 3 of 9

David_Prontnicki
Collaborator
Collaborator

Thank you for the reply, but I am having hard time understanding that code and converting it to VB. I'm assuming that is C#, but it does not convert in any online converter and even with my basic knowledge of and ability to read C# I am having a hard time making heads or tails of it. Any help would be greatly appreciated. 

0 Likes
Message 4 of 9

David_Prontnicki
Collaborator
Collaborator

@ambrosl

 

I want to make sure I am understanding you correctly: "That is basically creating a new database and loading the linetype into that database, and then copying the linetype from the new database into the database of the current drawing."

 

So I create a new database (acLtDbNew), load the linetype I want re-loaded (linetypeToReload) into this new database (acLtDbNew), then copy (linetypeToReload) from (acLtDbNew) to the existing database (acLtDb)? 

 

By doing this it forces a reload?

 

Or do you mean:

 

Create a new database (acLtDbNew), load the linetype I want re-loaded (linetypeToReload) into this new database (acLtDbNew), then copy ALL the other linetypes (linetypesExisting) from the existing database (acLtDb) into the new database (acLtDbNew) and discard the old database (acLtDb)?

 

Thanks

0 Likes
Message 5 of 9

ambrosl
Autodesk
Autodesk

The first, as long as you are using the Replace flag when cloning the linetype it should replace the definition in the existing drawing.  You may need to force an update on the drawing as well afterwards.   I have only personally done this with Dimension Styles and Layers stored in a CAD Standards (DWS) file and brought/updated them into my current drawing, not Linetypes though the concept should be the same.  If I get a bit of time today, I will try to create a code sample that does this.  Sorry, I have been a bit busy with the AutoCAD 2021 release.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 6 of 9

David_Prontnicki
Collaborator
Collaborator

@ambrosl 

 

No problem I completely understand. Below is what I came up with and it appears to be working, I need to do some more testing to be sure. I ending up having to load some text styles into the temp database for some of the linetypes to load, that is the CreateExistingTextStyle and CreateProposedTextStyle you see. What do you mean by force an update to the drawing? Also what is the DeferTranslation as Boolean at end of WblockCloneObjects do? Should that be true or false for what I am doing?

 

Also, thank you very much for all your help so far. I got a lesson in C++ as well. 😊

 

    Public Sub ReloadLinetype(ByVal selectedLineTypeName As String, ByVal lineTypeFile As String, ByVal acCurDb As Database)

        Try

            Using acTempDb As Database = New Database(True, True)

                CreateExistingTextStyle(acTempDb)
                CreateProposedTextStyle(acTempDb)
                
                acTempDb.LoadLineTypeFile(selectedLineTypeName, lineTypeFile)

                Using acTempTrans As Transaction = acTempDb.TransactionManager.StartTransaction()

                    Dim acTempLineTypeTbl As LinetypeTable = CType(acTempTrans.GetObject(acTempDb.LinetypeTableId, OpenMode.ForRead), LinetypeTable)

                    Dim acTempLineTypeId As ObjectId = acTempLineTypeTbl(selectedLineTypeName)

                    Dim acTempLineTypeObjIdColl As New ObjectIdCollection

                    acTempLineTypeObjIdColl.Add(acTempLineTypeId)

                    Dim acIdMap As IdMapping = New IdMapping()
                    acCurDb.WblockCloneObjects(acTempLineTypeObjIdColl, acCurDb.LinetypeTableId(), acIdMap, DuplicateRecordCloning.Replace, True)

                    acTempTrans.Commit()

                End Using

            End Using

        Catch ex As Exception

        End Try

    End Sub

 

 

0 Likes
Message 7 of 9

ambrosl
Autodesk
Autodesk
Accepted solution

I didn't run the code, but it looks like it follows the correct logic.

 

The Defer Translation flag affects when objects are copied if they are needed but not part of the ID array is my understanding.  You can find out more information about defer translation here:

https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-8A769B63-F192-4235-82B3-0CA2F3BBDFFD 

 

 



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 8 of 9

David_Prontnicki
Collaborator
Collaborator

@ambrosl 

 

Thank you again! I really appreciate it. Just one last question, what did you mean by force an update to the drawing? A regenall or something completely different?

 

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

does reloadlinetype works?

 

it doesn't work in my computer CAD2018.

 

using acCurDb.WblockCloneObjects(acTempLineTypeObjIdColl, acCurDb.LinetypeTableId(), acIdMap, DuplicateRecordCloning.Replace, True)

 cad crashes

 

using acCurDb.WblockCloneObjects(acTempLineTypeObjIdColl, acCurDb.LinetypeTableId(), acIdMap, DuplicateRecordCloning.Replace, false)

 cad doesn't crashes, but the linetype has no reload.

 

When I monitored acIdMap, I found that only one member has cloned,but the member isn't the linetype

0 Likes