Author Topic: Save&Restore toolbars position  (Read 6148 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Save&Restore toolbars position
« on: April 16, 2018, 01:00:42 PM »
Based on Lee Mac floatingtoolbarpositions I have written the functions below but I can not reposition correctly after moving...
Code: [Select]
(setq *AcadApp* (vlax-get-acad-object))
(defun ALE_Menu_ToolbarsSavePos ( / TmpLst OutLst LspOut FilPnt)
  (vlax-for MnuGrp (vla-get-MenuGroups *AcadApp*)
    (vlax-for VlaFor (vla-get-Toolbars MnuGrp)
      (setq TmpLst (cons (list (vla-get-name VlaFor) (vla-get-visible VlaFor) (vla-get-top  VlaFor) (vla-get-left VlaFor)) TmpLst))
    )
    (setq OutLst (cons (cons (strcase (vla-get-name MnuGrp)) TmpLst) OutLst)  TmpLst nil)
  )
  (and
    OutLst
    (progn
      (setq FilPnt (open (setq LspOut "Z:\\Temp\\$Cfg_Menu.lsp") "w"))
      (princ "'" FilPnt) (princ (vl-prin1-to-string OutLst) FilPnt)
      (close FilPnt)
      (alert (strcat "Toolsbars position saved on File: " LspOut))
    )
  )
  (princ)
)

(defun ALE_Menu_ToolbarsRecoverPos ( / MnuGrp TlbInf MnuObj TbsObj TlbObj)
  (setq
    MnuGrp (vla-get-menugroups *AcadApp*)
    TlbInf (load "Z:\\Temp\\$Cfg_Menu.lsp")
  )
  (foreach ForMnu TlbInf
    (and
      (cdr ForMnu)
      (setq MnuObj (ALE_Utl_GetItem MnuGrp (car ForMnu)))
      (setq TbsObj (vla-get-Toolbars MnuObj))
      (foreach ForElm (cdr ForMnu)
        (if (setq TlbObj (ALE_Utl_GetItem TbsObj (car ForElm)))
          (progn
            (vla-put-visible TlbObj (cadr ForElm))
            (and
              (= :vlax-true (cadr ForElm))
              (vla-put-top TlbObj (caddr ForElm)) (vla-put-left TlbObj (cadddr ForElm))
            )
          )
        )
      )
    )
  )
)

(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
  (vl-catch-all-apply
   '(lambda ( )
      (setq VlaObj (vla-item VlaCol KeyNam))
    )
  )
  VlaObj
)

(ALE_Menu_ToolbarsSavePos)
(ALE_Menu_ToolbarsRecoverPos)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #1 on: April 17, 2018, 04:53:24 AM »
Added DockStatus but do not works...
Code: [Select]
(setq *AcadApp* (vlax-get-acad-object))
(defun ALE_Menu_ToolbarsSavePos ( / TmpLst OutLst LspOut FilPnt)
  (vlax-for MnuGrp (vla-get-MenuGroups *AcadApp*)
    (vlax-for VlaFor (vla-get-Toolbars MnuGrp)
      (setq TmpLst (cons (list (vla-get-name VlaFor) (vla-get-visible VlaFor) (vla-get-top  VlaFor) (vla-get-left VlaFor) (vla-get-DockStatus VlaFor)) TmpLst))
    )
    (setq OutLst (cons (cons (strcase (vla-get-name MnuGrp)) TmpLst) OutLst)  TmpLst nil)
  )
  (and
    OutLst
    (progn
      (setq FilPnt (open (setq LspOut "Z:\\Temp\\$Cfg_Menu.lsp") "w"))
      (princ "'" FilPnt) (princ (vl-prin1-to-string OutLst) FilPnt)
      (close FilPnt)
      (alert (strcat "Toolsbars position saved on File: " LspOut))
    )
  )
  (princ)
)
(defun ALE_Menu_ToolbarsRecoverPos ( / MnuGrp TlbInf MnuObj TbsObj TlbObj)
  (setq
    MnuGrp (vla-get-menugroups *AcadApp*)
    TlbInf (load "Z:\\Temp\\$Cfg_Menu.lsp")
  )
  (foreach ForMnu TlbInf
    (and
      (cdr ForMnu)
      (setq MnuObj (ALE_Utl_GetItem MnuGrp (car ForMnu)))
      (setq TbsObj (vla-get-Toolbars MnuObj))
      (foreach ForElm (cdr ForMnu)
        (if (setq TlbObj (ALE_Utl_GetItem TbsObj (car ForElm)))
          (progn
            (vla-put-visible TlbObj (cadr ForElm))
            (and
              (= :vlax-true (cadr ForElm))
              (progn
                (vla-put-top TlbObj (caddr ForElm)) (vla-put-left TlbObj (cadddr ForElm))
                (or (= (vla-get-DockStatus TlbObj) (nth 4 ForElm))  (vla-Dock TlbObj (nth 4 ForElm)))
              )
            )
          )
        )
      )
    )
  )
)
(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
  (vl-catch-all-apply
   '(lambda ( )
      (setq VlaObj (vla-item VlaCol KeyNam))
    )
  )
  VlaObj
)
(ALE_Menu_ToolbarsSavePos)
(ALE_Menu_ToolbarsRecoverPos)

Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #2 on: April 17, 2018, 03:37:57 PM »
Added DockStatus but do not works...

