PDA

View Full Version : Object in Paperspace vs Modelspace



matt.worland
2004-07-28, 04:58 PM
Our VBA guy was wondering what are some ways to determine whether an object is in paperspace or modelspace. Any takers?

Thanks
Matt

msretenovic
2004-07-28, 05:28 PM
Matt,

You could get the OwnerID of the object. :idea: Once you have that, iterate through the Blocks collection and try to match the OwnerID you found to an ObjectID. :!: If it is in a block, you may need to call it recursively to get to either Model Space or Paper Space. You can check the Name property to see if it is a block or model/paper space :-) . If it is model space the Name property will return *MODEL_SPACE. If it is in paper space, the Name property will return *PAPER_SPACE .

:wink: HTH

matt.worland
2004-07-28, 05:36 PM
I told him that is how I did it in v-lisp, but he was hoping for an easier way.

Thanks for the re-enforcement, I will let him know.

Matt

RobertB
2004-07-28, 05:58 PM
You could get the OwnerID of the object. :idea: Once you have that, iterate through ...

:shock:

Um, no need to iterate.


Sub Test()
' Test assumes at least one entity in both ModelSpace & Layout1
With ThisDrawing.ModelSpace
Debug.Print GetOwningLayout(.Item(.Count - 1)).Name
End With
With ThisDrawing.Layouts.Item("Layout1").Block
Debug.Print GetOwningLayout(.Item(.Count - 1)).Name
End With
End Sub

Private Function GetOwningLayout(Entity As AcadEntity) As AcadLayout
Set GetOwningLayout = ThisDrawing.ObjectIdToObject(Entity.OwnerID).Layout
End Function

msretenovic
2004-07-28, 06:02 PM
Huh, didn't know about that function. Now I do :D . Thanks Robert!!!

jwanstaett
2004-07-29, 02:38 PM
You could get the OwnerID of the object
Get the object that the ownerId points to; Use ThisDrawing.ObjectIdToObject
Check the OwnerId of this Object IF = 0 then you have the Top Object ;else get the Owner of this Object

when you get the Top Object if it a block and IsLayout = Ture then the Object is in Paper Space else It In Model_Space

use "If TypeOf obj Is AcadBlock Then" to test for block and "If obj.IsLayout then" to test for IsLayout" do not put bouth in the same If Statement if the obj is not a block the IsLayout will error out

IF the Top object is not a block then the object you stated with is not a entity

Change Sorry isLayout will not work need to Check name of obj for *Model_Space


Public Function MSorPs(vObj As AcadObject)
'this function reture MS if object is in MS
' PS if object is in PS
' NA if not a Entity
Dim fnObj As AcadObject
Dim fnOwnerObj As AcadObject
Set fnObj = vObj
Set fnOwnerObj = ThisDrawing.ObjectIdToObject(fnObj.OwnerID)
'get the Top object
While fnOwnerObj.OwnerID <> 0
Set fnObj = fnOwnerObj
Set fnOwnerObj = ThisDrawing.ObjectIdToObject(fnObj.OwnerID)
Wend
'Check if block
If TypeOf fnObj Is AcadBlock Then
'Check if Model Space
If fnObj.Name = "*Model_Space" Then
MSorPs = "MS"
Else
MSorPs = "PS"
End If
Else
MSorPs = "NA"
End If
End Function