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

0 Members and 1 Guest are viewing this topic.

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.