Author Topic: how to get all data in a block?  (Read 2567 times)

0 Members and 1 Guest are viewing this topic.

rainier

  • Guest
how to get all data in a block?
« on: October 04, 2007, 09:41:36 PM »
how to get all data in a block without exploding a block..? in VBA?  :-(

especially attributes...  please help me..thanks!!  :angel:

rainier

  • Guest
Re: how to get all data in a block?
« Reply #1 on: October 05, 2007, 04:29:05 AM »
is there anyone can help me in getting the data...?? hope some can help me..thanks.. :-(

Chuck Gabriel

  • Guest
Re: how to get all data in a block?
« Reply #2 on: October 05, 2007, 07:35:25 AM »
Look at the GetAttributes method of the BlockRef object.  As for the rest of the data, you have to go back to the block definition and then apply whatever transformations have been done to the individual blockref you are looking at.

rainier

  • Guest
Re: how to get all data in a block?
« Reply #3 on: October 08, 2007, 08:40:34 PM »
how about the entities inside the block... how can i get the data...?? if i have circles or rectangles..etc. inside a block..

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get all data in a block?
« Reply #4 on: October 08, 2007, 08:53:48 PM »
If I say iterate the Block Items, will that help ?

A Block is simply a collection of Objects
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Bryco

  • Water Moccasin
  • Posts: 1864
Re: how to get all data in a block?
« Reply #5 on: October 08, 2007, 08:57:29 PM »
A better description of what you want to do with the info would help.
Many learners take a while to see the differenece between a block and a blockattribute.
It's a very simple matter to extract info on the entities within a block but quite complicated to mess with the transformations that Chuck mentioned.

rainier

  • Guest
Re: how to get all data in a block?
« Reply #6 on: October 08, 2007, 09:32:49 PM »
in attributes i have no problem on it but in the objects inside a block... i cant get the information what i want.. indeed its a mess..but any other ways in getting it..in a nice way  :-)

i just need the object inside a block...  :-(

rainier

  • Guest
Re: how to get all data in a block?
« Reply #7 on: October 08, 2007, 09:38:03 PM »
kerry,
how to get all of it..if its block reference... there is no item found but in acadblock it have an items...   :-(

If I say iterate the Block Items, will that help ?

A Block is simply a collection of Objects

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get all data in a block?
« Reply #8 on: October 08, 2007, 10:09:00 PM »

I don't do VBA, but have you tried something like ..

Code: [Select]
Dim theBlock As AcadBlock
Set theBlock = ThisDrawing.Blocks.Item("WhateverBlock")

Dim aEntity As AcadEntity
For Each aEntity In theBlock
  ' do stuff here
Next aEntity

Try that and step through the code with the Locals window open .. watch the aEntity variable properties
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

rainier

  • Guest
Re: how to get all data in a block?
« Reply #9 on: October 09, 2007, 03:41:22 AM »
kerry,
if i have multiple blocks in my drawings how can i get a specific block that i want???
sample block "DETAILS" <-- i have 100 items in my drawings...

the main reason why i need the information inside a block because i need to know inside a block, circle or rectangle location in a block not the bounding box of the block..its confusing... :|

Or how do i know if the block intersect in a line or polyline in my drawings....




I don't do VBA, but have you tried something like ..

Code: [Select]
Dim theBlock As AcadBlock
Set theBlock = ThisDrawing.Blocks.Item("WhateverBlock")

Dim aEntity As AcadEntity
For Each aEntity In theBlock
  ' do stuff here
Next aEntity

Try that and step through the code with the Locals window open .. watch the aEntity variable properties

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get all data in a block?
« Reply #10 on: October 09, 2007, 05:39:43 AM »
rainier
I'll leave you in the good hands of the VB'ers amongst us  ...
but it may be helpfull if you post the block you've using
and post some of the code you've tried so far.

Are you trying for a fully programmatic solution ?
What are the rules for each block ?

Do you know how to select a block insertion in VBA ?
Do you know how to retrieve a block definition from the Blocks Table/Collection ?
Do you know how to iterate through a collection ?
Do you know how to retrieve the X,X,Z scale from a block ?
Do you know how to do matrix translations ?
Do you know how to do vector multiplication and addition ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

rainier

  • Guest
Re: how to get all data in a block?
« Reply #11 on: October 09, 2007, 08:23:45 PM »
kerry,

thanks for the questions and responses that u gave to me... it helps me to get some idea to our questions..

and lastly on the second question that u give to me like,
"Do you know how to retrieve a block definition from the Blocks Table/Collection ?"

how to retrieve a block definition from the Blocks Table/Collection?? any idea??

thanks again..  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get all data in a block?
« Reply #12 on: October 09, 2007, 08:27:18 PM »
............
and lastly on the second question that u give to me like,
"Do you know how to retrieve a block definition from the Blocks Table/Collection ?"

how to retrieve a block definition from the Blocks Table/Collection?? any idea??

How about something similar to ;
Code: [Select]
Dim theBlock As AcadBlock
Set theBlock = ThisDrawing.Blocks.Item("WhateverBlockNameYouWant")
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Bryco

  • Water Moccasin
  • Posts: 1864
Re: how to get all data in a block?
« Reply #13 on: October 10, 2007, 01:32:07 AM »
To add a little.
Code: [Select]
Private Sub FindTheBlock()

    Dim oBref As AcadBlockReference
    Dim B As AcadBlock
    Dim Pt As Variant
    Dim C As AcadCircle
    Dim X As Double
    Dim Ent As AcadEntity

    'get the BlockReference
    ThisDrawing.Utility.GetEntity oBref, Pt, "Pick a block reference:"
'Use the BlockReference's name to find the block definition
    Set B = ThisDrawing.Blocks(oBref.Name)
'Cycle through the entities in the block
    For Each Ent In B
        If TypeOf Ent Is AcadCircle Then
'Store the circle in an object variable
            Set C = Ent
            Exit For
        End If
    Next Ent
     
    Dim L As AcadLine
    ThisDrawing.Utility.GetEntity L, Pt, "Pick a line:"
    L.Move oBref.InsertionPoint, B.Origin
    Pt = L.EndPoint
    'circle formula x^2+y^2=radius^2
    X = Sqr(C.radius ^ 2 - Pt(1) ^ 2)
    If Pt(0) < 0 Then X = -X
    Debug.Print Pt(0), X
    If Abs(Pt(0) - X) < 0.00000001 Then
        MsgBox "The line ends on the circle."
    End If
    L.Move B.Origin, oBref.InsertionPoint
   
End Sub


Now if the BlockReference you pick has a rotation of zero and a normal value of (0,0,1)
then the circle's center in the  BlockReference will be the same distance and direction from BlockReference InsertionPoint as the blocks circles center is from the block's origin.

rainier

  • Guest
Re: how to get all data in a block?
« Reply #14 on: October 10, 2007, 02:25:08 AM »
thanks Bryco and Kerry...  :angel:

it helps alot..