Results 1 to 9 of 9

Thread: Inserting block into drawing, get 'wrong client object' warning.

  1. #1
    Member
    Join Date
    2011-10
    Posts
    39
    Login to Give a bone
    0

    Default Inserting block into drawing, get 'wrong client object' warning.

    Hi, I want to say that everything seems to be working correctly when I insert a block into my drawing, however it gives me a wrong client object warning when I do it. Other than that everything else seems to be working correctly with the block insertion.

    Here is my code (existingPermit is a blockreference that is currently in the drawing and listPermitLocation(1) is the location of the block on the server):
    Code:
    insertBlockNoLoop(ThisDrawing, _
    existingPermit.Layer, _
    existingPermit.ColorIndex, _
    existingPermit.Position, _
    listPermitLocation(1), _
    existingPermit.ScaleFactors(0), _
    existingPermit.ScaleFactors(1), _
    existingPermit.ScaleFactors(2), _
    existingPermit.Linetype, _
    existingPermit.Rotation)
    
    existingPermit.Erase()
    
    Public Shared Sub insertBlockNoLoop(Drawing As Autodesk.AutoCAD.Interop.AcadDocument, layer As String, color As Integer, userPoint As Point3d, location As String, xscale As Double, yscale As Double, zscale As Double, linetype As String, rotation As Double)        Dim tempBlock As AcadBlockReference
    
            Try
                Dim inputPoint(0 To 2) As Double
                inputPoint(0) = userPoint(0)
                inputPoint(1) = userPoint(1)
                inputPoint(2) = userPoint(2)
                tempBlock = Drawing.ModelSpace.InsertBlock(inputPoint, location, xscale, yscale, zscale, rotation)
                tempBlock.Layer = layer
            Catch ex As System.Runtime.InteropServices.ExternalException
            Catch exs As Exception
            End Try
    
     End Sub
    I have attached the warning as well and I'm using Map 3D 2014 and VB.net. Also it doesn't seem to give a warning on the first time I replace the block, but after the first time it starts to give this warning and gives it every time.

    Thanks for any help,
    Attached Images Attached Images

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    Not sure there's enough information above, so I'll ask why not just use .NET API to Insert Blocks in lieu of COM?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    You pass an argument called ThisDrawing, but are you sure it is actually this drawing? When you are in vba, it is tied to the running instance of acad and it can monitor events so that when you switch documents, ThisDrawing gets updated with the currently active document. But that process doesn't happen in .NET.
    C:> ED WORKING....

  4. #4
    Member
    Join Date
    2011-10
    Posts
    39
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    I believe it is passing the correct value for ThisDrawing as it is defined in the form and everything is still actually working other than the warning message that is annoying. It correctly places the block without any issues that I can tell. I tried updating the code to use the .NET API as suggested and it still gives me the warning message. Here is the updated code:

    Code:
    Shared ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = CType(Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument), Autodesk.AutoCAD.Interop.AcadDocument)
    Shared doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
    Shared db As Database = doc.Database
    Shared ed As Editor = doc.Editor
    
     Public Shared Sub insertBlockNoLoop(blockName As String, blockLocation As String, userPoint As Point3d, layer As String, color As Integer, scaleFactor As Scale3d, rotation As Double)
            Dim trans As Transaction = db.TransactionManager.StartTransaction
            Try
                Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim btr As BlockTableRecord
                btr = trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim id As ObjectId
                If bt.Has(blockName) Then
                    Dim btrSrc As BlockTableRecord
                    btrSrc = trans.GetObject(bt.Item(blockName), OpenMode.ForRead)
                    id = btrSrc.Id
                Else
                    Dim dbDwg As New Database(False, True)
                    dbDwg.ReadDwgFile(blockLocation, IO.FileShare.Read, True, "")
                    id = db.Insert(blockName, dbDwg, True)
                    dbDwg.Dispose()
                End If
                Dim blkRef As New BlockReference(userPoint, id)
                checkNewLayer(layer, color)
                blkRef.Layer = layer
                blkRef.ColorIndex = color
                blkRef.ScaleFactors = scaleFactor
                blkRef.Rotation = rotation
                btr.AppendEntity(blkRef)
                trans.AddNewlyCreatedDBObject(blkRef, True)
                trans.Commit()
            Catch
                MsgBox("Failed to insert block")
            Finally
                trans.Dispose()
            End Try
        End Sub
    It also seems to be somewhat dependent on the blocks I insert. For instance the first blocks I inserted and was having the issue with now only errors the first time I change it and not every time I change it back (the user selects between two blocks, it deletes the old one and inserts the new one, this causes a warning however when I switch back to the old one it doesn't anymore). However other blocks cause the warning every time I try inserting them whether they were on the drawing or not. Also the message it gives states something to do with TBInformation, that is a ODTable that I have attached to a few elements in the drawing, however it is not existent in the drawing/blocks I am inserting or being attached or updated in anyway during the insertion.

    Thanks for the help.

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    Unfortunately, I do not have time this morning to debug your code for myself, but in skimming your revised code....

    Quote Originally Posted by BlackBox View Post
    ... you don't technically need to add a try / catch / finally block[, instead consider a] using statement, as once compiled the code is added for you.
    Cheers
    Last edited by BlackBox; 2014-03-13 at 11:43 AM. Reason: [Edited for clarity]
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Member
    Join Date
    2011-10
    Posts
    39
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    No problem, thanks for the help. Here is where things get weird, I've updated the code as follows and the original blocks that were causing the issues no longer causes a warning. The original blocks were Stamp1, Stamp2. It starts with Stamp1 by default and changing it to Stamp2 would give a warning the first time, and afterwards never get a warning switching between them once the block was defined in the drawing. However now it doesn't give a warning either time for Stamp1 or Stamp2. Seems like a good thing, but it's not because I also have 3 other blocks for the user to choose from, Logo1, Logo2, Logo3. These are acting the same way Stamp1 and Stamp2 did BEFORE, not the way they are currently working! I've debugged and they run through the exact same lines of code that Stamp1 and Stamp2 do, again causing the warning the first time they are put into the drawing and afterwards if I switch back to them they don't cause a warning.

    Here is the updated code:

    Code:
    Shared ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = CType(Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument), Autodesk.AutoCAD.Interop.AcadDocument)
    Shared doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
    Shared db As Database = doc.Database
    Shared ed As Editor = doc.Editor
    
        Public Shared Sub insertBlockNoLoop(blockLocation As String, userPoint As Point3d, layer As String, color As Integer, scaleFactor As Scale3d, rotation As Double)
            Using tr As Transaction = doc.TransactionManager.StartTransaction()
                Dim blockName As String = SymbolUtilityServices.GetBlockNameFromInsertPathName(blockLocation)
                Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                btr = tr.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim id As ObjectId
                If bt.Has(blockName) Then
                    Dim btrSrc As BlockTableRecord
                    btrSrc = tr.GetObject(bt.Item(blockName), OpenMode.ForRead)
                    id = btrSrc.Id
                Else
                    Using xDb As New Database(False, True)
                        xDb.ReadDwgFile(blockLocation, IO.FileShare.Read, True, "")
                        id = db.Insert(blockName, xDb, True)
                    End Using
                End If
    
                If id.IsNull Then
                    ed.WriteMessage(vbLf & "Failed to insert block")
                    Return
                End If
                Dim blkRef As New BlockReference(userPoint, id)
                checkNewLayer(layer, color)
                blkRef.Layer = layer
                blkRef.ColorIndex = color
                blkRef.ScaleFactors = scaleFactor
                blkRef.Rotation = rotation
                btr.AppendEntity(blkRef)
                blkRef.SetDatabaseDefaults()
                tr.AddNewlyCreatedDBObject(blkRef, True)
                tr.Commit()
            End Using
    End Sub
    As I mentioned both the Stamp1/2 and Logo1/2/3 go through the same process when debugging yet one causes the warning and one no longer does. The first time a user changes from Stamp1 to Stamp2 it goes through the section Using xDb As New Database(False, True) to define the id so it doesn't exist in the drawing already somehow and afterwards it goes into the first if bt.Has(blockName) Then section. This is the exact same process Logo1/2/3 goes through.

    I'm at a loss, but thanks for any help you can give me.

  7. #7
    Member
    Join Date
    2011-10
    Posts
    39
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    While debugging and watching the open drawing at the same time, the message window seems to pop up in the drawing at the line:
    id = db.Insert(blockName, xDb, True), however it doesn't do this for the Stamp1/2 anymore even though it hits that line of code but it does for the Logo1/2/3.

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    Quote Originally Posted by BlackBox View Post
    Unfortunately, I do not have time this morning to debug your code for myself, but in skimming your revised code....
    In my haste, I don't think I clearly communicated what I meant... I'll revisit this, as I did not mean that NO try/catch is needed at all, as I'm sure more experienced developers will attest, even with a using statement.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Member
    Join Date
    2008-02
    Location
    vancouver, bc
    Posts
    3
    Login to Give a bone
    0

    Default Re: Inserting block into drawing, get 'wrong client object' warning.

    Did this issue ever get resolved? I happen to be experiencing the exact same problem. I'm able to insert a block using almost the exact same approach (mind for the properties I set after block insertion). Able to use it just fine with some blocks, have a block which is now giving me the "Wrong client object" AutoCAD Map Message.

    Any help would be greatly appreciated!

Similar Threads

  1. Replies: 4
    Last Post: 2009-03-02, 01:23 PM
  2. Warning message when inserting family
    By jsteinhauer in forum Revit Architecture - General
    Replies: 0
    Last Post: 2008-02-08, 05:14 PM
  3. inserting block into drawing - freaking out
    By Mac Demer in forum AutoCAD General
    Replies: 4
    Last Post: 2007-06-19, 05:05 AM
  4. Replies: 0
    Last Post: 2007-04-05, 07:10 PM
  5. defining a block in a drawing w/o actually inserting
    By jgardner.79905 in forum AutoLISP
    Replies: 3
    Last Post: 2005-09-19, 08:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •