<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: LispFunction - ExportTo Styles in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/lispfunction-exportto-styles/m-p/7642668#M11897</link>
    <description>&lt;P&gt;I can't seem to find a pattern on when it works and doesn't. I change all of the compenent displays it stops working. Run it 3 times, on the fourth it stops working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like it might be opening the drawing without a document. If I open the drawing fully then it appears to work. This sucks and should not be marked as Solved until the bug is fixed in CIvil 3D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TestBlah.png" style="width: 687px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/442066i6D287E240D140058/image-size/large?v=v2&amp;amp;px=999" role="button" title="TestBlah.png" alt="TestBlah.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2017 17:44:14 GMT</pubDate>
    <dc:creator>Civil3DReminders_com</dc:creator>
    <dc:date>2017-12-21T17:44:14Z</dc:date>
    <item>
      <title>LispFunction - ExportTo Styles</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/lispfunction-exportto-styles/m-p/7640118#M11896</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some code I'm creating that exports some styles from one drawing to another. It works great a couple of times running it in the same drawing and then stops working. The stop working is that the code is gone through, returns to Civil 3D, but doesn't do the changes. It always makes it to the Commit() of the transaction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas on what could be causing this? Do I have to open the drawing?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [LispFunction("CtStyleImport")]
        public static ResultBuffer CtStyleImportCommand(ResultBuffer rbArgs)
        {
            // (CtStyleImport "C:\\Ct\\HQ\\C3D_2016\\Templates\\Ct_2016_Design_Other_Styles.dwt" 
            //        (list "LabelStyles.AlignmentLabelStyles.StationOffsetLabelStyles" "CR Main FL TR_Left" "CR Local TRC FL Lip SW_Down")
            //        (list "AlignmentStyles" "CAiCE" "Align - Mainline [Analysis]")
            //        (list "GetSurveyLabelStyles().LineLabelStyles" "Standard")
            // )

            // (CtStyleImport "C:\\Ct\\HQ\\C3D_2016\\Templates\\Ct_2016_Design_Other_Styles.dwt" (list "LabelStyles.AlignmentLabelStyles.StationOffsetLabelStyles" "CR Main FL TR_Left" "CR Local TRC FL Lip SW_Down")(list "AlignmentStyles" "CAiCE" "Align - Mainline [Analysis]")(list "GetSurveyLabelStyles().LineLabelStyles" "Standard"))

            var rstBuffer = new ResultBuffer();

            if (rbArgs == null)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nNo objects passed");
            }

            var rbArgsList = rbArgs.AsArray().ToList();
            
            try
            {
                var dwgPathAndName = rbArgsList[0].Value.ToString();

                if (!File.Exists(dwgPathAndName))
                {
                    rstBuffer.Add(new TypedValue((int)DxfCode.Text, "Drawing not found."));
                    return rstBuffer;
                }

                var civDoc = CivilApplication.ActiveDocument;
                
                var doc = Application.DocumentManager.MdiActiveDocument;
                var dbTo = doc.Database;
                var ed = doc.Editor;

                using (var tr = dbTo.TransactionManager.StartTransaction())
                {
                    // civDoc.Styles.LabelStyles.GetSurveyLabelStyles().LineLabelStyles;

                    using (var fromDb = new Database(false, true))
                    {
                        fromDb.ReadDwgFile(dwgPathAndName, FileOpenMode.OpenForReadAndAllShare, true, "");

                        var civDocFrom = CivilDocument.GetCivilDocument(fromDb);

                        for (int i = 1; i &amp;lt; rbArgsList.Count(); i++)
                        {
                            if (rbArgsList[i].TypeCode == (int)LispDataType.ListBegin)
                            {
                                try
                                {
                                    var styleColl = GetStyleCollection(rbArgsList, civDocFrom, i);

                                    var styleNamesToTransfer = GetStyleNames(rbArgsList, ref i);

                                    var styleObjIdsToTransfer = new ObjectIdCollection();

                                    foreach (var styleName in styleNamesToTransfer)
                                    {
                                        if (styleColl.Contains(styleName))
                                        {
                                            styleObjIdsToTransfer.Add(styleColl[styleName]);
                                            rstBuffer.Add(new TypedValue((int)DxfCode.Text, "Imported: " + styleName));
                                        }
                                        else
                                        {
                                            rstBuffer.Add(new TypedValue((int)DxfCode.Text, "Not Found: " + styleName));
                                        }
                                    }

                                    StyleBase.ExportTo(styleObjIdsToTransfer, dbTo, StyleConflictResolverType.Override);
                                }
                                catch (System.Exception ex)
                                {
                                    rstBuffer.Add(new TypedValue((int)DxfCode.Text, ex.Message));
                                }
                            }

                        }
                    }

                    tr.Commit();
                }

            }
            catch (System.Exception ex)
            {
                rstBuffer.Add(new TypedValue((int)DxfCode.Text, ex.Message));
            }

            return rstBuffer;
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 22:59:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/lispfunction-exportto-styles/m-p/7640118#M11896</guid>
      <dc:creator>Civil3DReminders_com</dc:creator>
      <dc:date>2017-12-20T22:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: LispFunction - ExportTo Styles</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/lispfunction-exportto-styles/m-p/7642668#M11897</link>
      <description>&lt;P&gt;I can't seem to find a pattern on when it works and doesn't. I change all of the compenent displays it stops working. Run it 3 times, on the fourth it stops working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like it might be opening the drawing without a document. If I open the drawing fully then it appears to work. This sucks and should not be marked as Solved until the bug is fixed in CIvil 3D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TestBlah.png" style="width: 687px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/442066i6D287E240D140058/image-size/large?v=v2&amp;amp;px=999" role="button" title="TestBlah.png" alt="TestBlah.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 17:44:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/lispfunction-exportto-styles/m-p/7642668#M11897</guid>
      <dc:creator>Civil3DReminders_com</dc:creator>
      <dc:date>2017-12-21T17:44:14Z</dc:date>
    </item>
  </channel>
</rss>

