Jump to content

Adding Dialog Prompt to command line question


rcb007

Recommended Posts

I need to figure out how to add a dialog popup box into the below routine. It is there to ask what layout tab you would want to use and then how many copies. I have alerts up to notify the user to place the commands at the command line. Just not sure if that is the best approach.

 

(defun c:Layouts_Duplicate ( / *error* oCMDECHO ctab name namer namei nname n i x )
  



  (Alert "Which Layout Tab to Duplicate?\n\nFor (Current Tab Press Enter):")
  (setq ctab (getvar "ctab"))
  (setq name (getstring (strcat "\nLayout to duplicate <" ctab "> (Current Tab Press Enter): "))) ;;;;;;; <<<<<--- Prompt for a Dialog for the user to set the value?
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  




  (while (and (> n 1)
              (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#"))
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)





  (Alert "How many additional Layout Tabs needed?\n\n(Matchline Viewports)") 
  (setq n (getint "\nHow many additional layout tabs needed: ")  ;;;;;;; <<<<<--- Prompt for a Dialog for the user to set the value?
        i (+ 1 namei n))
  




  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (foreach name	(layoutlist)
    (setvar 'ctab name)
    (setq n (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
    (command "-layer"
	     "Freeze"
	     "Matchline*"
	     "Thaw"
	     (strcat "*Area" (itoa (cdr (assoc 71 (dictsearch n name)))))
	     ""
    )
    (command "_mspace")
    (command "zoom" "extents")
    (command "ZOOM" "Scale" "1/10xp")
    (command "_pspace")
  )

(command "-xref" "reload" "*")
  (setvar 'CMDECHO oCMDECHO)
  (princ))

(c:Layouts_Duplicate)

thank you for any direction.

Edited by rcb007
Link to comment
Share on other sites

If you want a pop up list then have a look at Lee-mac.com he has a good one can populate the list with the layout names. 

 

So would replace at this point, note can make current layout the current highlited layout 

(Alert "Which Layout Tab to Duplicate?\n\nFor (Current Tab Press Enter):")
Link to comment
Share on other sites

Le Mac's http://www.lee-mac.com/tabsort.html lets you pick the Layout tab in a dialog box to copy, move, sort, rename, add prefix/suffix, or set current. There's even a help file.

A program designed with the intention to aid in the organisation of layout tabs in a drawing, the program enables the user to organise each layout tab using intuitively engineered buttons to move selected tabs up/down or to the top/bottom of the tab order.

The program also offers the ability to rename a layout tab by double-clicking on its entry in the list displayed, and furthermore add a prefix and/or suffix to selected/every layout tab.

A facility is also provided to add & delete layout tabs, and also sort the tabs into alphabetical, numerical, or architectural order; or reverse the order currently displayed.

A Find & Replace functionality is also offered to allow the user to quickly replace a text string in multiple layout tabs.

The user may also copy selected layout tabs, or set the selected entry as the current drawing layout.

A Help Dialog may be shown upon pressing H at the Main Dialog interface.

Link to comment
Share on other sites

  • 3 years later...
On 7/24/2020 at 11:23 AM, rcb007 said:

I need to figure out how to add a dialog popup box into the below routine. It is there to ask what layout tab you would want to use and then how many copies. I have alerts up to notify the user to place the commands at the command line. Just not sure if that is the best approach.

 

(defun c:Layouts_Duplicate ( / *error* oCMDECHO ctab name namer namei nname n i x )
  



  (Alert "Which Layout Tab to Duplicate?\n\nFor (Current Tab Press Enter):")
  (setq ctab (getvar "ctab"))
  (setq name (getstring (strcat "\nLayout to duplicate <" ctab "> (Current Tab Press Enter): "))) ;;;;;;; <<<<<--- Prompt for a Dialog for the user to set the value?
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  




  (while (and (> n 1)
              (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#"))
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)





  (Alert "How many additional Layout Tabs needed?\n\n(Matchline Viewports)") 
  (setq n (getint "\nHow many additional layout tabs needed: ")  ;;;;;;; <<<<<--- Prompt for a Dialog for the user to set the value?
        i (+ 1 namei n))
  




  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (foreach name	(layoutlist)
    (setvar 'ctab name)
    (setq n (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
    (command "-layer"
	     "Freeze"
	     "Matchline*"
	     "Thaw"
	     (strcat "*Area" (itoa (cdr (assoc 71 (dictsearch n name)))))
	     ""
    )
    (command "_mspace")
    (command "zoom" "extents")
    (command "ZOOM" "Scale" "1/10xp")
    (command "_pspace")
  )

(command "-xref" "reload" "*")
  (setvar 'CMDECHO oCMDECHO)
  (princ))

(c:Layouts_Duplicate)

thank you for any direction.

 

I am testing this with 2024, and it seems it seems when creating a new layout tab, it is not sync'd to the right layout tab name. Everything prior to 2024 seems to work as expected.

 

For example. If I have 4 areas, usually it will match area 1 with the first layout tab and so forth. However, it is now starting the reverse, so layout 4 would be area 1, then layout tab 3 would be area 2 and so forth.

 

Not sure what in the code needs to be modified to make it work correctly.

 

Thanks for any help.

 

Link to comment
Share on other sites

The fixed I used was to reorder the Layout Tabs.

https://www.cadtutor.net/forum/topic/65072-rename-layout/

 

(defun c:foo (/ i l n o)
 ;; Prefix
 (setq pre "BWSIP-2R-DD-TP-M")
 ;; Start number
 (setq n 1)
 ;; Get all paperspace layouts
 (vlax-for x (setq lo (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
   (cond ((> (vla-get-taborder x) 0) (setq o (cons x o))))
 )
 ;; Sort left to right
 (setq o (vl-sort o '(lambda (r j) (< (vla-get-taborder r) (vla-get-taborder j)))))
 ;; Apply a temp name to avoid duplicates
 (foreach l o (vla-put-name l (rtos (/ (getvar 'cdate) (vla-get-taborder l)) 2 12)))
 ;; Renumber
 (foreach l o
   (setq i (cond ((< n 10) (strcat "0" (itoa n)))
	  ((itoa n))
    )
   )
   (vla-put-name l (strcat pre i))
   (setq n (1+ n))
 )
 (princ)
)
(vl-load-com)

 

Hope this helps! Thanks Ron for putting this together.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...