.NET

Reply
Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 1 of 13 (210 Views)

Block Reference question.

210 Views, 12 Replies
06-14-2012 06:01 AM

1. first I have a drawing called "test1"

2. and a drawing call "Dwg1" Inside this drawing is a block called "Block1"

3. now after I insert Drawing "Dwg1" into drawing "test1" I explode it then I save and close the drawing test1.

4. now I run this code on drawing Test1 and it gives me a block count of 2 for block "Block1"
   but there is only one block Reference in the drawing called "Block1"
   yes I know when I inserted the Drawing "dwg1" is comes in as a block called "dwg1" and inside that Block is a   block called "block1"

   now my code count the block1 that is inside the drawing/block called "dwg1 Even though i exploded the drawing/block "dwg1"

 

   my question is Even though i exploded the Drawing/block "dwg1" why does "block1" that was inside Drawing/block "dwg1" show up as a Block Reference?
   and how do i work around this so i only get the Block Reference that is really in the drawing.

 

Public Sub DwgTest(ByVal pathtodwg As String, ByVal blockname As String)

        Dim db As Database = New Database(False, False)

        If IO.File.Exists(pathtodwg) = True Then
            db.ReadDwgFile(pathtodwg, System.IO.FileShare.Read, False, Nothing)

            Using Trans As Transaction = db.TransactionManager.StartTransaction
                Dim bktbl As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)

                Dim revblk As BlockTableRecord = bktbl(blockname).GetObject(OpenMode.ForRead)
                Dim refs As ObjectIdCollection = revblk.GetBlockReferenceIds(False, False)
                MsgBox(refs.Count.ToString)
            End Using

            db.Dispose()
        End If

    End Sub

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,892
Registered: ‎06-29-2007
Message 2 of 13 (207 Views)

Re: Block Reference question.

06-14-2012 06:10 AM in reply to: wowens63

Hi,

 

>> now after I insert Drawing "Dwg1" into drawing "test1" I explode it then I save and close the drawing test1.

If you insert DWG1 in TEST1 and you explode it then ==> you have exploded the block called DWG1, but as the block BLOCK1 was a subobject it is not exploded with it's parent one, so after your step 3 there is one blockreference called BLOCK1 in modelspace.

If you redo the same, you will have 2 blockreferences then.

 

You can simulate this by hand, insert DWG1 into a new drawing, explode it, you'll see that BLOCK1 is now available in modelspace.

 

Does that clear up you situation?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 3 of 13 (206 Views)

Re: Block Reference question.

06-14-2012 06:24 AM in reply to: Alfred.NESWADBA

I understand the when I explode Dwg1 it leaves Block1 in model space but the code shows that there are 2

Block References for block Block1 thats the part i do not understand. when i check the 

Block Reference (bref.BlockName one will = Block1 and the other will = *Model_Space) so why does is show a

bref.BlockName to Block1 after block1 was exploded.

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 4 of 13 (207 Views)

Re: Block Reference question.

06-14-2012 06:26 AM in reply to: wowens63

mistyped try this again.

I understand the when I explode Dwg1 it leaves Block1 in model space but the code shows that there are 2

Block References for block Block1 thats the part i do not understand. when i check the 

Block Reference (bref.BlockName one will = dwg1 and the other will = *Model_Space) so why does is show a

bref.BlockName to Block1 after block1 was exploded.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,892
Registered: ‎06-29-2007
Message 5 of 13 (198 Views)

Re: Block Reference question.

06-14-2012 06:40 AM in reply to: wowens63

Hi,

 

>> but the code shows that there are 2Block References for block Block1 thats the part i do not understand

When you open the drawing and select the content of the modelspace with QSELECT, how many BlockReferences do you see then? Because I don't see a problem with your code and counting.

 

>> so why does is show a bref.BlockName to Block1 after block1 was exploded.

I didn't see in your description (points 1 to 4) and position where you explode the BlockReference called "BLOCK1" in the modelspace of the new drawing?

You just exploded to parent DWG1.

 

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
norman.yuan
Posts: 965
Registered: ‎04-27-2009
Message 6 of 13 (197 Views)

Re: Block Reference question.

06-14-2012 06:42 AM in reply to: wowens63

What you might want to look into is BlockReference.Name, not BlockReference.BlockName.

 

The former is the name of a BlockTableRecord (block definition) the BlockReference is based on, while the later is the name of the BlockReference' owner (usually, it is the ModelSpace block or PaperSpace block).

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 7 of 13 (190 Views)

Re: Block Reference question.

06-14-2012 06:52 AM in reply to: wowens63

Hi alfred

if i open the drawing and do qselect there is only one item in model_space if i try erase all there is only one item found in model_space but my code shows 2 Block References for Block1..if i purge the drawing then my code shows only one Block References for Block1

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 8 of 13 (188 Views)

Re: Block Reference question.

06-14-2012 06:55 AM in reply to: norman.yuan

Hi Norman.

yes i know that,  i was using BlockReference.BlockName only to see what was going on

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 9 of 13 (186 Views)

Re: Block Reference question.

06-14-2012 06:59 AM in reply to: Alfred.NESWADBA

HI alfred

I never explode Block1 I only explode block Dwg1

Valued Contributor
wowens63
Posts: 98
Registered: ‎06-22-2007
Message 10 of 13 (183 Views)

Re: Block Reference question.

06-14-2012 07:03 AM in reply to: wowens63

here is the code and the drawing mybe you can tell me why my code gives me a count of 2 for block DBDSTXT

 

Call DwgTest("C:\test.dwg", "DBDSTXT")

    Public Sub DwgTest(ByVal pathtodwg As String, ByVal blockname As String)

        Dim db As Database = New Database(False, False)

        If IO.File.Exists(pathtodwg) = True Then
            db.ReadDwgFile(pathtodwg, System.IO.FileShare.Read, False, Nothing)

            Using Trans As Transaction = db.TransactionManager.StartTransaction
                Dim bktbl As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)

                Dim revblk As BlockTableRecord = bktbl(blockname).GetObject(OpenMode.ForRead)
                Dim refs As ObjectIdCollection = revblk.GetBlockReferenceIds(False, False)
                MsgBox(refs.Count.ToString)
            End Using

            db.Dispose()
        End If

    End Sub

 

 

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