Inserting a Drawing Into My Current Drawing

Inserting a Drawing Into My Current Drawing

mgorecki
Collaborator Collaborator
819 Views
3 Replies
Message 1 of 4

Inserting a Drawing Into My Current Drawing

mgorecki
Collaborator
Collaborator

Hello,

I'm just learning VB.Net and would like to be able to insert an existing drawing into my current drawing.  The existing drawing has all of my dimension and text styles already defined, I would like to insert it so I can use the styles later.  Manually, I can insert the drawing using the "Insert" command and insert it exploded.  That's what I'd like to do in VB.Net.

 

I have code (that I found) that inserts the drawing, but it also leaves the block on the list of editable blocks.  It's not commented, so I really con't learn much from it.  I would like to insert the drawing so the styles are available in my current drawing, but not have the block name in the list of blocks.  Attached is the code I found.

 

Thanks in advance for any help on this.

Mark

0 Likes
820 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

It might be eaiser to just add the styles from a drawing instead of inserting the drawing

 

 

I am not at my normal computer so later I can post the code that is not quickly thrown together as this and a better example, but this should be good enough to show the general idea.

 

This adds all the textstyles and plotsettings(Page Setups) from a existing drawing .

 

The textstyles is to show grabbing from a Symbol Table and the PlotSettings is to show grabbing from a Dictionary

 

 <CommandMethod("AddTextStylesAndPlotSettings")> _
        Public Sub AddTextStylesAndPlotSettings()

            Dim db As Database = HostApplicationServices.WorkingDatabase
            Dim stylesDb As New Database(FalseTrue)
            stylesDb.ReadDwgFile("C:\Test\Styles.dwg"FileOpenMode.OpenForReadAndAllShare, True"")

            Dim objIdColl As New ObjectIdCollection

            Using trx As Transaction = db.TransactionManager.StartTransaction
                Using stylesTrx As Transaction = stylesDb.TransactionManager.StartTransaction

                    Dim txtStyleTbl As TextStyleTable = db.TextStyleTableId.GetObject(OpenMode.ForWrite)
                    Dim stylesTxtStyleTbl As TextStyleTable = stylesDb.TextStyleTableId.GetObject(OpenMode.ForRead)

                    For Each objId As ObjectId In stylesTxtStyleTbl
                        Dim txtStyleRec As TextStyleTableRecord = objId.GetObject(OpenMode.ForRead)

                        If Not txtStyleTbl.Has(txtStyleRec.Name) Then
                            objIdColl.Add(txtStyleRec.ObjectId)
                        End If

                    Next

                    Dim map As New IdMapping
                    db.WblockCloneObjects(objIdColl, txtStyleTbl.ObjectId, map, DuplicateRecordCloning.Replace, False)



                    Dim stylesPlotDic As DBDictionary = stylesDb.PlotSettingsDictionaryId.GetObject(OpenMode.ForRead)

                    For Each dicEntry As DictionaryEntry In stylesPlotDic

                        Dim objId As ObjectId = CType(dicEntry.Value, ObjectId)
                        Dim pltSettings As PlotSettings = objId.GetObject(OpenMode.ForRead)

                        Dim copyPltSettings As New PlotSettings(False)
                        copyPltSettings.CopyFrom(pltSettings)

                        copyPltSettings.AddToPlotSettingsDictionary(db)

                    Next

                    trx.Commit()

                End Using
            End Using
        End Sub
0 Likes
Message 3 of 4

mgorecki
Collaborator
Collaborator

Hi Jeff,

Thank you so much for your code.  It works great, although I had to change one line for some reason.

stylesDb.ReadDwgFile("C:\Test\Test.dwg", FileShare.Read, True, "")

stylesDb.ReadDwgFile("C:\Test\Test.dwg",FileOpenMode.OpenForReadAndAllShare, True, "")

 

After reading your post, I also looked around at "The Swamp".  You seem to have a group of very knowedgable people over there.  I decided to join "The Swamp", I'm sure I'll learn a lot. 

 

Thanks again,

Mark

0 Likes
Message 4 of 4

Anonymous
Not applicable

You will find great info and in opionion the best fourm to learn

0 Likes