The second menu in menugoups is "DBCONNECT" does not have a count property, therefore no (cdr) property list . Could this be the problem?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #3 on: April 17, 2018, 03:48:55 PM »
Added DockStatus but do not works...

The second menu in menugoups is "DBCONNECT" does not have a count property, therefore no (cdr) property list . Could this be the problem?
In my version I have:
Code: [Select]
(defun Test ( / )
  (vlax-for MnuGrp (vla-get-MenuGroups *AcadApp*)
    (Print (vla-get-name MnuGrp))
  )
  (princ)
)
"ACAD"
"CUSTOM"
"USER"
no "DBCONNECT"... I do not think this is the problem.



Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #4 on: April 17, 2018, 04:01:55 PM »
Must be version specific. When i run on my system (2012)  i get.

Command: (test)

"AUTOCADWS"
"DBCONNECT"
"ACAD"
"MODELDOC"
"RONSCUSTOM"
"EXPRESS"
"ACFUSION"
"CONTENTEXPLORER"

Not all of these have a toolbars property

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #5 on: April 17, 2018, 04:12:04 PM »
Ok, thanks... try this version (modify the path "Z:\\Temp\\$Cfg_Menu.lsp" of your choice):
Code: [Select]
(setq *AcadApp* (vlax-get-acad-object))
; Only ACAD menu
(defun ALE_Menu_ToolbarsSavePos ( / TmpLst OutLst LspOut FilPnt MnuNam)
  (vlax-for MnuGrp (vla-get-MenuGroups *AcadApp*)
    (if (= (strcase (setq MnuNam (vla-get-name MnuGrp))) "ACAD")
      (progn
        (vlax-for VlaFor (vla-get-Toolbars MnuGrp)
          (setq TmpLst (cons (list (vla-get-name VlaFor) (vla-get-visible VlaFor) (vla-get-top  VlaFor) (vla-get-left VlaFor) (vla-get-DockStatus VlaFor)) TmpLst))
        )
        (setq OutLst (cons (cons (strcase (vla-get-name MnuGrp)) TmpLst) OutLst)  TmpLst nil)
      )
    )
  )
  (and
    OutLst
    (progn
      (setq FilPnt (open (setq LspOut "Z:\\Temp\\$Cfg_Menu.lsp") "w"))
      (princ "'" FilPnt) (princ (vl-prin1-to-string OutLst) FilPnt)
      (close FilPnt)
      (alert (strcat "Toolsbars position saved on File: " LspOut))
    )
  )
  (princ)
)

Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #6 on: April 17, 2018, 05:27:27 PM »
Works OK for me, i get the expected list in the file.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #7 on: April 18, 2018, 02:40:54 AM »
Works OK for me, i get the expected list in the file.
Yes, but if you move a Toolbar and run (ALE_Menu_ToolbarsRecoverPos) does the Toolbar return to its position?

For those wishing to try these functions, I say that they do not upset the Toolbars that have not been moved.

Perhaps it is better to go in the system registry read, save and then restore its values?
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\...\Profiles\ProfileA\Toolbars]
"ACAD.AC_SMOOTH_MESH"="hide float 200 200 1"
"ACAD.AC_SMOOTH_MESH_PRIMITIVES"="hide float 200 200 1"
"ACAD.TB_DIMENSION"="hide float 100 130 1"
"ACAD.TB_DRAW"="hide left 0 0"
"ACAD.TB_DRAWORDER"="hide right 0 1"
"ACAD.TB_INQUIRY"="hide float 100 170 1"
"ACAD.TB_INSERT"="hide float 100 190 1"
"ACAD.TB_LAYOUTS"="hide float 100 350 1"
"ACAD.TB_MODIFY"="hide right 0 0"
...

Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #8 on: April 18, 2018, 05:11:32 AM »
Yes, but if you move a Toolbar and run (ALE_Menu_ToolbarsRecoverPos) does the Toolbar return to its position?

For those wishing to try these functions, I say that they do not upset the Toolbars that have not been moved.

Oops i'll test and report back.

Perhaps it is better to go in the system registry read, save and then restore its values?
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\...\Profiles\ProfileA\Toolbars]

I'm always leery about writing to the registry, having had mishaps twice because i wasn't paying attention.  :uglystupid2:

Exporting/Importing the keys via shell using regedit would be another option, plenty of scripts out there but i've never tried it.

Also accessing the registry would depend on whether the user has named Profiles or just uses a default, and what if there is more that one profile?

acad-object -> preferences -> profiles -> activeprofile   

should get you the "\ProfileA\" part for the active profile, but maybe exporting the entire tree from \Profiles\ would be the way to go.


Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #9 on: April 18, 2018, 05:46:50 AM »
Saves and restores as expected. :-)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #10 on: April 18, 2018, 01:10:25 PM »
Saves and restores as expected. :-)
What do you mean? that if you move a Toolbar and run (ALE_Menu_ToolbarsRecoverPos) the Toolbar return to its saved position?
I do not have this behaviour...


Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #11 on: April 18, 2018, 04:29:21 PM »
Saves and restores as expected. :-)
What do you mean? that if you move a Toolbar and run (ALE_Menu_ToolbarsRecoverPos) the Toolbar return to its saved position?
I do not have this behaviour...

Yes, i activated one hidden acad toolbar, and saved positions. I then moved the tool bar from centre screen to the left side and ran Restore. The toolbar was back in centre screen. Do you want me to test with more?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #12 on: April 18, 2018, 05:25:04 PM »
Saves and restores as expected. :-)
What do you mean? that if you move a Toolbar and run (ALE_Menu_ToolbarsRecoverPos) the Toolbar return to its saved position?
I do not have this behaviour...

Yes, i activated one hidden acad toolbar, and saved positions. I then moved the tool bar from centre screen to the left side and ran Restore. The toolbar was back in centre screen. Do you want me to test with more?
Yes, please.  :-)

1) move the tool bar from centre screen to the left side NOT FLOAT (DOCKED) and ran Restore

2) save positions then move a DOCKED tool bar into the center and ran Restore

Thanks again. :embarrassed:

Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #13 on: April 18, 2018, 07:42:18 PM »
Ok i've run a few test using the previously stored, (this included the floating toolbar in centre screen). My Profile loaded normally, without the saved centre screen toolbar.

1. I took another invisible "ACAD" toolbar and docked it to the left hand side having unlocked the docked toolbars. Restoring the saved toolbar positions removed the docked toolbar and reinstated the previously saved centre screen floating toolbar.

2. When i moved a previously docked "ACAD" toolbar and made it floating it also restored it to its previous location.

3. I unlocked the docked toolbars moved an "ACAD" toolbar from docked to float then locked both floating and docked toolbar positions. It restored the toolbar to it's previous position.

This only works with "ACAD" toolbars, since your newest "save position" code only processes the "ACAD" toolbars and not "Express Tools" as i mistakenly moved one and it didn't restore.

From my end it's working within the scope of the functions in 2012. Will test later in 2009.


Dlanor

  • Bull Frog
  • Posts: 263
Re: Save&Restore toolbars position
« Reply #14 on: April 19, 2018, 05:22:52 AM »
Same as above in 2009.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #15 on: April 19, 2018, 10:31:25 AM »
Same as above in 2009.
Thanks for your time. I have tested in 2013. I will test on Bricscad.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Save&Restore toolbars position
« Reply #16 on: April 19, 2018, 12:46:37 PM »
I just hard code where I want the toolbars to be placed. If I want a different location, I just revise the code.


