Author Topic: Mid point of a blockref  (Read 10090 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Mid point of a blockref
« on: April 25, 2008, 10:35:33 AM »
Hi

Let me see if I can explain this;
Does anyone happen to have any code that will find the absolute mid point of a blockref?

For instance, I know a block has an insertion point, obviously but within the block are tons of entities, obviously

I guess this could be done a few ways, that is find the most centered entity within the blockref and get its point or get the most lower left and most upper right points of the lowest left and upper right entities in the block, then find the mid point based off of those points.

Does that make sense?

I could try to work on it later but this code would really benefit  me right now if anyone has something that could get it done.

I'd appreciate it

Thanks
Mark

Bob Wahr

  • Guest
Re: Mid point of a blockref
« Reply #1 on: April 25, 2008, 10:37:30 AM »
Question, are you after the centroid of a shape that tightly conforms to the objects in the block, or the center of the bounding box for the block?

ML

  • Guest
Re: Mid point of a blockref
« Reply #2 on: April 25, 2008, 10:38:04 AM »

Yes! Precisely Bob!

ML

  • Guest
Re: Mid point of a blockref
« Reply #3 on: April 25, 2008, 10:38:44 AM »

I'm sorry,
I guess I would want the midpoint of the centroid

M

Guest

  • Guest
Re: Mid point of a blockref
« Reply #4 on: April 25, 2008, 10:42:24 AM »
Have you looked into .GetBoundingBox??


<EDIT>
I suppose I should read a little bit closer next time.

Question, are you after the centroid of a shape that tightly conforms to the objects in the block, or the center of the bounding box for the block?

ML

  • Guest
Re: Mid point of a blockref
« Reply #5 on: April 25, 2008, 10:47:18 AM »

No Matt
I never used BoundBox

I guess it could be a centroid or bounding box, if the bounding box is what I think it is.

I just need that midpoint.

I am being lazy, I need to insert about 75 blocks into a drawing using the midpoint of the blockref  and I am a bit tired of drawing rectangles.

Unfortunately, I don't have time right now to dive in and try to program it myself.

M

Bob Wahr

  • Guest
Re: Mid point of a blockref
« Reply #6 on: April 25, 2008, 10:55:51 AM »
It makes a pretty large difference in complexity.  If the centroid(~midpoint) of the bounding box, which is a rectangle from the minimum x&y of elements in the block to the maximum x&y, will work, it's fairly simple.  If you need the centroid of the geometry, the easiest way to get a close approximation that I can think of is to place a region for the bounding box of each entity in the block, then find the centroid with massprop.  Sounds to me like the former is what you're after.

ML

  • Guest
Re: Mid point of a blockref
« Reply #7 on: April 25, 2008, 11:11:46 AM »

I see
Thanks Bob

Quote
It makes a pretty large difference in complexity.  If the centroid(~midpoint) of the bounding box, which is a rectangle from the minimum x&y of elements in the block to the maximum x&y, will work, it's fairly simple.

Yes, it is the first method that I would be after.
I like simple :)

M


Bob Wahr

  • Guest
Re: Mid point of a blockref
« Reply #8 on: April 25, 2008, 11:12:47 AM »
as usual, quick, dirty, untested.  Own risk, blahblahblah

Code: [Select]
Option Explicit

Public Sub blkCent()
  Dim minExt As Variant
  Dim maxExt As Variant
  Dim pntCent(0 To 2) As Double
 
    lineObj.GetBoundingBox minExt, maxExt

  Dim strSet As String
  Dim strSetName As String
  Dim intGroup(0) As Integer
  Dim varGroup(0) As Variant
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
  Dim strBlkName As String
  Dim objBlkRef As AcadBlockReference
  Dim objEnt As AcadEntity
  Dim intCnt As Integer
 
  Set objSelSets = ThisDrawing.SelectionSets
  strSetName = 1
  intGroup(0) = 0
  varGroup(0) = "insert"
  KillSet strSetName
  Set objSelSet = objSelSets.Add(strSetName)
  objSelSet.Select acSelectionSetAll, , , intGroup, varGroup
  For Each objEnt In objSelSet
    If TypeOf objEnt Is AcadBlockReference Then
      objBlkRef = objEnt
      objBlkRef.GetBoundingBox minExt, maxExt
      pntCent(0) = (minExt(0) + maxExt(0)) / 2
      pntCent(1) = (minExt(1) + maxExt(1)) / 2
      pntCent(2) = (minExt(2) + maxExt(2)) / 2
    End If
  Next objEnt
