Author Topic: Finding list of tabs ...  (Read 5465 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Finding list of tabs ...
« on: January 08, 2007, 06:37:54 PM »
Hey ever-body,
I'm on my way out the door at the moment, so I'll catch your comments tomorrow but I want to leave a question for you all.

I've searched the swamp for most of the day and have found a lot of info I'm looking for in regards to layout tabs.

I am wondering however, how I can get a list of the current layout tabs and then automatically select the one I need.

We set our drawings up with the first & second tabs pertaining to the drawings.  Any other tabs we may have in the drawing would be Addendums to the plans & details.
When working on our drawings in Model space, and we switch to Paper space, many times it goes to the last layout tab used, and many times that tab is an Addendum tab.
Also, when we send our drawings out to others, we usually clean them up and package them nicely for others to use.
I am looking for a way to automate this tedious, mundane task.

So if we have the plan tabs labeled S-01 or S-1 or S-1.1A & S-1.1B and the rest are labeled Add-1, Add-2, SCS-02, PR-07, etc., I want to, when going from model space to paper space, have a lisp routine diagnose all the tabs and automatically put S-01 or S-1.1A as the current tab.

I think I have most of the info I need to put the code together, but I don't know how to find the list of all the tabs and then filter them to get the one I want.  Can you help me ??

I do appreciate your help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8718
  • AKA Daniel
Re: Finding list of tabs ...
« Reply #1 on: January 08, 2007, 06:51:09 PM »
you mean like (layoutlist) ?
Dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #2 on: January 08, 2007, 07:09:34 PM »
Sort a list of tabs
http://www.theswamp.org/index.php?topic=5939.0

Tab Mover Lisp
http://www.theswamp.org/index.php?topic=6511.0
This one uses a special sort, see the thread.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #3 on: January 08, 2007, 07:33:25 PM »
On a side note:  Does anyone know how to get which paper space tab it will switch to?  I don't really have a need, but was trying some stuff out for this thread, and ran into an error when trying to find it out with ActiveX.  I was trying to get the Paper space block for the active document, which works some times, and then check it against what values are associated with the tabs, ie the block names of the tabs.  Here is a partial dump of the active document object to show the error.
Quote
;   ModelSpace (RO) = #<VLA-OBJECT IAcadModelSpace3 1bcac2b4>
;   MSpace = AutoCAD: Invalid mode
;   Name (RO) = "Drawing1.dwg"
;   ObjectSnapMode = 0
;   PaperSpace (RO) = Exception occurred

This is weird; it should return an object like ModelSpace does.  Anyone else ever seen this before? or knows of a way around it?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #4 on: January 08, 2007, 10:34:08 PM »
Try
Code: [Select]
(vla-get-name(vla-get-layout(vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Finding list of tabs ...
« Reply #5 on: January 08, 2007, 10:37:45 PM »
Tim, my first thought was that you'd get an error for the Paperspace object if no paperspace had yet been created...i.e. before any Layout had been activated. But, based on a quick test in 2002, that doesn't appear to be correct. I started a new drawing and before doing anything else dumped the Doc object and it reports a Paperspace object.

So, I dunno..... although I'm having vague recollections of running into something similar quite some time ago. I'll go through some of my old test junk later tonight or tomorrow to see what I can find.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Finding list of tabs ...
« Reply #6 on: January 09, 2007, 10:47:47 AM »
Morn'n everyone.

Thank you for the plethora of responses.

Dan asked ...
Quote
you mean like (layoutlist) ?

A, yes, I think that's what it would be.  If that would give a list of the layout tabs currently in the drawing.

Tim brought up a good question,
Quote
Does anyone know how to get which paper space tab it will switch to?

Couldn't you just filter the list to find the layout and set it to the variable 'CTAB' ??
(of course this won't work out of the gate as is, I'm not THAT good)   :wink:
Code: [Select]
... Assuming the layoutlist gives a list of available tabs (I haven't seen it in working order to know)
... "S1.1A" "S1.1B" "Add-1" "Add-2" "Add-3"

(setq tab-1 (car (layoutlist)))
(if (= tab-1 S1.1A)
    (setvar "CTAB" tab-1))

Perhaps I'm up in the night, (Don't ask my Wife, she'll just confirm it   :-D)  but this is where my thoughts on this subject are at.  I don't have enough experience with this to know any better.

Thanks Jeff for your input.  You're right, there is always a layout tab (Well, for the newer versions of cad anyway).  So with a layoutlist, on a blank drawing, you would still have "layout" if I'm not mistaking.
We appreciate your looking into some more though, thank you.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #7 on: January 09, 2007, 11:09:21 AM »
Try
Code: [Select]
(vla-get-name(vla-get-layout(vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))))
I was looking for something simple like that, and must have missed it, but it will still error once in awhile, because the '(vla-get-paperspace' will return an error.

Thanks though Alan, I don't know how I missed that one '(vla-get-layout' that is.  :wink:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #8 on: January 09, 2007, 11:16:51 AM »
Tim,
When it errors can you reissue the call & get the layout name or does it still error?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #9 on: January 09, 2007, 11:28:12 AM »
Alan,

  When it errors, it will continue to error until Acad tells it not to.  I have issued it and had it error 4 times in a row, then I manually switch (push the tabs) and it still errors.  Using 'tilemode' and it still errors.  This dosn't happen offten, but it does happen.  I don't know what causes it, or how to fix it, so maybe an error catch will work probably 80% of the time.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #10 on: January 09, 2007, 11:50:13 AM »
Wow, sounds like it really broken.  :-o
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #11 on: January 09, 2007, 12:03:04 PM »
Wow, sounds like it really broken.  :-o
Yea, and I never noticed it until I tried to do the stuff in the this thread, so it might just be a random thing with certain drawings.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Finding list of tabs ...
« Reply #12 on: January 09, 2007, 03:13:04 PM »
So what's the conclusion to this little dilemma, ...

are you telling me that it doesn't matter what tab it goes to when switching to paper space, you can't determine and set active the particular tab you want ???
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #13 on: January 09, 2007, 03:18:48 PM »
So what's the conclusion to this little dilemma, ...

are you telling me that it doesn't matter what tab it goes to when switching to paper space, you can't determine and set active the particular tab you want ???
You might be able to, but sometimes it might error, so it won't be able to.

If all you want to do is a get a list of the layouts, and then pull up a little dialog so select, then yest you can make it work (I think).  If you have a specific layout you want it to always go to, then I think you can make a button to do that also.  I would think you would want a new button, and not a reactor (just a thought I wanted to put out there =D).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #14 on: January 09, 2007, 04:06:03 PM »
So what's the conclusion to this little dilemma, ...

are you telling me that it doesn't matter what tab it goes to when switching to paper space, you can't determine and set active the particular tab you want ???
Questions:
Is the preferred tab always the first one after the Model Space Tab?
Does the preferred tab always have the same name or is the name unique in some way?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Finding list of tabs ...
« Reply #15 on: January 09, 2007, 04:08:52 PM »
Quote
If you have a specific layout you want it to always go to, then I think you can make a button to do that ...
I would think you would want a new button, and not a reactor (just a thought I wanted to put out there =D).

Actually Tim, I want it to work with the following code.
Code: [Select]
  (setq space (getvar "tilemode"))
;
  (if (= space 1);;; Model space
    (progn
      (command ".zoom" "E")
      (command ".-layer" "thaw" "0" "on" "0" "set" "0" "")
      (command "tilemode" 0)
      (if (/= (getvar "cvport") 1)
        (command ".pspace"))
*** Enter Code to make it go to required tab ***
      (setvar "ltscale" (/ dims 2))
      (command ".zoom" "E")
    )
  )
  (if (= space 0); Paper space
    (progn
      (if (/= (getvar "cvport") 1)
    (command ".pspace"))
*** Enter Code to make it go to required tab ***
      (command ".-layer" "thaw" "0" "on" "0" "set" "0" "")
      (setvar "ltscale" (/ dims 2))
      (command ".zoom" "E")
    )
  )

Usually the required tab is the first tab in any given set of tabs on a drawing.  Sometimes though, that required tab would be second or third.
As I posted initially, the tab would be one of a series of possible names;  S-1, S-11, S1.1, S1.1A, SF101, etc.

My initial thought is to create a conditional,
Code: [Select]
  (setq tab-1 (car (layoutlist)))
  (progn
    (cond ( (= tab-1 "S-1")
               (setvar "ctab" tab-1))
             ( (= tab-1 "S-11")
               (setvar "ctab" tab-1))
             ( (= tab-1 "S1.1")
               (setvar "ctab" tab-1))
  ... etc, etc.

I'm not quite understanding this though,
Code: [Select]
...
(foreach tab (layoutlist)
    (if (not (member tab (list "Model" ctab)))
        (progn
 ...

I should say I don't understand how layoutlist is working here.  From the examples CAB posted above, I'm not following them very well.
And I realize my code for breaking the layoutlist down would be very tedious.  Do you have another way for getting the list broken down to the individual tabs names from within the list ??

*** Edited ***

Quote
Is the preferred tab always the first one after the Model Space Tab?

CAB - 9 times out of 10, Yes.
Quote
Does the preferred tab always have the same name or is the name unique in some way?

It has a unique name as mentioned above (at least I think it's unique).  :-D
« Last Edit: January 09, 2007, 04:14:21 PM by Hangman »
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Finding list of tabs ...
« Reply #16 on: January 09, 2007, 04:45:55 PM »
You could try this:
Code: [Select]
(defun c:test()
   (setq tabs (GetLayouts))
    (cond
      ((setq tab-1 (member "S-1" tabs)))
      ((setq tab-1 (member "S-11" tabs)))
      ((setq tab-1 (member "S1.1" tabs)))
      ((setq tab-1 tabs))
    )
    (setvar "ctab" (car tab-1))
 )


Code: [Select]
;;  Returns the layouts in "Tab Order"
(defun GetLayouts(/ tab-list)
  ;; get tab names, sort in tab order & remove model & flagged tab names
  (vlax-map-collection
    (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    '(lambda (x) (setq tab-list (cons x tab-list))))
  ;;  sort in tab order just in case it is needed
  (setq tab-list (vl-sort tab-list '(lambda (x y)
                            (< (vla-get-taborder x) (vla-get-taborder y)))))
  ;;  make list of names into strings  remove Model space
  (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Finding list of tabs ...
« Reply #17 on: January 09, 2007, 05:32:04 PM »
Damn CAB, that is slick !!!  Thanks.

I am curious, I don't understand lambda yet, but I'm thinking it would not cause the list to repeat itself would it ??
This is what I get when typing it in at the command prompt:
Quote
Command: (vlax-map-collection
(_>     (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
(_> '(lambda (x) (setq tab-list (cons x tab-list))))
Quote
#<VLA-OBJECT IAcadLayouts 0c289564>

Command: (setq tab-list (vl-sort tab-list '(lambda (x y)
(('(_>                             (< (vla-get-taborder x) (vla-get-taborder y)))))
Quote
(#<VLA-OBJECT IAcadLayout 0c2a62a4> #<VLA-OBJECT IAcadLayout 0c2a62a4>
#<VLA-OBJECT IAcadLayout 0c2a7c94> #<VLA-OBJECT IAcadLayout 0c2a7c94>
#<VLA-OBJECT IAcadLayout 11085894> #<VLA-OBJECT IAcadLayout 11081574>
#<VLA-OBJECT IAcadLayout 11081524> #<VLA-OBJECT IAcadLayout 110858e4>)

Command: (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list))
Quote
("S1.1A" "S1.1A" "S1.1B" "Add-1 (1)" "Add-1 (2)" "Add-1 (3)")


So I went back and retyped it to the command line without the 'vl-remove' statement,
Quote
Command: (mapcar '(lambda (x)(vla-get-name x))tab-list)
Quote
("Model" "Model" "S1.1A" "S1.1A" "S1.1B" "Add-1 (1)" "Add-1 (2)" "Add-1 (3)")


Notice the repeat of "Model" and "S1.1A".  Anyone know the reasoning behind this phenomenon ??
« Last Edit: January 09, 2007, 05:55:18 PM by Hangman »
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding list of tabs ...
« Reply #18 on: January 09, 2007, 06:42:25 PM »
Maybe 'tab-list' was set to something before you ran the routine, since you should be getting more than what is onet he drawing.  I only get three tabs, and all I have is three in the current drawing.  Try this then
Code: [Select]
(progn
 (setq tab-list nil)
 (setq tab-name-list nil)
 (vlax-map-collection
  (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  '(lambda (x) (setq tab-list (cons x tab-list)))
 )
 (setq tab-list (vl-sort tab-list '(lambda (a b) (< (vla-get-TabOrder a) (vla-get-TabOrder b)))))
 (setq tab-name-list (vl-remove-if '(lambda (x) (= x "Model")) (mapcar 'vla-get-Name tab-list)))
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding list of tabs ...
« Reply #19 on: January 09, 2007, 06:56:36 PM »
Maybe 'tab-list' was set to something before you ran the routine, since you should be getting more than what is onet he drawing.  ....  Try this then
Code: [Select]
(progn
 (setq tab-list nil)
 (setq tab-name-list nil)
;;.............
 

That is probably something that code testers should burn into their brain ... make sure your data lists are
uncontaminated.
« Last Edit: January 09, 2007, 06:57:37 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Finding list of tabs ...
« Reply #20 on: January 09, 2007, 07:00:54 PM »
Yeah I'm a think'n you're right.
I haven't been able to duplicate my 'double vision' so it must have been a contaminating smudge on my glasses.   :kewl:

Thanks guys.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~