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

Help on LINQ query to list all block references in current drawing.

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ProfWolfMan
760 Views, 2 Replies

Help on LINQ query to list all block references in current drawing.

Dear All,

 

Why my LINQ query always returns nothing ?

There is already some block refernces in the current drawing.

 

Please advise me where i am worng?

 

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

        '' Get the current document and database
        Dim acDoc As Object = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Object = HostApplicationServices.WorkingDatabase

        Dim acCurBlkTbl As Object = acCurDb.BlockTableId

        Dim blkrefs = From b In CType(CTypeDynamic(acCurBlkTbl, GetType(IEnumerable(Of Object))),  _
                              IEnumerable(Of Object))
                          Where (b.GetRXClass().Name = "AcDbBlockReference")
                          Select b

        For Each blk As BlockReference In blkrefs
            acDoc.Editor.WriteMessage(vbCrLf + blk.Name + vbCrLf)
        Next

    End Sub

 

FYI : There are many goodways to list all block references. But here i am trying to study Dynamic and LINQ features of .NET.

 

Thanks & Regards,
G
2 REPLIES 2
Message 2 of 3
_gile
in reply to: ProfWolfMan

Hi,

 

The BlockTable contains BlockTableRecordS, not BlockReferenceS.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
ProfWolfMan
in reply to: _gile

Hi Gilles,

 

Thanks for point out the Error.

 

Below is corrected one.

 

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

        '' Get the current document and database
        Dim acDoc As Object = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Object = HostApplicationServices.WorkingDatabase

        Dim acCurSpace = acCurDb.CurrentSpaceId

        Dim blkrefs = From b In CType(CTypeDynamic(acCurSpace, GetType(IEnumerable(Of Object))),  _
                            IEnumerable(Of Object))
                            Where (b.GetRXClass().Name = "AcDbBlockReference")
                            Select b

        For Each blk As Object In blkrefs
            acDoc.Editor.WriteMessage(vbCrLf + blk.Name + vbCrLf)
        Next

    End Sub

 

 

 

Thanks & Regards,
G

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