Author Topic: Searching for Layout1 in a list  (Read 10735 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Searching for Layout1 in a list
« on: February 20, 2007, 12:15:14 PM »
Hey guys, how can this piece of code be manipulated to search for a named layout ??
Code: [Select]
    (progn
      (setq Layout
        (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 (x y) (< (vla-get-taborder x) (vla-get-taborder y)))))
      (setq tab-1 (vl-remove "Layout1" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
      (setvar "ctab" (car tab-1)))

I need to do a search & destroy,
Quote
  If "Layout1" exists, then remove
  If "8.5 x 11" exists, then remove
  Else leave list in sorted order

Thanks a bunch.
Hangman  8)

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #1 on: February 20, 2007, 12:37:23 PM »
Code: [Select]
(vl-catch-all-apply
 'vla-Item
 (list
  (vla-get-Layouts
   (vla-get-ActiveDocument
    (vlax-get-Acad-Object)
   )
  )
  "Layout1"
 )
)
You can set this to something, then check to see if it's an error, if so, then the layout doesn't exist, if it's not an error, then it will return the layout object.
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: Searching for Layout1 in a list
« Reply #2 on: February 20, 2007, 01:55:06 PM »
I don't know who the author is.
Code: [Select]
(defun i:deletelayout (layoutname)
  (vl-load-com)
  (cond ((not
           (vl-catch-all-error-p
             (vl-catch-all-apply
               (function
                 (lambda ()
                   (vla-delete
                     (vla-item
                       (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
                       layoutname
                     )
                   )
                 )
               )
             )
           )
         )
        )
  )
)
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Searching for Layout1 in a list
« Reply #3 on: February 20, 2007, 02:24:23 PM »
>CAB

I have a little reduced a code.
In a code there were superfluous letters...

Code: [Select]
(defun i:deletelayout (layoutname)
 (vl-load-com)
 (not
  (vl-catch-all-error-p
   (vl-catch-all-apply
    (function
     (lambda ()
      (vla-delete
       (vla-item
        (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
        layoutname
       ) ;_  vla-item
      ) ;_  vla-delete
     ) ;_  lambda
    ) ;_  function
   ) ;_  vl-catch-all-apply
  ) ;_  vl-catch-all-error-p
 ) ;_  not
)

Hangman

  • Swamp Rat
  • Posts: 566
Re: Searching for Layout1 in a list
« Reply #4 on: February 20, 2007, 02:35:16 PM »
Well, I'm at a bit of a loss here.
Maybe I'm trying too hard.
OK, so this is what I've tried.
Quote
(vl-catch-all-apply (vla-delete 'vla-Item (list
(((_> (vla-get-layouts (vla-get-activedocument (vlax-get-Acad-object))
"Layout1"))))
; error: Too many actual parameters
Quote
(vla-delete (vl-catch-all-apply 'vla-Item (list
(((_> (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))
"Layout1"))))
; error: Too many actual parameters
Quote
(setq tab (vl-catch-all-apply 'vla-item (list (vla-get-layouts
((((_> (vla-get-activedocument (vlax-get-acad-object)) "Layout1"))))
; error: Too many actual parameters
Quote
  (setq Layout
    (progn
      (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
          '(lambda (x) (setq tab-list (cons x tab-list)))))
      (setq tab-1 (vla-delete "Layout1" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
      (setvar "ctab" (car tab-1)))

I know I already have the "...get-layouts", the "... get-activedocument" & the "...get-acad-object".  I wouldn't think I would need them twice.
What I'm not understanding from CAB's post, is the (function (lambda () (vla-delete ... ))).  Does the (function (lambda ... )) allow the tab to be deleted ??  Tims post gets the "Layout1" name from the list.  Much like the earlier code mearly removes it from the list, it doesn't delete it from the drawing, right ??

So how do I make an IF statement that will delete the "Layout1" tab from the drawing if it is there without writing all the "get-Layouts", "get-activedocument", & "get-acad-object" two or three times ??
I have that in my code so far,
Code: [Select]
  (setq Layout
    (progn
      (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
        '(lambda (x) (setq tab-list (cons x tab-list)))))
    (setq tab-1 (vl-remove "Layout1" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
I don't need to remove the "Layout1" from the list, but if it is in the list, then delete the tab from the drawing.
Am I getting warmer by putting it this way ??
Code: [Select]
  (setq Layout
    (progn
      (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
        '(lambda (x) (setq tab-list (cons x tab-list)))))
    (if (setq tab-1 (vla-item "Layout1" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
      (function (lambda ()(vla-delete (vla-item "Layout1")))))

Thanks.
Hangman  8)

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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Searching for Layout1 in a list
« Reply #5 on: February 20, 2007, 02:42:55 PM »
the code above is the ticket ... a slower method, but shorter code is ...

Code: [Select]
(if (member layoutname (layoutlist))
    (vl-cmdf "_.layout" "d" layoutname)
)

Of course capitalization is a factor ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Searching for Layout1 in a list
« Reply #6 on: February 20, 2007, 02:59:42 PM »
Quote
What I'm not understanding from CAB's post, is the (function (lambda () (vla-delete ... ))).  Does the (function (lambda ... )) allow the tab to be deleted ??

You don't need to check if it exists.
The stuff in the (function (lambda ... )) TRIES to delete the layout assuming it exists.
The   (Vl-catch-all-error-p   (vl-catch-all-apply .... )) wrapper is just in case it Doesn't exist.

Quote
I know I already have the "...get-layouts", the "... get-activedocument" & the "...get-acad-object".  I wouldn't think I would need them twice.

Not sure what you mean by this ..

but ..
If you already have variables holding the name of the layouts collection you can use it instead because the variable points to the collection object irrespective of what it contains. In theory you only need to set the variable once per document instance and re-use the same variable for all code. 





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: Searching for Layout1 in a list
« Reply #7 on: February 20, 2007, 03:29:39 PM »
the code above is the ticket ... a slower method, but shorter code is ...
Code: [Select]
(if (member layoutname (layoutlist))
    (vl-cmdf "_.layout" "d" layoutname)
)
Of course capitalization is a factor ...
Ahhh, so this is also case sensitive ?.  Interesting.  Thank you Keith, I didn't know that.


Quote
What I'm not understanding from CAB's post, is the (function (lambda () (vla-delete ... ))).  Does the (function (lambda ... )) allow the tab to be deleted ??

You don't need to check if it exists.
The stuff in the (function (lambda ... )) TRIES to delete the layout assuming it exists.
The   (Vl-catch-all-error-p   (vl-catch-all-apply .... )) wrapper is just in case it Doesn't exist.

That is what I was thinking, the current code I have is
Code: [Select]
(setq Layout
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      '(lambda (x) (setq tab-list (cons x tab-list)))))
    (setq tab-1 (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
    (setvar "ctab" (car tab-1)))
I need this to get to a layout "8.5 x 11" out of two or three layouts in the drawing.  I don't need a "Layout1" if it exists.
But when I try to input the
          (vl-catch-all-error-p
             (vl-catch-all-apply
               (function
                 (lambda ()
                   (vla-delete
                     (vla-item
                       (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
                       layoutname ...
It keeps erroring on me.  I'm not putting it correctly, but I don't know how it's suppose to read yet.



Quote
I know I already have the "...get-layouts", the "... get-activedocument" & the "...get-acad-object".  I wouldn't think I would need them twice.

Not sure what you mean by this ..

but ..
If you already have variables holding the name of the layouts collection you can use it instead because the variable points to the collection object irrespective of what it contains. In theory you only need to set the variable once per document instance and re-use the same variable for all code. 

Basically, just what you said there.  I already have
Code: [Select]
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
Why would I need it again.

I need to go try Keith's example, see I can get it to work.  BRB
Hangman  8)

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

Hangman

  • Swamp Rat
  • Posts: 566
Re: Searching for Layout1 in a list
« Reply #8 on: February 20, 2007, 03:49:00 PM »
*** Grrrrrr ***   :realmad:
I just don't know what I'm doing.

Here's what I put in, and got out.
Quote
Command: (setq Layout (progn (vlax-map-collection (vla-get-layouts
(vla-get-activedocument (vlax-get-acad-object)))
(((_> '(lambda (x) (setq tab-list (cons x tab-list))))))
#<VLA-OBJECT IAcadLayouts 061326b4>    So it's getting the object, or the List.

Command: (if (member "Layout1" (tab-list))
(_> (vl-cmdf "_.layout" "d" "Layout1"))
; error: bad function: (#<VLA-OBJECT IAcadLayout 06133fb4> #<VLA-OBJECT
IAcadLayout 06132044> #<VLA-OBJECT IAcadLayout 06132424>)

Command: (if (member Layout1 (tab-list))(vl-cmdf ".LAYOUT" "D" Layout1))
; error: bad function: (#<VLA-OBJECT IAcadLayout 06133fb4> #<VLA-OBJECT
IAcadLayout 06132044> #<VLA-OBJECT IAcadLayout 06132424>)

Command: (if (member "Layout1" (Layout))(vl-cmdf ".LAYOUT" "D" "Layout1"))
; error: bad function: #<VLA-OBJECT IAcadLayouts 061326b4>

Command: (if (member Layout1 (Layout))(vl-cmdf ".LAYOUT" "D" "Layout1"))
; error: bad function: #<VLA-OBJECT IAcadLayouts 061326b4>

Command: (if (member Layout1 (tab-list))(vl-cmdf ".LAYOUT" "D" "Layout1"))
; error: bad function: (#<VLA-OBJECT IAcadLayout 06133fb4> #<VLA-OBJECT
IAcadLayout 06132044> #<VLA-OBJECT IAcadLayout 06132424>)

I don't understand what format or order this code has to be in to read correctly.
I'm understanding the concept behind it I think.
Quote
If "Layout1" is a member of (Tab-List)
vl-command ".Layout" "Delete" "Layout1"
I would think it would be a straight forward command.
Hangman  8)

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #9 on: February 20, 2007, 03:52:45 PM »
Just use the code provide by Alan or Evgeniy.  All you need to do is supply the name to the call.  So call like
Code: [Select]
(i:deletelayout "Layout1")
Tim

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

Please think about donating if this post helped you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Searching for Layout1 in a list
« Reply #10 on: February 20, 2007, 04:53:54 PM »
the one I provided is also where you supply the name of the layout ..

But if you already have the reference to the layout as a vla-object, all you need to do is simply delete it ...

Code: [Select]

(vla-delete MyLayoutObject)

Or you could cycle through the entire list of layouts ...
Code: [Select]
(defun dellayouts (MyLayoutListToDelete / *layouts* *layout*)
  (vl-load-com)
  (setq *layouts* (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for *layout* *layouts*
    (if (member (strcase (vlax-get-property *layout* 'Name)) MyLayoutListToDelete)
      (vla-delete *layout*)
    ) ;_ end of if
  ) ;_ end of vlax-for
) ;_ end of defun

You would use the above like so ...
Code: [Select]
(dellayouts '("LAYOUT1" "11 X 17" "ANOTHER LAYOUT"))

Good Luck
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Searching for Layout1 in a list
« Reply #11 on: February 20, 2007, 06:09:35 PM »
Hangman,

You could try this...it's not much different that what been posted above, but uses wcmatch so wildcards can be used.

Code: [Select]
(defun elayout (filter)

  (vlax-map-collection
    (vla-get-layouts
      (vla-get-activedocument (vlax-get-acad-object))
    )
    '(lambda (x)
       (if (wcmatch (strcase (vla-get-name x)) (strcase filter))
(vla-delete x)
       )
     )
  )
 
)

Use like so: (elayout "*")

Take a look at wcmatch filters in the  developer help file for more info. Once you get your filter setup, deleting tabs will be a cinch.  :-)

Code: [Select]
# (pound)
 Matches any single numeric digit.
 
@ (at)
 Matches any single alphabetic character.
 
. (period)
 Matches any single nonalphanumeric character.
 
* (asterisk)
 Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end.
 
? (question mark)
 Matches any single character.
 
~ (tilde)
 If it is the first character in the pattern, it matches anything except the pattern.
 
[...]
 Matches any one of the characters enclosed.
 
[~...]
 Matches any single character not enclosed.
 
- (hyphen)
 Used inside brackets to specify a range for a single character.
 
, (comma)
 Separates two patterns.
 
` (reverse quote)
 Escapes special characters (reads next character literally).
 


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Hangman

  • Swamp Rat
  • Posts: 566
Re: Searching for Layout1 in a list
« Reply #12 on: February 20, 2007, 06:59:18 PM »
Hangman,
You could try this...it's not much different that what been posted above, but uses wcmatch so wildcards can be used.
Code: [Select]
(defun elayout (filter)
  (vlax-map-collection
    (vla-get-layouts
      (vla-get-activedocument (vlax-get-acad-object))
    )
    '(lambda (x)
       (if (wcmatch (strcase (vla-get-name x)) (strcase filter))
(vla-delete x)
       )
     )
  )
)

Use like so: (elayout "*")

Ron, this looks really close to what I'm after.  Sorry, I just don't know how to put the VL stuff together yet.  I'm learn'n, but I'm slow.
Basically, I want to take this,
Code: [Select]
(not
  (vl-catch-all-error-p
   (vl-catch-all-apply
    (function
     (lambda ()
      (vla-delete
       (vla-item
        (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
        layoutname
       ) ;_  vla-item
      ) ;_  vla-delete
     ) ;_  lambda
    ) ;_  function
   ) ;_  vl-catch-all-apply
  ) ;_  vl-catch-all-error-p
 ) ;_  not

And incorporate it into this.
Code: [Select]
    (setq Layout
      (progn
        (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 (x y) (< (vla-get-taborder x) (vla-get-taborder y)))))
      (setq tab-1 (vl-remove "Layout1" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
      (setvar "ctab" (car tab-1)))

As you can see from all my posts, I've been trying, but I keep messing it up.  Perhaps I am asking something that can't be done the way I am looking to do it.
But I have enough examples here, I SHOULD be able to do something with it.  (right)   :lmao:

Thank you, I'll keep working on it.
Hangman  8)

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #13 on: February 20, 2007, 07:17:32 PM »
Why do you want to make a list of all the layouts?  If you only want to erase the layout, then there is no need to go about making a list of them.  If you have a reason for making a list, then we could code something up that will erase it if it's there, and if it's not (meaning doesn't match the name) when we will add it to the list.

I guess it would help us to understand what the whole program is going to be doing.
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: Searching for Layout1 in a list
« Reply #14 on: February 20, 2007, 07:46:51 PM »
Why do you want to make a list of all the layouts?  If you only want to erase the layout, then there is no need to go about making a list of them.  If you have a reason for making a list, then we could code something up that will erase it if it's there, and if it's not (meaning doesn't match the name) when we will add it to the list.

I guess it would help us to understand what the whole program is going to be doing.

I need a list of the layouts so I can get the layout I need for plotting.  There are two to three layouts, depending on the detail.
Some of these details have not been updated in a while and have no layout, just "Layout1".  There is nothing set in it, not even a viewport.  Some of these details have two or three layouts, "Layout1", "8.5 x 11", &/or "Detail1".
I'm doing a mass cleanup of these details so I can plot a DWF of them for the engineers.  I have a proto called "8.5 x 11" I am pulling into the drawing.  But I need to delete the old "8.5 x 11" and the "Layout1", then import the new "8.5 x 11" and set it as current, leaving the other layouts alone.  Once I have the new "8.5 x 11" layout as current, I can use the variable 'cvport' to go in & zoom to its proper scale.

I'm just about there if I can figure out how to delete the 1, 2, or 3 layouts while keeping any others and setting a new imported layout as the current layout so I can plot it.

I hope this made sense, otherwise it's a really, really, really, really, really, really, really, really, really long story.   :|
Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Searching for Layout1 in a list
« Reply #15 on: February 20, 2007, 08:24:05 PM »
...........
I guess it would help us to understand what the whole program is going to be doing.

With due respect to Hangman ..
This is a continuing problem with questions asked in this and other forums.
The little bit of time it takes to be explicit with questions will generally save a lot of time and aggravation later ... for both the O.P. and anyone trying to help solve the problem.


 
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.

Glenn R

  • Guest
Re: Searching for Layout1 in a list
« Reply #16 on: February 20, 2007, 08:36:26 PM »
Agreed++

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #17 on: February 21, 2007, 12:29:21 PM »
Could you delete all paper space layouts, and then insert your new one?

How I would go about getting a list of layout names (with the layout object).

Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (setq LoList (cons (cons (vla-get-Name Lo) Lo) LoList))
)
Returns a list like
Quote
(
 ("Model" . #<VLA-OBJECT IAcadLayout 11894b34>)
 ("Layout2" . #<VLA-OBJECT IAcadLayout 11894b84>)
 ("Layout1" . #<VLA-OBJECT IAcadLayout 11894bd4>)
)
Now maybe put the names in a dialog box, and then ask the user which ones to delete, and then delete them, using the object.  Something of an example (without a dialog box, using the code above).
Code: [Select]
(progn
 (setq cnt 0)
 (foreach i LoList
  (prompt (strcat "\n " (itoa cnt) " - " (car i)))
  (setq cnt (1+ cnt))
 )
 (setq Num (getint "\n Enter number of layout to delete: "))
 (if Num
  (vla-Delete (cdr (nth Num LoList)))
 )
)
Hope this helps.
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: Searching for Layout1 in a list
« Reply #18 on: February 21, 2007, 02:07:53 PM »
Could you delete all paper space layouts, and then insert your new one?

Well, as I mentioned, there are some I need to keep.  Mostly from the newer details, but it isn't in all the details so I can't just recreate it later.
I know the names of all of the layouts to be deleted, mainly "Layout1", "8.5 x 11", & "Detail1".  But I also know that these three layouts are NOT in all the details either, they vary.  The layouts I need to keep have names like: "ConnPlate1", "PierReinf1", etc.


Now maybe put the names in a dialog box, and then ask the user which ones to delete, and then delete them, using the object.  Something of an example (without a dialog box, using the code above).
  ...
Hope this helps.

Ohhh, oh, oh, oh, ...  Doht !!!  Now I understand where a confusing dialog is taking place.
Ok, this project here is also part of another question I had in this forum as well.  http://www.theswamp.org/index.php?topic=15024.0
I am updating a mass of details (somewhere's in the neighborhood of 400 +) and am creating this to be totally automated.  I will be running a lisp that will create a script you taught me about, and that will run this routine to clean up the details.
So, I don't want any user input stuff going on, otherwise it defeats the purpose of this project.

The only user input is at the beginning of the script creating lisp, asking the type of detail to be updated.  The user (me) inputs FTG for footing and the lisp goes out, gets all the footing details, creates the script and then runs the script which will access this routine we are currently discussing.
This routine we are discussing here is to purge everything, set layer to zero, color to bylayer, etc.  It creates the office's new layer standard & converts the items on the old layers to the new.  It creates two text styles, and a dimension style (depending on the dimscale - assuming the detail was drawn to a scale), & puts the dimension strings & leaders to the new style.  It then imports a new paperspace layout complete with plotting configurations & such.  It then deletes any old, voided layouts, while keeping the pertinent ones, setting the new layout as current, zooming the detail to it's scale and dropping the name of the detail into the title.
The script saves it, closes it, and opens the next detail.

It's quite lengthy, but it's good practice.  I spent four days updating details and schedules manually and realized I'd be at it for the next six months if I didn't automate the process.  Six months without making the company any money is unacceptable.  :doa:
Hangman  8)

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #19 on: February 21, 2007, 02:18:49 PM »
Okay.  So if you know the names of the layouts to delete, then I would just create a list of them, and then step through the layouts collection, and delete anyone the matches the names in the list.
Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (if (vl-position (strcase (vla-get-Name Lo)) '("LAYOUT1" 8.5 X 11" "DETAIL1"))
  (vla-Delete Lo)
 )
)
Tim

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

Please think about donating if this post helped you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Searching for Layout1 in a list
« Reply #20 on: February 21, 2007, 02:37:47 PM »
Okay.  So if you know the names of the layouts to delete, then I would just create a list of them, and then step through the layouts collection, and delete anyone the matches the names in the list.
Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (if (vl-position (strcase (vla-get-Name Lo)) '("LAYOUT1" 8.5 X 11" "DETAIL1"))
  (vla-Delete Lo)
 )
)
Which is EXACTLY what I stated in this post

All that is needed is to add the function I have there to whatever program you want to add it to .. then call it like I showed in the post.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #21 on: February 21, 2007, 02:42:11 PM »
Okay.  So if you know the names of the layouts to delete, then I would just create a list of them, and then step through the layouts collection, and delete anyone the matches the names in the list.
Code: [Select]
(vlax-for Lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
 (if (vl-position (strcase (vla-get-Name Lo)) '("LAYOUT1" 8.5 X 11" "DETAIL1"))
  (vla-Delete Lo)
 )
)
Which is EXACTLY what I stated in this post

All that is needed is to add the function I have there to whatever program you want to add it to .. then call it like I showed in the post.
You are correct Keith.  I even missed a double quote in my list.  :-)
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: Searching for Layout1 in a list
« Reply #22 on: February 21, 2007, 04:01:39 PM »
Ok, Two things plus One.
First, when I plugged in the code, I received - "Model".  The tabs didn't get deleted, nothing else happened, just the  "Model"
Here's a pic.

Secondly, and this goes back to my question, How do I incorporate your code into this one ??
Code: [Select]
(setq Layout
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      '(lambda (x) (setq tab-list (cons x tab-list)))))
    (setq tab-1 (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
    (setvar "ctab" (car tab-1)))
Maybe I keep asking something here that I'm just not understanding, but if I am importing a new "8.5 x 11" into a drawing with one or two other layouts, don't I have to have a list so I can get the new imported layout to be the current layout ??
After I delete the old layout(s), I import a new layout.  I now have three layouts in a drawing.  I need a list of the three layouts, then filter out the one I need to make it current.  Is this thought correct or am I overlooking something or not understanding something ??

My plus One.  After import the new layout, I noticed it was called "Layout1-8.5 x 11".  I initially thought it was because I hadn't deleted the first "Layout1" yet, but when I imported it to a drawing that didn't have a "Layout1", I still got the name "Layout1-8.5 x 11".
Would you know why ??
Here's my code for importing the layout.
Code: [Select]
(command ".LAYOUT" "T" "X:\\DETAILS\\DWF\\_8x11 Print Proto.dwg" "8.5 x 11")

Thank you for your continued help.
Hangman  8)

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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Searching for Layout1 in a list
« Reply #23 on: February 21, 2007, 04:31:09 PM »
Code: [Select]
The problem is that you need to test with uppercase letters ...

Once again .. if you simply add the code provided in [url=http://www.theswamp.org/index.php?topic=15130.msg183590#msg183590]this post
to your program, then at the point in your program that you want to delete the list of layouts add this (dellayouts (list "LAYOUT1" "DETAIL1")) .. it will delete all of the layouts in the list you pass .. if they exist ...

Now, if you want to set a specific layout current, simply set the value of CTAB to the layout name you want current .. i.e.
Code: [Select]
(setvar "CTAB" "8.5 x 11")
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Searching for Layout1 in a list
« Reply #24 on: February 21, 2007, 04:36:23 PM »
Quote
but when I imported it to a drawing that didn't have a "Layout1", I still got the name "Layout1-8.5 x 11".

You didn't have a "Layout1", but you did have a "8.5 x 11" .. so the imported Layout gets named "Layout1-8.5 x 11"
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: Searching for Layout1 in a list
« Reply #25 on: February 21, 2007, 04:41:12 PM »
Code: [Select]
[quote author=Keith™ link=topic=15130.msg183992#msg183992 date=1172093469]
[code]The problem is that you need to test with uppercase letters ...
[/quote]

Thanks Keith.   Yeah, I realized that after I posted and went back to playing with it.

Now, if you want to set a specific layout current, simply set the value of CTAB to the layout name you want current .. i.e.
Code: [Select]
(setvar "CTAB" "8.5 x 11")
[/quote]
Now that I didn't know.  I was thinking the variable could only accept numerical entries which would make it difficult to know just where the layout is.
That's what I get for thinking I know everything.
Thank you again.

* Edited to fix quote*

I'm trying to learn and understand this VLA so please bear with me.
OK, let me see if I understand this,
Code: [Select]
(setq Layout
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) ...
Is the "Layout" that is set here, holding the (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) ??
So if there is a second piece of code put in, I would have to reference that "Layout" that is setq, or retype the entire line of (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) to get the second piece of code to function properly ??

If so, could this be setup at the front when one sets all the variables in preparation for a lisp and then just reference the setq when needed ??

Quote
but when I imported it to a drawing that didn't have a "Layout1", I still got the name "Layout1-8.5 x 11".

You didn't have a "Layout1", but you did have a "8.5 x 11" .. so the imported Layout gets named "Layout1-8.5 x 11"
Ohhh, I didn't know it would do that.  Thank you Kerry.  I'm learn'n a boatload here today.   Thank you everyone for you patience and help, I really appreciate it.[/code]
« Last Edit: February 21, 2007, 04:43:05 PM by Hangman »
Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Searching for Layout1 in a list
« Reply #26 on: February 21, 2007, 04:45:22 PM »
................
Secondly, and this goes back to my question, How do I incorporate your code into this one ??
Code: [Select]
(setq Layout
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      '(lambda (x) (setq tab-list (cons x tab-list)))))
    (setq tab-1 (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
    (setvar "ctab" (car tab-1)))

What do you think this code is doing ?

Do you use the VLIDE ?

I GUESS you mean it to be something like this ..
Code: [Select]
(SETQ Layout
         (PROGN
             (VLAX-MAP-COLLECTION
                 (VLA-GET-LAYOUTS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))
                 '(LAMBDA (x) (SETQ tab-list (CONS x tab-list)))
             )
         )
)
(SETQ tab-1 (VL-REMOVE "Model" (MAPCAR '(LAMBDA (x) (VLA-GET-NAME x)) tab-list)))
(SETVAR "ctab" (CAR tab-1))
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: Searching for Layout1 in a list
« Reply #27 on: February 21, 2007, 05:34:38 PM »
  ...
Code: [Select]
(setq Layout
  (progn
    (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      '(lambda (x) (setq tab-list (cons x tab-list)))))
    (setq tab-1 (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))tab-list)))
    (setvar "ctab" (car tab-1)))

What do you think this code is doing ?

Do you use the VLIDE ?

Well, ... ummm, ...  Yeah, I use vlide.  But now that your asking, I'm probably not using it correctly.   :oops:
About the code, are you asking to decipher it or is this a retorical question ?. 

Quote
I GUESS you mean it to be something like this ..
Code: [Select]
(SETQ Layout
         (PROGN
             (VLAX-MAP-COLLECTION
                 (VLA-GET-LAYOUTS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))
                 '(LAMBDA (x) (SETQ tab-list (CONS x tab-list)))
             )
         )
)
(SETQ tab-1 (VL-REMOVE "Model" (MAPCAR '(LAMBDA (x) (VLA-GET-NAME x)) tab-list)))
(SETVAR "ctab" (CAR tab-1))

Yeah, that's it.   there was actually another line that sorted the list alphabetically.
Hangman  8)

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Searching for Layout1 in a list
« Reply #28 on: February 21, 2007, 06:08:57 PM »
there was actually another line that sorted the list alphabetically.
Code: [Select]
(setq tab-list (vl-sort tab-list '(lambda (a b) (< (strcase a) (strcase b)))))
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: Searching for Layout1 in a list
« Reply #29 on: February 21, 2007, 07:45:38 PM »

Well, ... ummm, ...  Yeah, I use vlide.  But now that your asking, I'm probably not using it correctly.   :oops:
About the code, are you asking to decipher it or is this a retorical question ?. 


It's just that the code would have thrown an error as it was ..

I couldn't scan read it as posted so I copied it into my editor and formatted it, which also highlighted the parenthesis location error .. which changed the logic of the code.

Where possible, posting formatted code makes life SO much easier .. and sometimes the formatting will identify the problem.

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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Searching for Layout1 in a list
« Reply #30 on: February 21, 2007, 10:44:17 PM »

Well, ... ummm, ...  Yeah, I use vlide.  But now that your asking, I'm probably not using it correctly.   :oops:
About the code, are you asking to decipher it or is this a retorical question ?. 


It's just that the code would have thrown an error as it was ..

I couldn't scan read it as posted so I copied it into my editor and formatted it, which also highlighted the parenthesis location error .. which changed the logic of the code.

Where possible, posting formatted code makes life SO much easier .. and sometimes the formatting will identify the problem.



Agreed .. formatted code is so much easier to read ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Hangman

  • Swamp Rat
  • Posts: 566
Re: Searching for Layout1 in a list
« Reply #31 on: February 22, 2007, 11:35:41 AM »
  ...
It's just that the code would have thrown an error as it was ..

I couldn't scan read it as posted so I copied it into my editor and formatted it, which also highlighted the parenthesis location error .. which changed the logic of the code.

Where possible, posting formatted code makes life SO much easier .. and sometimes the formatting will identify the problem.


Cool.  Well, I ummm, ...   :|  don't know how to use vlide very well.   :oops:  Most all my formatted code I put together is from my head.  Perhaps that is why I am struggling so much with the VLA stuff.
Hangman  8)

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