Modelspace viewport count by activex ...

Discussion in 'AutoCAD' started by michael puckett, Sep 17, 2003.

  1. Has anyone else found the results bogus or unreliable?

    (vla-get-count
    (vla-get-viewports
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    )
    )

    I have a drawing with 4 modelspace vports; *NO* viewports in paperspace (
    aside from paperspace itself ), yet the above code reports 27. I've toggled
    the active space back and forth, re-opened the dwg. Done an audit / recover
    etc. No change.

    Other drawings correctly report the modelspace vport count.

    Is it a flaky method or am I misinterpreting the results / failing to
    understand the vla-get-viewports method ( collection of all <modelspace>
    viewports in the drawing )?

    PS: I initially encountered the problem using objectdbx, ie:

    (vla-get-count
    (vla-get-viewports DBXDOC)
    )

    but the same values ( one would hope ) are realized opening the dwg in the
    editor and using

    (vla-get-count
    (vla-get-viewports
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    )
    )

    Thanks for any enlightening thoughts fellow lithpers.

    Michael.
     
    michael puckett, Sep 17, 2003
    #1
  2. michael puckett

    Rudy Tovar Guest

    Just so you know, I'm not trying to be funny, but doesn't seem everything is
    running as smooth as it should.

    They (Autodesk) wrote a disclaimer regarding the functions they found to be
    flawed, leaving us the rest to find.
     
    Rudy Tovar, Sep 17, 2003
    #2
  3. didn't test for long but here's what i noticed:

    tilemode 1, vports from 1 to 4 - function returns 1 (last state)
    tm 0 - function returns 4

    so the function only returns the correct count when switching tilemode
    (vanilla 2004 e-international)

    same with saved viewport configurations.
    tilemode 1 - vports saved & changed
    after switching tilemode correct count of sum of all viewports (active
    plus saved)

    and: reliable so far (10 minutes ;-).

    btw has nothing to do with LAYOUTREGENCTL
     
    ruul morawetz, Sep 17, 2003
    #3
  4. As much as I might enjoy jumping on the "bash Autodesk" wagon, it appears that
    the dwg does have 27 vport objects:

    I ran this:

    (vlax-for viewport
    (vla-get-viewports
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    )
    (print
    (vl-remove-if 'null
    (mapcar
    '(lambda (x) (if (member (car x) '(-1 0 5)) x))
    (entget (vlax-vla-object->ename viewport))
    )
    )
    )
    )

    and this was the result:

    ((-1 . <Entity name: 4091ef10>) (0 . "VPORT") (5 . "A1E2"))
    ((-1 . <Entity name: 4091ef18>) (0 . "VPORT") (5 . "A1E3"))
    ((-1 . <Entity name: 4091ef20>) (0 . "VPORT") (5 . "A1E4"))
    ((-1 . <Entity name: 4091ef28>) (0 . "VPORT") (5 . "A1E5"))
    ((-1 . <Entity name: 4091ef30>) (0 . "VPORT") (5 . "A1E6"))
    ((-1 . <Entity name: 4091ef38>) (0 . "VPORT") (5 . "A1E7"))
    ((-1 . <Entity name: 4091ef40>) (0 . "VPORT") (5 . "A1E8"))
    ((-1 . <Entity name: 4091ef48>) (0 . "VPORT") (5 . "A1E9"))
    ((-1 . <Entity name: 4091ef50>) (0 . "VPORT") (5 . "A1EA"))
    ((-1 . <Entity name: 4091ef58>) (0 . "VPORT") (5 . "A1EB"))
    ((-1 . <Entity name: 4091ef60>) (0 . "VPORT") (5 . "A1EC"))
    ((-1 . <Entity name: 4091ef68>) (0 . "VPORT") (5 . "A1ED"))
    ((-1 . <Entity name: 4091ef70>) (0 . "VPORT") (5 . "A1EE"))
    ((-1 . <Entity name: 4091ef78>) (0 . "VPORT") (5 . "A1EF"))
    ((-1 . <Entity name: 4091ef80>) (0 . "VPORT") (5 . "A1F0"))
    ((-1 . <Entity name: 4091ef88>) (0 . "VPORT") (5 . "A1F1"))
    ((-1 . <Entity name: 4091ef90>) (0 . "VPORT") (5 . "A1F2"))
    ((-1 . <Entity name: 4091ef98>) (0 . "VPORT") (5 . "A1F3"))
    ((-1 . <Entity name: 4091efa0>) (0 . "VPORT") (5 . "A1F4"))
    ((-1 . <Entity name: 4091efa8>) (0 . "VPORT") (5 . "A1F5"))
    ((-1 . <Entity name: 4091efb0>) (0 . "VPORT") (5 . "A1F6"))
    ((-1 . <Entity name: 4091efb8>) (0 . "VPORT") (5 . "A1F7"))
    ((-1 . <Entity name: 4091f000>) (0 . "VPORT") (5 . "A1F8"))
    ((-1 . <Entity name: 40926ef0>) (0 . "VPORT") (5 . "BA6E"))
    ((-1 . <Entity name: 40926ef8>) (0 . "VPORT") (5 . "BA6F"))
    ((-1 . <Entity name: 40926f00>) (0 . "VPORT") (5 . "BA70"))
    ((-1 . <Entity name: 40926f08>) (0 . "VPORT") (5 . "BA71"))

    Why there are 27 in the dwg when modelspace only sports 4 (and none in
    paperspace) is a mystery at this point. Residual artifacts from earlier vport
    command sequences?

    Hmmmm ...

    So what's new, yeah that's not the only screwy function.

    Seems to be something missing...not your code.

    < snippage >
     
    michael puckett, Sep 17, 2003
    #4
  5. Thanks Luis, but I'm writing an auditing program for our company using
    objectdbx :)

    "Luis Esquivel" <www.draftteam.com> wrote in message
    why not use: (vports)
     
    michael puckett, Sep 17, 2003
    #5
  6. michael puckett

    Rudy Tovar Guest

    So what you're saying is that there's 23 hidden vports or stored?
     
    Rudy Tovar, Sep 17, 2003
    #6
  7. michael puckett

    Doug Broad Guest

    Michael,
    Do you want the number of paperspace viewports? If so then
    you don't want vla-get-viewports. Viewports are objects that
    contain the view settings of vports in model space. Each saved
    viewport configuration has a number of viewports associated with
    it. The active viewport configuration also (I think) has a copy
    of the viewports that have been saved. There is also a relationship
    between layouts and model space viewports but I don't know
    the specifics.
    Does that help?
     
    Doug Broad, Sep 17, 2003
    #7
  8. Hi Doug,

    What I'm trying to do is get the modelspace vport count.

    But - your info helped. Lots. Said drawing has 12 named viewports in
    modelspace ( including the *Active* Viewport, which sports 4 ).

    Between all of the named viewports there are precisely 27 possible vports.

    THANKS :)

    ( and thanks to Luis and Rudy who prompted me to think of other things too ).

    Michael,
    Do you want the number of paperspace viewports? If so then
    you don't want vla-get-viewports. Viewports are objects that
    contain the view settings of vports in model space. Each saved
    viewport configuration has a number of viewports associated with
    it. The active viewport configuration also (I think) has a copy
    of the viewports that have been saved. There is also a relationship
    between layouts and model space viewports but I don't know
    the specifics.
    Does that help?
     
    michael puckett, Sep 17, 2003
    #8
  9. Oops, Ruul too :)


    < snip >

    ( and thanks to Luis and Rudy who prompted me to think of other things too ).

    < snip >
     
    michael puckett, Sep 17, 2003
    #9
  10. B y o b j e c t d b x .

    But thanks :)

    "Luis Esquivel" <www.draftteam.com> wrote in message
    Michael,

    return the number of viewports in model:

    (setvar "tilemode" 1)
    (length (vports))
     
    michael puckett, Sep 17, 2003
    #10
  11. No worries mang! Appreciate you dropping by my thread; cheers :)

    "Luis Esquivel" <www.draftteam.com> wrote in message

    Sorry SIR I did not read your previous... it won't happen again... I
    promised!... cross my heart! ;-)
     
    michael puckett, Sep 17, 2003
    #11
  12. michael puckett

    Doug Broad Guest

    Glad to help.
    Look at the object model for more "good" info and you might
    find this revealing:

    (vlax-map-collection
    (vla-get-viewports
    (vla-get-activedocument
    (vlax-get-acad-object)))
    'vlax-dump-object)
     
    Doug Broad, Sep 17, 2003
    #12
  13. While this may not be pretty it works ...

    (setq Count 0)
    (vlax-for vport (vla-get-viewports OBJDBX)
    (if (eq "*ACTIVE" (strcase (vla-get-name vport)))
    (setq Count (1+ Count))
    )
    )

    I use 'vlax-dump-object quite extensively, it is most useful. Between it, the
    object model map and my little atoms.vlx app there are not too many secrets :)

    Thanks again Doug.

    Glad to help.
    Look at the object model for more "good" info and you might
    find this revealing:

    (vlax-map-collection
    (vla-get-viewports
    (vla-get-activedocument
    (vlax-get-acad-object)))
    'vlax-dump-object)
     
    michael puckett, Sep 17, 2003
    #13
  14. michael puckett

    Doug Broad Guest

    That seems the best technique. The current configuration is a
    viewport and if split into other viewports, each viewport has
    the same name, "*ACTIVE"....

    You're welcome.
     
    Doug Broad, Sep 17, 2003
    #14
  15. michael puckett

    Mark Propst Guest

    saved for undo?
     
    Mark Propst, Sep 17, 2003
    #15
  16. Something else: via DBX this won't be an issue I assume, but when using
    either of your approaches in an open drawing how do you guarantee that
    you really get the current state from AutoCAD?

    the 1st function [using (vla-get-count ...] and also the 2nd one
    [stepping through viewport collection] return a wrong result (1st: wrong
    number, 2nd: nil) when VPORTS is used in MS to save/delete/change the
    current configuration.
    Toggling of TILEMODE to refresh and get the correct number was necessary
    for me.

    (vports) returns different lists, too. all data present but the
    numbering is different.
    (3 .. 4 .. 2 .. 5 ..) versus (2 .. 3 .. 4 .. 5 ..)

    I haven't noticed that behaviour before....
    and: as my old'n'rusty (vports) using functions still work, I don't
    worry too much. ;-)
     
    ruul morawetz, Sep 18, 2003
    #16
  17. I cannot think of any advantage using activex over vanilla in the case of
    determining the number of vports in modelspace *IF* the dwg is open in the
    AutoCAD editor. I would use (length (vports)) < in the proper space of course
    I have found that in order to get reliable vport count results using activex
    in the AutoCAD editor < on the active document > you must toggle tilemode
    prior to the count < regen, regenall is not enough to force the database to
    update >.

    Finally, this ...

    (defun OBJDBX-GetVportCount ( DBXDOC / count )
    ; DBXDOC must be a valid ObjectDBX,
    ; object and a valid doc must be opened
    ; prior to this function call. No error
    ; checking is employed in this function
    ; in the interests of performance
    (setq count 0)
    (vlax-for vport (vla-get-viewports DBXDOC)
    (if (eq "*ACTIVE" (strcase (vla-get-name vport)))
    (setq count(1+ count))
    )
    )
    count
    )

    Has proven reliable for objectdbx queries so far < 1 day of use >.

    Cheers.

    Something else: via DBX this won't be an issue I assume, but when using
    either of your approaches in an open drawing how do you guarantee that
    you really get the current state from AutoCAD?

    the 1st function [using (vla-get-count ...] and also the 2nd one
    [stepping through viewport collection] return a wrong result (1st: wrong
    number, 2nd: nil) when VPORTS is used in MS to save/delete/change the
    current configuration.
    Toggling of TILEMODE to refresh and get the correct number was necessary
    for me.

    (vports) returns different lists, too. all data present but the
    numbering is different.
    (3 .. 4 .. 2 .. 5 ..) versus (2 .. 3 .. 4 .. 5 ..)

    I haven't noticed that behaviour before....
    and: as my old'n'rusty (vports) using functions still work, I don't
    worry too much. ;-)
     
    michael puckett, Sep 18, 2003
    #17
  18. I like dbview.arx too but I don't think it works in 2004.
     
    Eric Schneider, Sep 19, 2003
    #18
  19. michael puckett

    Luis Guest

    Eric,

    I think you can email Shaan Hurley and ask him for the A2004 version.
     
    Luis, Sep 19, 2003
    #19
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.