Author Topic: Finding and replacing Blocks in specific Space  (Read 4137 times)

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
Finding and replacing Blocks in specific Space
« on: June 01, 2006, 06:07:18 PM »
Is there a way to find if a block is in model or paper space?  I have dwgs that have a certain block mostly in layouts.  I simply do a loop based on the # of blocks found..
For x = 0 to tempset.count -1
When each block is found it records the data for inserting a new one (ie. insertpt, scale, rotation, etc)
The problem is sometimes it finds a block in Mspace and inserts into Pspace or viceversa.

Does this make sense? 
Any ideas?

Thanks in advance...

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Finding and replacing Blocks in specific Space
« Reply #1 on: June 01, 2006, 06:16:15 PM »
I looked at the properties of a block inserted in PS and MS, and couldn't see an active space (for lack of better word) property
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Finding and replacing Blocks in specific Space
« Reply #2 on: June 01, 2006, 06:27:35 PM »
Function IsPs(oBref As AcadBlockReference) As Boolean
    Dim oblock As AcadBlock
    Set oblock = ThisDrawing.ObjectIdToObject(oBref.OwnerID)
    If Not oblock.Name = "*Model_Space" Then
        IsPs = True
    End If
End Function

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Finding and replacing Blocks in specific Space
« Reply #3 on: June 01, 2006, 06:33:36 PM »
Hint....the OWNER of an Entity is the Block of the Layout it resides in.....

Shoot, Bryco beat me to it.....but he doesn't address WHICH PS layout it's in..... :-)

Bob Wahr

  • Guest
Re: Finding and replacing Blocks in specific Space
« Reply #4 on: June 01, 2006, 06:55:20 PM »
they both beat me to it.  Work jumped up in the middle of me testing it.  Like Bryco, I didn't address which layout but what I had was

If objBlkRef.OwnerID = ThisDrawing.modelSpace.ObjectID Then
  'It's modelspace
Else
  'It's not
End if

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Finding and replacing Blocks in specific Space
« Reply #5 on: June 01, 2006, 08:10:36 PM »
I think this is better, alot faster.

Code: [Select]
Private  lngMs As Long  'Put this in the declarations area

Function IsMsBlockref(lngOwner As Long) As Boolean
    If lngMs = 0 Then
        lngMs = ThisDrawing.ModelSpace.ObjectID
    End If
    If lngOwner = lngMs Then IsMsBlockref = True
End Function


Sub TestisModelSpace()
    Dim SS As AcadSelectionSet
    Dim i As Integer
    Set SS = sset(0, "insert")
    For i = 0 To SS.Count - 1
        Debug.Print IsMsBlockref(SS(i).OwnerID), i, SS(i).Name
    Next
End Sub

Edited as Bob's use of modelspace was better than  a string search
« Last Edit: June 01, 2006, 08:23:44 PM by Bryco »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Finding and replacing Blocks in specific Space
« Reply #6 on: June 01, 2006, 08:14:27 PM »
Oh Baby call me Jerimiah, just noticed I'm over 200 posts.
Pretends to be Grid iron bloke, throws ball on ground and does a "Ministry of funny walks" walk.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Finding and replacing Blocks in specific Space
« Reply #7 on: June 01, 2006, 08:20:19 PM »
This is how I go about replacing objects, oBlkRef is the block to be replaced:
Code: [Select]
Set oSpace = ThisDrawing.ObjectIdToObject(oBlkRef.OwnerID)
Set oNewBlk = oSpace.InsertBlock(insPt, Name, yada yada......)
'adjust properties to match original, or use them in the insertion code
Now I need not know anything else about the space I'm in.

Bob Wahr

  • Guest
Re: Finding and replacing Blocks in specific Space
« Reply #8 on: June 02, 2006, 10:49:38 AM »
Nice Jeff.

Maverick®

  • Seagull
  • Posts: 14778
Re: Finding and replacing Blocks in specific Space
« Reply #9 on: June 02, 2006, 11:29:43 AM »
.......does a "Ministry of funny walks" walk.

  Theres a Ministry of funny walks?

Bob Wahr

  • Guest

Maverick®

  • Seagull
  • Posts: 14778
Re: Finding and replacing Blocks in specific Space
« Reply #11 on: June 02, 2006, 11:41:10 AM »
  Doh!  I should have remembered that.  :-D

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Finding and replacing Blocks in specific Space
« Reply #12 on: June 03, 2006, 12:18:23 AM »
Bob to the rescue, man that was good to watch again. A+ or is that c++