LispFunction - ExportTo Styles

LispFunction - ExportTo Styles

Civil3DReminders_com
Mentor Mentor
581 Views
1 Reply
Message 1 of 2

LispFunction - ExportTo Styles

Civil3DReminders_com
Mentor
Mentor

 

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. 

 

Any ideas on what could be causing this? Do I have to open the drawing? 

 

        [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 < 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;
        }

 

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
582 Views
1 Reply
Reply (1)
Message 2 of 2

Civil3DReminders_com
Mentor
Mentor

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.

 

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.

 

TestBlah.png

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes