.NET

.NET

Reply
Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 1 of 4

What is the difference between .Net created and Interop object created layer?

395 Views, 3 Replies
01-10-2013 06:28 AM

Hi Guys,

 

I have used VB.net created a layer. then place a polyline on this layer. Then I use Teigh object export the drawing to bmp

oHost =

New TeighaX.OdaHostApp 'Create the DDX application

oBmp =

New TeighaX.OdaBmpOut 'Create the bmp-exporter'Variable stores a reference to the current drawing

oDoc = oHost.Application.Documents.Open(strDrawingPath)

'Open a drawing from the specified dwg-file

oBmp.WriteFile(oDoc.Database, strThumbBMPPath)

 

This throw an error.

 

However if I use COM Interop Object create a layer. place the same polyline on it. Then use the same code to export drawing to bmp. There is no error.

 

I think there must be different between .Net created layer to COM Interop created layer. Could anybody give me a hint? This drive me mad now.

 

here are code

VB.Net

    Public Function AutoCADCreateLayer(ByVal strLayerName As String, Optional ByVal lngLayerColour As Long = -1, _
                                       Optional ByVal blnLayerOn As Boolean = True, Optional ByVal blnLayerLocked As Boolean = False) As Boolean
        Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database

        Dim blnRt As Boolean
        Try
            Using lock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
                Using trans As Transaction = db.TransactionManager.StartTransaction
                    Dim objLayertb As LayerTable = db.LayerTableId.GetObject(OpenMode.ForWrite)
                    Dim objNewLayer As New LayerTableRecord
                    With objNewLayer
                        .Name = strLayerName
                        .Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, lngLayerColour)
                        '    .IsHidden = Not blnLayerOn
                        '   .IsLocked = blnLayerLocked
                    End With
                    objLayertb.UpgradeOpen()
                    Dim objNewLayerID As ObjectId = objLayertb.Add(objNewLayer)
                    trans.AddNewlyCreatedDBObject(objNewLayer, True)
                    db.Clayer = objNewLayerID
                    trans.Commit()
                End Using

                blnRt = True
            End Using
        Catch ex As Exception
            acApp.ShowAlertDialog("Error in create layer: " & ex.Message)
            Debug.Assert(False)

            blnRt = False
        Catch ex As SystemException
            acApp.ShowAlertDialog("Erro in create layer: " & ex.Message)
            Debug.Assert(False)

            blnRt = False

        End Try
        Return blnRt
    End Function

 COM Interop

Dim objCOMDrawing As Autodesk.AutoCAD.Interop.AcadDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument

objCOMDrawing.Layers.Add("mylayername")

 

Thanks very much

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 4

Re: What is the difference between .Net created and Interop object created layer

01-10-2013 11:07 AM in reply to: yaqiz

If you're adding layer in the current document

me think you need to remove" using LockDocument.. " code block from there,

just a guess, sorry

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 3 of 4

Re: What is the difference between .Net created and Interop object created layer

01-11-2013 06:42 AM in reply to: yaqiz

Are you sure you're asking your question in the right place ?

 

There's plenty of implementation differences between AutoCAD and other look-a-like APIs, and I don't know if this is the best place to ask about them.

 

Distinguished Mentor
607 Posts
37 Kudos
Registered: ‎03-18-2008
Post 4 of 4

Re: What is the difference between .Net created and Interop object created layer

01-11-2013 11:43 AM in reply to: DiningPhilosopher

What type of error is shown? If it is in one of your catch statements what does ex.message say?

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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!