.NET

Reply
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 1 of 10 (336 Views)

BlockTable case sensitive keys

336 Views, 9 Replies
07-01-2013 03:35 AM

When I want to test if block with a given name exists in drawing, I use BlockTable.Has(key as String) method, which is case sensitive, but then, when I try to insert a block with the same name, but different case, the block name is considered the same.

 

How can I test if the block in in the drawing then?

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 2 of 10 (332 Views)

Re: BlockTable case sensitive keys

07-01-2013 03:47 AM in reply to: matus.brlit

Hi,

 

>> I use BlockTable.Has(key as String) method, which is case sensitive

Sorry, no, it's not case senstitive! You also can't create a block named "XXX" and a block "xxx" coexisting in the same drawing.

How did you test it?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
_gile
Posts: 2,071
Registered: ‎04-29-2006
Message 3 of 10 (329 Views)

Re : BlockTable case sensitive keys

07-01-2013 03:51 AM in reply to: matus.brlit

Hi,

 

By my side, I never saw the SymbolTable.Has(string) method being case sensitive...

Gilles Chanteau
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 4 of 10 (321 Views)

Re: BlockTable case sensitive keys

07-01-2013 04:09 AM in reply to: Alfred.NESWADBA

alfred.neswadba wrote:

Hi,

 

>> I use BlockTable.Has(key as String) method, which is case sensitive

Sorry, no, it's not case senstitive! You also can't create a block named "XXX" and a block "xxx" coexisting in the same drawing.

How did you test it?

 

- alfred -


That's what I call case sensitive, when a block XXX is in the drawing, BlockTable.Has("xxx") returns False

 

but then id = db.Insert("xxx", sourceDb, True) fails for some reason, as if there already was a block with that name

 

I also tried to create blocks "xxx" and "XXX" in AutoCAD IDE. I created block "xxx", then tried to create block "XXX" and I got an error: 

A block named "XXX" already exists.
*Invalid*

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 5 of 10 (311 Views)

Re: BlockTable case sensitive keys

07-01-2013 04:23 AM in reply to: matus.brlit

Hi,

 

>>  BlockTable.Has("xxx") returns False

If a Blockdefinition in your drawing exists with the Name "XXX" or "Xxx" or "xxx" ... the BlockTable.Has("xxx") should return true (does it for me). Can you show a full sample (how you get the blocktable) and a test drawing that gives us the option to try this with your code?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
_gile
Posts: 2,071
Registered: ‎04-29-2006
Message 6 of 10 (309 Views)

Re: BlockTable case sensitive keys

07-01-2013 04:32 AM in reply to: matus.brlit

Hi,

 

Try this little sample. It add a new block definition named "block" if not already exists and runs BlockTable.Has() with "block", "Block" and "BLOCK".

 

        <CommandMethod("Test")> _
        Public Sub Test()
            Dim doc As Document = AcApp.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Using trans As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
                If Not bt.Has("block") Then
                    Dim btr As BlockTableRecord = New BlockTableRecord()
                    btr.Name = "block"
                    Dim circ As Circle = New Circle(Point3d.Origin, Vector3d.ZAxis, 10.0)
                    bt.Add(btr)
                    trans.AddNewlyCreatedDBObject(btr, True)
                    btr.AppendEntity(circ)
                    trans.AddNewlyCreatedDBObject(circ, True)
                End If
                trans.Commit()

                ed.WriteMessage(String.Format("{0}Has 'block': {1}", vbLf, bt.Has("block")))
                ed.WriteMessage(String.Format("{0}Has 'Block': {1}", vbLf, bt.Has("Block")))
                ed.WriteMessage(String.Format("{0}Has 'BLOCK': {1}", vbLf, bt.Has("BLOCK")))
            End Using
        End Sub

 

Gilles Chanteau
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 7 of 10 (298 Views)

Re: BlockTable case sensitive keys

07-01-2013 05:10 AM in reply to: matus.brlit

you are right with the case sensitivity, it's not case sensitive, I missed one more difference in the name, one has underscore "_" and the other has dash "-" in the name

 

If I have one of them in the drawing, then my code throws an exception, when trying to insert the other one:

 

Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'E:\AutoCAD Civil 3D 2013\acad.exe'.

Additional Information: The runtime has encountered a fatal error. The address of the error was at 0xf4a4d4cc, on thread 0x1218. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

 

After some more tests, I found out interresting things. The names of the blocks are: 0413_R1_ZVODIDLA_rozpiska and 0413_R1_Zvodidla-rozpiska

I tried to change the second name to 0413_R1_Zvodidla-rozpiska - kópia and 0413-rozpiska; both failed upon insert, then I renamed it to 123456 and I was able to insert it.

 

Here's my code for inserting the block:

 

Using sourceDb As Database = New Database(False, True)
      sourceDb.ReadDwgFile(dwgPath, FileShare.ReadWrite, True, "")
      id = db.Insert(blkName, sourceDb, True)
 End Using

 

 

Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 8 of 10 (243 Views)

Re: BlockTable case sensitive keys

07-02-2013 03:41 AM in reply to: matus.brlit
any idea, what this could be?
ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 9 of 10 (211 Views)

Re: BlockTable case sensitive keys

07-04-2013 09:44 PM in reply to: matus.brlit

Have you tried it in AutoCAD UI without the API ?

 

The crash does not seem to be related to the block name/ drawing name.

Here is the code snippet that I tried with two sample drawings created using AutoCAD 2013 and it worked ok.

 

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (DocumentLock docLock = doc.LockDocument())
{
    string dwgPath1 = @"C:\Temp\0413_R1_Zvodidla-rozpiska.dwg";
    using (Database dbSource = new Database(false, true))
    {
        dbSource.ReadDwgFile(dwgPath1, FileShare.ReadWrite, true, null);
        ObjectId id1 = db.Insert("0413_R1_Zvodidla-rozpiska", dbSource, true);
    }

    string dwgPath2 = @"C:\Temp\0413_R1_Zvodidla_rozpiska.dwg";
    using (Database dbSource = new Database(false, true))
    {
        dbSource.ReadDwgFile(dwgPath2, FileShare.ReadWrite, true, null);
        ObjectId id2 = db.Insert("0413_R1_Zvodidla_rozpiska", dbSource, true);
    }
}

 Can you please share non-confidential drawings and the steps to reproduce the problem ?



Balaji
Developer Technical Services
Autodesk Developer Network

Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 10 of 10 (191 Views)

Re: BlockTable case sensitive keys

07-07-2013 11:01 PM in reply to: Balaji_Ram

Without API it works.

And it's probably not about the name, because I tried again with renamed dwgs and it failed too. I also tried exactly your code, just to see if the document lock would do any difference, it didn't, it fails with your code too.

 

Then I examined the drawing and I found out, that there's a lot of blocks, if purged, it works, so it must be some of them causing this problem.

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