+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 24
  1. #11
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    Registered forum members do not see this ad.

    FWIW - There's a .NET sample for exporting Command Settings to .XML already included in the Sample folder for your installation here:

    Code:
    (defun c:C3dCsSample (/ folder)
      (if
        (setq folder
               (findfile
                 (strcat
                   (vl-registry-read
                     (strcat "HKEY_LOCAL_MACHINE\\"
                             (if vlax-user-product-key                      ; If 2013
                               (vlax-user-product-key)                      ; Use 2013 function
                               (vlax-product-key)                           ; Use legacy function
                             )
                     )
                     "ACADLOCATION"
                   )
                   "\\Sample\\Civil 3D API\\DotNet\\CSharp\\CommandSettingsSample"
                 )
               )
          )
        (startapp "explorer" folder)
        (prompt "\n** Folder not found ** ")
      )
      (princ)
    )
    I've taken the liberty of compiling this sample .NET code to .NET 3.5, which should work for Civil 3D 2010 and newer. Simply rename the file from CommandSettings.txt to CommandSettings.dll

    Once you've NETLOADed the assembly, simply enter in the CommandMethod name of "ExportCS"

    Again, this is only a sample... For those who would prefer (as I do), to compile the source code themselves:

    Code:
    using System;
    using System.Text;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.Civil.ApplicationServices;
    using Autodesk.Civil.Settings;
    using System.Reflection;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.EditorInput;
    using System.Collections;
    using Autodesk.AutoCAD.Windows;
    using System.IO;
    
    namespace CommandSettingsSample {
        /// <summary>
        /// This sample illustrates the Civil 3D .NET Command Settings API
        /// It exports a list of all command settings in one Civil document as
        /// an xml document.
        /// </summary>
        public class CSSample {
    
            public Editor ed;
            public StringBuilder xml;
            public String file;
    
            /// <summary>
            /// Command to export command settings.
            /// </summary>
            [CommandMethod("ExportCS")]
            public void ExportCommandSettings() {
                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = "XML Files (*.xml)|*.xml";
                sfd.DefaultExt = "xml";
                sfd.FileName = "cmd_settings.xml";           
                sfd.Title = "Export command settings";
               
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                    file = sfd.FileName;
                } else {
                    return;
                }
    
                CivilDocument doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
                ed = Application.DocumentManager.MdiActiveDocument.Editor;
                xml = new StringBuilder();
    
    
                // Get all the settings defined in AeccDbMgd using Reflection
                Type[] types = new Type[] { typeof(Autodesk.Civil.Settings.SettingsRoot) };
                Assembly aeccdbmgd = typeof(CivilDocument).Module.Assembly;
                Type[] types2 = aeccdbmgd.GetTypes();
                foreach (Type t in types2) {
                    // A command setting's class name contains "SettingsCmd", and is derived from SettingsAmbient (or
                    // derived from a child of SettingsAmbient) 
                    if (t.Name.Contains("SettingsCmd")
                        && (t.BaseType.Name.Contains("SettingsAmbient")
                        || t.BaseType.BaseType.Name.Contains("SettingsAmbient"))) {
                        ed.WriteMessage("Command Setting found: " + t.Name + "\n");
                        xml.Append( String.Format("<CommandSetting name=\"{0}\">\n", t.Name));
    
                        try {
    
                            ConstructorInfo conInfo = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, types, null);
                            object[] s4 = new object[] { doc.Settings };
    
                            SettingsAmbient settingsAmbient = (SettingsAmbient)conInfo.Invoke(s4);
                            // This gets the properties of the class and adds it to the xml string
                            GetPropsOfObj(settingsAmbient, 2);
    
                        } catch (System.Exception e) {
                            ed.WriteMessage("Error: " + e.Message + "\n" + e.GetType() + "\n");
                        }
    
                        xml.Append( "</CommandSetting>\n");
                    }
                }
    
                using (var sw = new StreamWriter(file)) {
                    sw.Write(xml.ToString());
                    sw.Close();
                }
                ed.WriteMessage("DONE\n");
            }
    
            /// <summary>
            /// Gets the properites for an object using Reflection
            /// </summary>
            /// <param name="obj">The object to inspect</param>
            /// <param name="tab">Tab level for xml indentation</param>
            private void GetPropsOfObj(Object obj, int tab) {
                String space = " ".PadRight(tab);
                Type type = obj.GetType();
                PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo propInfo in properties) {
    
                    object prop = type.InvokeMember(propInfo.Name, BindingFlags.GetProperty, null, obj, new object[0]);
    
                    if (prop.GetType().Name.Contains("Settings")) {
                        xml.Append(String.Format(space + "<Property name=\"{0}\">\n", propInfo.Name));
                        GetPropsOfObj(prop, tab + 3);
                        xml.Append( space + "</Property>\n");
                    } else if (prop.GetType().Name.Contains("Property")) {
                        Type propType = prop.GetType();
                        object val = propType.InvokeMember("Value", BindingFlags.GetProperty, null, prop, new object[0]);
                        xml.Append( String.Format(space + "<Property name=\"{0}\" value=\"{1}\"/>\n", propInfo.Name, val.ToString()));
                    } else {
                        ed.WriteMessage("Didn't process: {0} {1}\n", propInfo.Name, propInfo.PropertyType.ToString());
                    }
                }
            }
        }
    }
    HTH
    Attached Files
    "Potential has a shelf life." - Margaret Atwood

  2. #12
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    Forgot to mention, that the resultant .XML file may not be properly read by simply double clicking on it, as (in my case using an OOTB .DWT to test), some of the string information was written to file as:

    Code:
    <snip>
    
      <Property name="NameFormat">
         <Property name="SheetFile" value="<[View Frame Group Name(CP)]> - (<[Next Counter(CP)]>)"/>
         <Property name="Layout" value="Sheet - (<[Next Counter(CP)]>)"/>
         <Property name="MatchLine" value="ML - (<[Next Counter(CP)]>)"/>
         <Property name="ViewFrame" value="VF - (<[Next Counter(CP)]>)"/>
         <Property name="ViewFrameGroup" value="VFG - <[View Frame Group Alignment Name(CP)]> - (<[Next Counter(CP)]>)"/>
      </Property>
    
    <snip>
    ... Which causes the XML file to be unreadable to non-XML enabled readers, such as Visual Studio, Notepad++, etc..
    "Potential has a shelf life." - Margaret Atwood

  3. #13
    Full Member sandiegophil's Avatar
    Computer Details
    sandiegophil's Computer Details
    Operating System:
    Windows 7 64bit
    Computer:
    HP z600
    RAM:
    16gb
    Graphics:
    nvidia quadro fx 4800 1gb
    Using
    Civil 3D 2012
    Join Date
    Feb 2009
    Location
    San Diego, CA
    Posts
    79

    Default

    RenderMan,

    I have tried several times with no luck. this is the message i am receiving.

    Command: netload
    Cannot load assembly. Error details: System.IO.FileLoadException: Could not
    load file or assembly 'file:///C:\Users\pendrizz\Desktop\CommandSettings.dll'
    or one of its dependencies. Operation is not supported. (Exception from
    HRESULT: 0x80131515)
    File name: 'file:///C:\Users\pendrizz\Desktop\CommandSettings.dll' --->
    System.NotSupportedException: An attempt was made to load an assembly from a
    network location which would have caused the assembly to be sandboxed in
    previous versions of the .NET Framework. This release of the .NET Framework
    does not enable CAS policy by default, so this load may be dangerous. If this
    load is not intended to sandbox the assembly, please enable the
    loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569
    for more information.
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyN ame fileName, String
    codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
    StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
    forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadAsse mblyName(AssemblyName
    assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
    forIntrospection, Boolean suppressSecurityChecks)
    at System.Reflection.RuntimeAssembly.InternalLoadFrom (String assemblyFile,
    Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm
    hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks,
    StackCrawlMark& stackMark)
    at System.Reflection.Assembly.LoadFrom(String assemblyFile)
    at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(Stri ng fileName)
    at loadmgd()

  4. #14
    Full Member sandiegophil's Avatar
    Computer Details
    sandiegophil's Computer Details
    Operating System:
    Windows 7 64bit
    Computer:
    HP z600
    RAM:
    16gb
    Graphics:
    nvidia quadro fx 4800 1gb
    Using
    Civil 3D 2012
    Join Date
    Feb 2009
    Location
    San Diego, CA
    Posts
    79

    Default

    caddcop,

    I contacted them and was told that they do not support C3D 2012 as of yet.

    thanks for all your help.

    Phil

  5. #15
    Full Member caddcop's Avatar
    Computer Details
    caddcop's Computer Details
    Operating System:
    WinXP
    Computer:
    Lenovo ThinkPad Laptop - Dual Screens on Docking Station
    Monitor:
    Dell and Viewsonic 22' Widescreens
    Discipline
    Civil
    caddcop's Discipline Details
    Occupation
    CADD Manager - Civil/Survey
    Discipline
    Civil
    Details
    Working with Land Desktop 2008 and 2009, Civil 3D 2009, 2010, 2011, 2012 & 2013
    Using
    Land Desktop 2009
    Join Date
    Sep 2009
    Location
    Maryland (DC Suburbs)
    Posts
    94

    Default

    In this zip file is the xml from that tool. I added a line to assign a stylesheet to it and have included the stylesheet in the zip file. If you open the xml file in Internet Explorer, Firefox or even Excel, you will see some tables of the first few nodes of the xml file.
    The statistics from Notepad++ are as follows:
    2,087,955 bytes
    2,051,385 non blank characters
    225,968 words
    18286 lines
    That's a lot of data.
    This is from one of the NCS Imperial Templates delivered with 2011
    BTW, this is a very incomplete and preliminary stylesheet. Ideally, the various data that is setup using similar formats can be processed via a shared xsl template.
    To read files from 2009 or earlier or 2012 and later would require some other tool.
    It would appear that the dll from the other reply creates a different xml file. I wonder if there are settings in the functions, properties or methods that would correct of modify the output?
    Attached Files
    Last edited by caddcop; 5th Sep 2012 at 11:52 am. Reason: ADDITIONAL INFO

  6. #16
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,780

    Default

    Hi Renderman same problem get the long error message 2013 it may be something not loaded as we are externally controlled on what turns up on our pc's could it be a missing library file. We did have a problem and had to load a new .net library for something else.
    A man who never made mistakes never made anything

  7. #17
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    Unfortunately, as I stated above, I compiled this code to .NET 3.5 for 2010 database format (which covers 2010, 2011, and 2012). 2013 is .NET 4.0, and requires an assembly reference to AcCoreMgd.dll, and may or may not include an assembly reference to XAML.dll (.NET 4.0 includes this automatically in new Visual Studio projects in my template).

    I do not have Civil 3D 2013 installed, so I am missing the appropriate references to AecBaseMgd.dll, and AeccDbMgd.dll (if memory serves) for 2013 specifically to compile, hence the source code wing posted above for others to compile.

    HTH
    Last edited by BlackBox; 10th Sep 2012 at 12:40 am. Reason: Typos
    "Potential has a shelf life." - Margaret Atwood

  8. #18
    Forum Newbie
    Using
    Civil 3D 2013
    Join Date
    Sep 2012
    Posts
    5

    Default

    Quote Originally Posted by sandiegophil View Post
    I have tried several times with no luck. this is the message i am receiving.

    Command: netload
    Cannot load assembly. Error details: System.IO.FileLoadException: Could not
    load file or assembly 'file:///C:\Users\pendrizz\Desktop\CommandSettings.dll'
    Phil,
    That message comes from 1, of 2, reasons that I am aware of. One being that you tried to load it from a network location, which it doesn't appear you are doing. The other is that you did not Unblock the ZIP file before extracting the dll. This is the most common problem, especially with Win7 since it likes to protect you from yourself so well. Anytime a file is downloaded, either from the 'net itself, or via an email attachment, if Win7 senses the file contains exe or dll files, Win7 will Block the files from running. To fix that, before any files are extracted(if a zip) or run (in the case of a renamed file), right-click the file, select Properties, at the bottom of the General tab should be a button labeled Unblock. Click that, close the properties, then extract the files (make sure to delete any files previously extracted first).

  9. #19
    Forum Newbie
    Using
    Civil 3D 2013
    Join Date
    Sep 2012
    Posts
    5

    Default

    Renderman, for the OP's wish for the Styles to also be output, there is another sample provided which can be modified to do just that. Look at the Compare Styles sample, it has code to regenerate an ArrayList of all styles which can then be used to create an XML file (I've done this for a company) or any other format file (txt, csv, etc.).

    As for the Command Settings sample not outputting correctly formatted XML code, I used this as an excuse to learn how to use the .NET XML Document tools. Shoot me an email if you want more info.

  10. #20
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    3,780

    Default

    Registered forum members do not see this ad.

    Did the unblock etc netloaded now no error messages but nothing happens when you run "exportcs" "unknown command"
    A man who never made mistakes never made anything

Similar Threads

  1. generate part-list/order-list in autocad 2011LT
    By Borken in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 12th Jul 2012, 09:39 am
  2. How do I generate a scene object list
    By I AM CHUPA in forum CAD Management
    Replies: 1
    Last Post: 15th Jul 2011, 04:57 pm
  3. Noob Need Help - Can generate Bill of Materials List?
    By MrRee in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 20th Jul 2009, 11:28 am
  4. Replies: 0
    Last Post: 15th Nov 2006, 06:10 pm
  5. Generate a drawing from a list of coordinates
    By braedan51 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 15th Jul 2006, 09:41 pm

Bookmarks

Posting Permissions

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