Code: [Select]
(defun C:GDF  ()
  (cond ((= "BRICSCAD" (strcase (getvar 'product)))(GDF:BricsCAD))
        ((/= "BRICSCAD" (strcase (getvar 'product)))(GDF:AutoCAD)))
  (princ))
;;;
(defun GDF:BricsCAD  ()
  (setvar "INTERFEREOBJVS" "")
  (setvar "INTERFEREVPVS" "")
  (setvar "plotoutputpath" (getvar "dwgprefix"))
  (setvar "cmddia" 1) ;command dialog box on
  (setvar "filedia" 1) ;file dialog box on   
  (setvar "pickbox" 5)
   (setvar "snapmode" 0)
  (princ "\n*** Fowler's Standard Preferences Settings ***")
  (command "toolbar" "ALL" "hide")
  (command "toolbar" "STANDARD" "show")
  (command "toolbar" "LAYERS" "show")
  (command "toolbar" "arch.arch_program" "show")
  (command "toolbar" "arch.arch_sset" "show")
  (command "toolbar" "arch.arch_toolpalette" "show")
  ;;
  (command "toolbar" "STANDARD" "top" "0,0")
  (command "toolbar" "LAYERS" "top" "515,0")
  (command "toolbar" "arch.arch_program" "top" "825,0")
  (command "toolbar" "arch.arch_sset" "top" "900,0")
  (command "toolbar" "arch.arch_toolpalette" "top" "950,0")
  (princ "\n***    Fowler's Standard Toolbar Setup     ***")
  (princ))
;;
(defun GDF:AutoCAD  ()
  (setenv "PlotToFilePath" (getvar "DWGPREFIX"))
  ;;(command "_-view" "_top")
  ;;(if (= (getvar "CTAB") "FullSize")(command "layout" "rename" "FullSize" "."))
  (setvar "cmddia" 1) ;command dialog box on
  (setvar "filedia" 1) ;file dialog box on
  ;;(command "-layer" "Plot" "N" "JUNK,*CODE*,*-AREA*,*-SF*" "")
  ;;(setenv "username" "GDF") 
  (if (> (getvar "ribbonstate") 0)
    (command "ribbonclose"))
  (if (tblsearch "layer" "Defpoints")
    (progn
      (if (or (= (getvar "clayer") "DEFPOINTS") (= (getvar "clayer") "Defpoints"))
        (command ".layer" "s" "0" ""))))
  (setvar "SHORTCUTMENU" 0) ;reset to autocad 14 behavior
  (setvar "aperture" 5)
  (setvar "pickbox" 5)
  (setvar "snapmode" 0)
  ;;(vla-put-displayscrollbars (vla-get-display (vla-get-preferences (vlax-get-acad-object))) :vlax-false)
  (princ "\n*** Fowler's Standard Preferences Settings ***")
  (setvar "cmdecho" 0)
  (setenv "CmdVisLines" "1")
  (command "toolbar" "ALL" "hide")
  (command "toolbar" "acad.TB_STANDARD" "show")
  (command "toolbar" "acad.TB_LAYER" "show")
  (command "toolbar" "arch.arch_program" "show")
  (command "toolbar" "arch.arch_sset" "show")
  (command "toolbar" "arch.arch_toolpalette" "show")
  ;;
  (command "toolbar" "acad.TB_STANDARD" "top" "0,0")
  (command "toolbar" "acad.TB_LAYER" "top" "515,0")
  (command "toolbar" "arch.arch_program" "top" "825,0")
  (command "toolbar" "arch.arch_sset" "top" "900,0")
  (command "toolbar" "arch.arch_toolpalette" "top" "950,0")
  (cond ((>= (distof (substr (getvar "acadver") 1 4)) 17.2)
         (setvar "menubar" 1)))
  (setvar "lockui" 5) 
  (princ "\n***    Fowler's Standard Toolbar Setup     ***")
  (princ))

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #17 on: April 19, 2018, 03:53:51 PM »

I just hard code where I want the toolbars to be placed. If I want a different location, I just revise the code.
...
Ok, I will test your method. Thanks.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Save&Restore toolbars position
« Reply #18 on: April 19, 2018, 04:25:04 PM »
Don't forget to FLOAT the toolbar first...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Save&Restore toolbars position
« Reply #19 on: May 28, 2018, 03:44:28 PM »
It's been a while ... I tried a solution, this is the one that produces the best result but often you need to launch it several times to get the initial position  :x:
(try with at least two rows (ex bottom) and two columns (ex left))
Code: [Select]
(setq *AcadApp* (vlax-get-acad-object))
; New version 2018/05/30
;(ALE_Menu_ToolbarsSavePos)
;
(defun ALE_Menu_ToolbarsSavePos ( / TmpLst OutLst LspOut FilPnt TlbIdx TlbDck TlbTop TlbLft)
  (vlax-for MnuGrp (vla-get-MenuGroups *AcadApp*)
    (vlax-for VlaFor (vla-get-Toolbars MnuGrp)
      (setq
        TlbDck (vla-get-DockStatus VlaFor)   TlbLft (vla-get-left VlaFor)   TlbTop (vla-get-top  VlaFor)
        TlbIdx (atoi (strcat (itoa TlbDck) (itoa TlbLft) (itoa TlbTop)))
        TmpLst (cons (list TlbIdx (vla-get-name VlaFor) TlbDck TlbLft TlbTop (= :vlax-true (vla-get-visible VlaFor))) TmpLst)
      )
    )
    (setq
      TmpLst (vl-sort TmpLst '(lambda (a b) (> (car a) (car b))))
      OutLst (cons (cons (strcase (vla-get-name MnuGrp)) TmpLst) OutLst)
      TmpLst nil
    )
  )
  (and
    OutLst
    (progn
      (setq FilPnt (open (setq LspOut "Z:\\Temp\\$Cfg_Menu.lsp") "w"))
      (princ "'" FilPnt) (princ (vl-prin1-to-string (reverse OutLst)) FilPnt)
      (close FilPnt)
      (alert (strcat "Asso message:\n\nPosizione Toolsbars salvata nel File: " LspOut))
    )
  )
  (princ)
)
;
;(repeat 5 (ALE_Menu_ToolbarsRecoverPos))
;
(defun ALE_Menu_ToolbarsRecoverPos ( / MnuGrp TlbInf MnuObj TbsObj TlbObj PosInf)
  (setq
    MnuGrp (vla-get-menugroups *AcadApp*)
    TlbInf (load "Z:\\Temp\\$Cfg_Menu.lsp")
    PosLst '((0 . "_TOP") (1 . "_BOTTOM") (2 . "_LEFT") (3 . "_RIGHT") (4 . "_FLOAT"))
  )
  (foreach ForMnu TlbInf
    (and
      (cdr ForMnu)
      (setq MnuObj (ALE_Utl_GetItem MnuGrp (car ForMnu)))
      (setq TbsObj (vla-get-Toolbars MnuObj))
      (foreach ForElm (cdr ForMnu)
        (if (setq TlbObj (ALE_Utl_GetItem TbsObj (cadr ForElm)))
          (progn
            (if (nth 5 ForElm)
              (progn
                (vla-put-visible TlbObj :vlax-true)
                (setq PosInf (assoc (caddr ForElm) PosLst))
                (vla-Float TlbObj 0 0 1)
                (if (or #BCFlg (/= 4 (car PosInf)))
                  (command "_TOOLBAR" (cadr ForElm) (cdr PosInf) (strcat (itoa (cadddr ForElm)) "," (itoa (nth 4 ForElm))))
                  (command "_TOOLBAR" (cadr ForElm) (cdr PosInf) (strcat (itoa (cadddr ForElm)) "," (itoa (nth 4 ForElm))) "1")
;                 (or (= (vla-get-DockStatus TlbObj) (caddr ForElm))  (vla-Dock TlbObj (caddr ForElm)))
;                 (vla-put-left TlbObj (cadddr ForElm)) (vla-put-top TlbObj (nth 4 ForElm)) ; not used
                )
              )
              (vla-put-visible TlbObj :vlax-false)
            )
          )
          (vla-put-visible TlbObj :vlax-false)
        )
      )
    )
  )
  (princ)
)
Edit: New version 2018/05/30