.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BlockTable case sensitive keys

9 REPLIES 9
Reply
Message 1 of 10
matus.brlit
1027 Views, 9 Replies

BlockTable case sensitive keys

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?

9 REPLIES 9
Message 2 of 10

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 10
_gile
in reply to: matus.brlit

Hi,

 

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



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 10


@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*

Message 5 of 10

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 10
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 10
matus.brlit
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

 

 

Message 8 of 10
matus.brlit
in reply to: matus.brlit

any idea, what this could be?
Message 9 of 10
Balaji_Ram
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

Message 10 of 10
matus.brlit
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost