Results 1 to 6 of 6

Thread: Object in Paperspace vs Modelspace

  1. #1
    100 Club matt.worland's Avatar
    Join Date
    2015-12
    Location
    Denver, CO USA
    Posts
    174
    Login to Give a bone
    0

    Question Object in Paperspace vs Modelspace

    Our VBA guy was wondering what are some ways to determine whether an object is in paperspace or modelspace. Any takers?

    Thanks
    Matt

  2. #2
    I could stop if I wanted to msretenovic's Avatar
    Join Date
    2002-02
    Location
    Galloway, Oh
    Posts
    305
    Login to Give a bone
    0

    Default Re: Object in Paperspace vs Modelspace

    Matt,

    You could get the OwnerID of the object. 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 .

    HTH

  3. #3
    100 Club matt.worland's Avatar
    Join Date
    2015-12
    Location
    Denver, CO USA
    Posts
    174
    Login to Give a bone
    0

    Default Re: Object in Paperspace vs Modelspace

    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

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Lightbulb Re: Object in Paperspace vs Modelspace

    Quote Originally Posted by msretenovic
    You could get the OwnerID of the object. Once you have that, iterate through ...


    Um, no need to iterate.

    Code:
    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

  5. #5
    I could stop if I wanted to msretenovic's Avatar
    Join Date
    2002-02
    Location
    Galloway, Oh
    Posts
    305
    Login to Give a bone
    0

    Talking Re: Object in Paperspace vs Modelspace

    Huh, didn't know about that function. Now I do . Thanks Robert!!!

  6. #6
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Object in Paperspace vs Modelspace

    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
    Code:
    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
    Last edited by jwanstaett; 2004-07-29 at 03:35 PM.

Similar Threads

  1. Replies: 2
    Last Post: 2017-08-09, 01:04 PM
  2. Replies: 9
    Last Post: 2007-01-10, 09:28 AM
  3. Replies: 2
    Last Post: 2006-12-27, 10:16 PM
  4. Move Object from Paperspace to Modelspace
    By DONCORINO in forum AutoCAD General
    Replies: 3
    Last Post: 2006-02-15, 06:01 PM
  5. Link a object in Modelspace to a Field in Paperspace
    By Spectrefish in forum AutoCAD Fields
    Replies: 3
    Last Post: 2005-02-04, 10:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •