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

The number of levels for nested blocks in .Net

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
454 Views, 5 Replies

The number of levels for nested blocks in .Net

Dear Friends,


Can any one help me ,how to count the number of levels for nested blocks?

For Example

Block 1 -> Block2 and Block3 (nested Blocks)

So Block 1 number of Level is one.

But

Block 4 - >Block 5 and Block6(nested Blocks)

Block 7 ->Block 1 and Block4

So how get the number of Levels for Block 7 in .net?
Pls give some idea or samples friends....?

Very Urgent..............................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Thank u Friends.
5 REPLIES 5
Message 2 of 6
deepa
in reply to: Anonymous

How to get the number of Levels for nested drawing Blocks in VB.net?
Message 3 of 6
Anonymous
in reply to: Anonymous

you would iterate through the block object looking for other blocks.
Keep following that trail til you exhaust the blocks, and the trail that went the furthest is the winner.
Do not assume there will only be one block within a given block.

I'm wondering how this is so urgent when its fairly obvious to anyone doing .net api stuff. Block tables are the first
thing you learn. You have to deal with them to draw anything. It sounds like you have more to learn than just block
table objects.

It will take a few hours to develop the code on your end so I hope you have at least that, and are good at writing and
testing .net code in acad.

raji <>
|>Dear Friends,
|>
|>
|>Can any one help me ,how to count the number of levels for nested blocks?
|>
|>For Example
|>
|>Block 1 -> Block2 and Block3 (nested Blocks)
|>
|>So Block 1 number of Level is one.
|>
|>But
|>
|>Block 4 - >Block 5 and Block6(nested Blocks)
|>
|>Block 7 ->Block 1 and Block4
|>
|>So how get the number of Levels for Block 7 in .net?
|>Pls give some idea or samples friends....?
|>
|>Very Urgent..............................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|>
|>
|>Thank u Friends.
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 4 of 6
deepa
in reply to: Anonymous

Dear James,

First,Thanks for your reply.

yes.you are correct i would iterate through the block object.
Below is my coding.But I dont know how to iterate .pls can you give detailed idea.Iteration is OK.but i am not clear.pls show me my
coding and help me.

Public Function Blocks(ByVal sBlockName As String)

Try
Try
btr = CType(trans.GetObject(bl.Item(sBlockName), OpenMode.ForRead), BlockTableRecord)
Catch ex As Exception
trans.Dispose()
Return False
Exit Function
End Try

For Each id As ObjectId In btr
ids.Add(id)
Try
Dim Ent As Entity = trans.GetObject(id, OpenMode.ForRead)

BLayer = Ent.Layer.ToString
If BLayer = "0" Then
Else
Layercount += 1
msgbox(LayerCount)
End If

' Here is my doubt the below commandline codes count's only the
blocks but i need the number of levels.

' If TypeOf Ent Is BlockReference Then
' BlkRef = Ent
' NestedCount += 1
' End If

Catch ex As Exception
trans.Dispose()
Return False
Exit Function
End Try
Next

' If NestedCount > 0 Then
' nooflevel += 1
' End If


ids.Clear()

Catch

trans.Dispose()
Return False
Exit Function

End Try

End Function
Message 5 of 6
Anonymous
in reply to: Anonymous

james ,

I think deepa coding is correct .pls give me the suggesion for iterate itereate through all drawing blocks.
Message 6 of 6
Anonymous
in reply to: Anonymous

you need to write a function to take a block name, and return an integer of the number of blocks below it.
Then run that recursively on any block you find and recored the deepest level.
So that's the concept, it would take me a while to write the code since recursive stuff is tricky.
I'll see if I can put something together as I know I've seen code to look through blocks like this.

James Maeding
|>you would iterate through the block object looking for other blocks.
|>Keep following that trail til you exhaust the blocks, and the trail that went the furthest is the winner.
|>Do not assume there will only be one block within a given block.
|>
|>I'm wondering how this is so urgent when its fairly obvious to anyone doing .net api stuff. Block tables are the first
|>thing you learn. You have to deal with them to draw anything. It sounds like you have more to learn than just block
|>table objects.
|>
|>It will take a few hours to develop the code on your end so I hope you have at least that, and are good at writing and
|>testing .net code in acad.
|>
|>raji <>
|>|>Dear Friends,
|>|>
|>|>
|>|>Can any one help me ,how to count the number of levels for nested blocks?
|>|>
|>|>For Example
|>|>
|>|>Block 1 -> Block2 and Block3 (nested Blocks)
|>|>
|>|>So Block 1 number of Level is one.
|>|>
|>|>But
|>|>
|>|>Block 4 - >Block 5 and Block6(nested Blocks)
|>|>
|>|>Block 7 ->Block 1 and Block4
|>|>
|>|>So how get the number of Levels for Block 7 in .net?
|>|>Pls give some idea or samples friends....?
|>|>
|>|>Very Urgent..............................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|>|>
|>|>
|>|>Thank u Friends.
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - at - hunsaker - dotcom
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom

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