Autocad 2015 create layout

Autocad 2015 create layout

marcwalen
Participant Participant
1,228 Views
5 Replies
Message 1 of 6

Autocad 2015 create layout

marcwalen
Participant
Participant

I'm trying to migrate my code from 2012 to 2015. I'm having problems with a part of my code where I try to create a layout. This part is a copy of the example found here: http://help.autodesk.com/ . 

 

My code:

 

// Reference the Layout Manager
                        LayoutManager acLayoutMgr = LayoutManager.Current;

                        // Create the new layout with default settings
                        ObjectId objID = acLayoutMgr.CreateLayout("Tekstborden 1");
                        
                        // Open the layout
                        Layout acLayout = transaction.GetObject(objID, OpenMode.ForWrite) as Layout;

                        try
                        {
                            PlotSettingsValidator plotSetVal = PlotSettingsValidator.Current;
                            plotSetVal.RefreshLists(acLayout);
                            System.Collections.Specialized.StringCollection sheetList = plotSetVal.GetPlotStyleSheetList();
                            foreach (String str in sheetList)
                            {
                                if (str.ToLower().Equals("_standaard.ctb"))
                                {
                                    //find out if drawing is using ctb
                                    System.Object test = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("PSTYLEMODE");
                                    if (test.ToString().Equals("1"))
                                    {
                                        // drawing is using ctb so go ahead and
                                        //assign acad.ctb to the layout

                                        //acLayout.UpgradeOpen();
                                        plotSetVal.SetCurrentStyleSheet(acLayout, str);
                                        acLayout.DowngradeOpen();
                                    }
                                }
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

 This works on 2012. But on 2015 after 

ObjectId objID = acLayoutMgr.CreateLayout("Tekstborden 1");

the objID = null. The only exeption I could find while debugging is: 'ObjectLeftOnDisk = 'objID.ObjectLeftOnDisk' threw an exception of type 'System.AccessViolationException'' ; 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

 

Can anyone tell me whats going on?

0 Likes
Accepted solutions (1)
1,229 Views
5 Replies
Replies (5)
Message 2 of 6

Dale.Bartlett
Collaborator
Collaborator

Only just now moving to 2015. I include in mine (not tested 2015):

DocumentLock doclock = doc.LockDocument();
...
doclock.Dispose();

 

Does this help? http://forums.autodesk.com/t5/net/layout-import-code-fails-in-autocad-2015/td-p/5224441 

 

Dale

 




______________
Yes, I'm Satoshi.
0 Likes
Message 3 of 6

marcwalen
Participant
Participant

I already have it enclosed in:

using (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                
            }

 It doesn't seem to make any difference wether I lock the document or not. I get same result either way.

0 Likes
Message 4 of 6

autodaug
Autodesk
Autodesk
Accepted solution

Sounds like it may be the same problem as this:

http://forums.autodesk.com/t5/net/need-help-programming-around-2015-api-createlayout-big/td-p/548437...

 

The workarounds found so far are to use COM, or to avoid accessing the layout dictionary beforehand (get layout names from the block table instead).

 

0 Likes
Message 5 of 6

SENL1362
Advisor
Advisor
Maybe .NET doesn't like these Dutch billboards, try "TextBoards" instead 🙂

Could you try to copy or import a layout instead of create and then modify to you're needs. Create Layout without using the LayoutManager didn't work out very well in previous versions of AutoCAD especially when assigning Named Plot Styles.
0 Likes
Message 6 of 6

marcwalen
Participant
Participant

Yes, exact same problem. I managed to 'solve' this by putting the part of creating the layout in its own seperate class. Thanks all!

0 Likes