End Sub

Function KillSet(strSet As String)
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
 
  Set objSelSets = ThisDrawing.SelectionSets
     
  For Each objSelSet In objSelSets
    If objSelSet.Name = strSet Then
      ThisDrawing.SelectionSets.Item(strSet).Delete
    Exit For
    End If
  Next

End Function


ML

  • Guest
Re: Mid point of a blockref
« Reply #9 on: April 25, 2008, 11:21:10 AM »

Wouldn't have it any other way :)
We can always clean it up later

Well, here goes nothing

Thanks so much Bob

I will let you know if it gets the job done

M


ML

  • Guest
Re: Mid point of a blockref
« Reply #10 on: April 25, 2008, 11:23:56 AM »

Bob

The lineobj variable is not set

Code: [Select]
lineObj.GetBoundingBox minExt, maxExt

I'm not sure what the line is for?

Shoud I declare the variable as an acadline?

Mark

ML

  • Guest
Re: Mid point of a blockref
« Reply #11 on: April 25, 2008, 11:24:24 AM »

Or is the intent blockref.GetBoundingBox   ?

ML

  • Guest
Re: Mid point of a blockref
« Reply #12 on: April 25, 2008, 11:42:28 AM »
Bob

I did not see how the line fit in; it is the blkref.boundingbox that we are after

I am not totally sure how you code is suppose to work.

I have like 50 blocks in this drawing, so I did some quick tweaking so that I can pick the blockref that I want, then I tried to print out the results and still nothing.

Here is my quick, down and dirty attempt

M

Code: [Select]
Option Explicit
Public Sub blkCent()
  Dim minExt As Variant
  Dim maxExt As Variant
  Dim pntCent(0 To 2) As Double
   
  'lineObj.GetBoundingBox minExt, maxExt

  Dim strSet As String
  Dim strSetName As String
  Dim intGroup(0) As Integer
  Dim varGroup(0) As Variant
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
  Dim strBlkName As String
  Dim objBlkRef As AcadBlockReference
  Dim objEnt As AcadEntity
  Dim intCnt As Integer
 
 
  Set objSelSets = ThisDrawing.SelectionSets
  strSetName = 1
  intGroup(0) = 0
  varGroup(0) = "insert"
  KillSet strSetName
  Set objSelSet = objSelSets.Add(strSetName)
  objSelSet.Select acSelectionSetAll, , , intGroup, varGroup
  objSelSet.SelectOnScreen intGroup, varGroup
  For Each objEnt In objSelSet
   'If TypeOf objEnt Is AcadBlockReference Then
    If objEnt.ObjectName = "AcDbBlockreference" Then
      objBlkRef = objEnt
      objBlkRef.GetBoundingBox minExt, maxExt
      pntCent(0) = (minExt(0) + maxExt(0)) / 2
      pntCent(1) = (minExt(1) + maxExt(1)) / 2
      pntCent(2) = (minExt(2) + maxExt(2)) / 2
    End If
     Debug.Print pntCent(0); pntCent(1)
  Next objEnt
End Sub

Bob Wahr

  • Guest
Re: Mid point of a blockref
« Reply #13 on: April 25, 2008, 11:43:22 AM »
yeah, that one.  I snagged the bounding box code from help and pasted it into something else I had so I wouldn't have to do any more typing than absolutely necessary.  Yeah, that's how lazy I am.

ML

  • Guest
Re: Mid point of a blockref
« Reply #14 on: April 25, 2008, 11:45:38 AM »

Hey

We all do it man

Being resource (in my opinion) far outweighs accumulative knowledge.

Why re invent the wheel, right?

Unfortunately this is not going to get me what I beed right now but may be I will look at it later.

Thanks again
Mark