See the top rated post in this thread. Click here

Page 4 of 5 FirstFirst 12345 LastLast
Results 31 to 40 of 46

Thread: Page Setup Manager

  1. #31
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Building on my earlier post, here's an incremental update which makes available a LispFunction Method named vla-SetActivePageSetup.

    A help file for this function is attached to the bottom of this post. 2011 .chm colors used. The help file is in HTM format, but a .TXT extension has been added, as .HTM is not a supported upload file format here at AUGI.

    Please note that while I have tested this enough to determine that it functions as designed (tested for 2010-2012, using Civil 3D), I have not yet had an opportunity to test this via ObjectDBX, etc., so constructive criticism is welcomed.



    vla-SetActivePageSetup

    Sets a named page setup active for a given layout by name

    Code:
    (vla-SetActivePageSetup layoutName pageSetupName)


    Arguments

    layoutName

    A string specifying the name of a layout to apply the named page setup.


    pageSetupName

    A string specifying the page setup to apply to the layout.



    Return Values

    Nil if either the layoutName, or pageSetupName cannot be found. Otherwise, T if successful.



    Example

    Code:
    (foreach layoutname (layoutlist)
      (vla-SetActivePageSetup layoutname “YourPageSetupName”)
    )


    Like me, most of you would prefer to compile the .NET assembly yourself, so here's the source code for your use:

    Code:
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Runtime;
    
    using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
    
    [assembly: CommandClass(typeof(BlackBox.AutoCAD.PageSetup.Commands))]
    
    namespace BlackBox.AutoCAD.PageSetup
    {
        public class Commands
        {
            [LispFunction("vla-SetActivePageSetup")]
            public bool vlaSetActivePageSetup(ResultBuffer resbuf)
            {
                Document doc = acApp.DocumentManager.MdiActiveDocument;
    
                Database db = doc.Database;
    
                bool ret = false;
    
                try
                {
                    if (resbuf == null)
                        throw new TooFewArgsException();
    
                    TypedValue[] args = resbuf.AsArray();
                    if (args.Length < 1)
                        throw new TooFewArgsException();
    
                    if (args.Length > 2)
                        throw new TooManyArgsException();
    
                    if (args[0].TypeCode != (int)LispDataType.Text)
                        throw new ArgumentTypeException("stringp", args[0]);
    
                    if (args.Length == 2 && args[1].TypeCode != (int)LispDataType.Text)
                        throw new ArgumentTypeException("stringp", args[1]);
    
                    string layoutName = args[0].Value.ToString().ToUpper();
                    string pageSetupName = args[1].Value.ToString().ToUpper();
    
                    using (DocumentLock dl = doc.LockDocument())
                    {
                        using (Transaction tr =
                            doc.Database.TransactionManager.StartOpenCloseTransaction())
                        {
                            DBDictionary layoutDic =
                                tr.GetObject(doc.Database.LayoutDictionaryId,
                                OpenMode.ForRead, false) as DBDictionary;
    
                            if (layoutDic != null)
                            {
                                foreach (DBDictionaryEntry entry in layoutDic)
                                {
                                    Layout layout =
                                        tr.GetObject(entry.Value,
                                        OpenMode.ForRead) as Layout;
    
                                    if (layout != null && 
                                        layout.LayoutName.ToUpper() == layoutName)
                                    {
                                        DBDictionary acPlotSettings =
                                            tr.GetObject(db.PlotSettingsDictionaryId,
                                            OpenMode.ForRead) as DBDictionary;
    
                                        if (acPlotSettings.Contains(pageSetupName))
                                        {
                                            PlotSettings ps =
                                                (PlotSettings)tr.GetObject(
                                                    acPlotSettings.GetAt(pageSetupName), OpenMode.ForRead);
    
                                            layout.UpgradeOpen();
    
                                            layout.CopyFrom(ps);
    
                                            ret = true;
                                        }
                                    }
                                }
                            }
    
                            tr.Commit();
                        }
                    }
                }
    
                catch (LispException ex)
                {
                    doc.Editor.WriteMessage("\n; error: LispException: " + ex.Message);
                }
    
                catch (System.Exception ex)
                {
                    doc.Editor.WriteMessage("\n; error: System.Exception: " + ex.Message);
                }
    
                return ret;
            }
        }
    
        // Special thanks to Gile, for his work on the following Exception helpers
        class LispException : System.Exception
        {
            public LispException(string msg) : base(msg) { }
        }
    
        class TooFewArgsException : LispException
        {
            public TooFewArgsException() : base("too few arguments") { }
        }
    
        class TooManyArgsException : LispException
        {
            public TooManyArgsException() : base("too many arguments") { }
        }
    
        class ArgumentTypeException : LispException
        {
            public ArgumentTypeException(string s, TypedValue tv)
                : base(string.Format(
                "invalid argument type: {0}: {1}",
                s, tv.TypeCode == (int)LispDataType.Nil ? "nil" : tv.Value))
            { }
        }
    }
    [Edit] 2013-04-16, Namespace changed from AUGI.Sample.PageSetup to BlackBox.AutoCAD.PageSetup.

    [Edit] - 2016-08-19, App .bundle updated to support 2015, 2016, and 2017.
    Attached Files Attached Files
    Last edited by BlackBox; 2016-08-19 at 05:32 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  2. #32
    100 Club
    Join Date
    2004-10
    Location
    Scotland
    Posts
    102
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Irné,
    Thanks for sharing the routines, the command line & dialogue versions both work a treat with ACAD 2013.
    This should be a routine incorporated into AutoCAD as standard - it's that useful.
    For those like me who had initial problems with the dialogue versions, make sure you place/add the DCL file location in the ACAD support path.

  3. #33
    100 Club
    Join Date
    2005-06
    Location
    Atlanta
    Posts
    118
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Thanks Blackbox, this is awesome

  4. #34
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Quote Originally Posted by Julesagain View Post
    Thanks Blackbox, this is awesome
    You're welcome; I'm happy to help.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #35
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    FWIW -

    Attached to the bottom of my post here, is an Autoloader .bundle for 2012 (R18.2), 2013 (R19.0), and 2014 (R19.1)... Simply unzip to %AppData%\Autodesk\ApplicationPlugins.

    ** Also important to note, is that ./Contents/Windows/2012/bbox_AcPageSetup18.dll has been compiled to .NET 3.5 which makes it available for both 2010 (R18.0), and 2011 (R18.1) as well... Since these versions do not support Autoloader, simply use NETLOAD Command, or Registry Loader.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #36
    Woo! Hoo! my 1st post
    Join Date
    2013-12
    Posts
    1
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Mr Blackbox, I am running Autocad 2010. I cannot find this folder where i should unzip to. Is it C:\Program Files\Autodesk\DWG TrueView 2012\Plugins ? And what should i put there ? Only this file?: "bbox_AcPageSetup18.dll" Grateful for any help...

  7. #37
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Quote Originally Posted by dan.jarrendal462249 View Post
    Mr Blackbox, I am running Autocad 2010. I cannot find this folder where i should unzip to. Is it C:\Program Files\Autodesk\DWG TrueView 2012\Plugins ? And what should i put there ? Only this file?: "bbox_AcPageSetup18.dll" Grateful for any help...
    Unfortunately, only AutoCAD 2012 and newer support Autoloader, so you'd want to use the NETLOAD Command to load the *18 assembly.

    You can store the assembly anywhere on your local disk, perhaps in a folder that is included in your Support File Search Path (SFSP)? You can also store, and load this assembly from the network, but there are other considerations... Let me know if you require this method.

    NETLOAD will allow you to load the .NET assembly into your session once... To load each time you start AutoCAD, you might add something like this to your Acad.lsp (as .NET assemblies need only be loaded once per session):

    Code:
    (command "._netload" "<YourFilePath>\\<NetAssemblyFileName>.dll")
    Another, more complex option, is to use a Registry loader... But we'll skip that for now.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  8. #38
    Member
    Join Date
    2006-12
    Posts
    10
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    I'm having a bit of trouble. I have the of LayoutTools.lsp loaded via acaddoc.lsp. When I type -mpagesetup at the command line I am able to step through the function just as I want. But then I want to automate it to run whenever a certain profile AutoCAD is started (by desktop icon). So I try putting this command further down in my acaddoc.lsp, but from that point on, everything fails. Also if I just copy/paste this line into the command line (when LayoutTools.lsp is successfully loaded), it also errors and says -mpagesetup Unknown command "-MPAGESETUP". Press F1 for help.

    (command "-mpagesetup" "*" "a0")

    Basically what I want to do is use the PSETUPIN command then -mpagesetup all through lisp and happening when the drawing opens, and be completely transparent to the user. Thank you.

  9. #39
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Quote Originally Posted by dtiemeyer View Post
    Basically what I want to do is use the PSETUPIN command then -mpagesetup all through lisp and happening when the drawing opens, and be completely transparent to the user.
    Not sure what version you're using, nor am I familiar with -MPAGESETUP Command, however that is exactly the purpose of this post.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  10. #40
    Member
    Join Date
    2008-09
    Posts
    3
    Login to Give a bone
    0

    Default Re: Page Setup Manager

    Thanks for sharing this great tools!

    I think there are some errors in the function "DataMerge"

    (subst comp data2) and
    (subst comp data1)

    are not correct.

    fixed lisp for the function "DataMerge" should be like this:

    Code:
    (defun DataMerge (lst1 lst2 comp / lst data1 data2 val1 val2 found)
      (setq lst (reverse lst1))
      (foreach data2 lst2
        (if	(setq val2 (cdr (assoc comp data2)))
    
          (progn
    	(setq found nil)
    	(foreach data1 lst1
    	  (if (= val2 (setq val1 (cdr (assoc comp data1))))
    	    (setq found t)
    	  ) ;_ end of if
    	) ;_ end of foreach
    	(if (not found)
    	  (setq lst (cons data2 lst))
    	) ;_ end of if
          ) ;_ end of progn
    
        ) ;_ end of if val2
      ) ;_ end of foreach
      (reverse lst)
    ) ;_ end of defun

Page 4 of 5 FirstFirst 12345 LastLast

Similar Threads

  1. Page Setup Manager Dialog
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2009-10-13, 04:53 AM
  2. page setup manager SLOW
    By cr_gixxer in forum ACA General
    Replies: 1
    Last Post: 2009-05-08, 10:05 PM
  3. Enhancement to Page Setup Manager
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2006-02-13, 05:08 PM
  4. Add Plot Stamp to Page Setup Manager
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2006-01-15, 05:25 AM
  5. Page Setup Manager
    By ejohnson.73328 in forum AutoCAD General
    Replies: 4
    Last Post: 2004-08-27, 02:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •