switch layout1 to layout2,and then layout3...

switch layout1 to layout2,and then layout3...

Anonymous
Not applicable
1,025 Views
3 Replies
Message 1 of 4

switch layout1 to layout2,and then layout3...

Anonymous
Not applicable

Dear All Guys:

I have a multi layout file, i want do something in layout1, switch to layout2,do something, and then  switch to layout3...

what i can do? i don‘t know how to switch layout.

 

Capture.PNG

0 Likes
Accepted solutions (1)
1,026 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant

Hi,

 

You can use the CTAB system variable:

 

Application.SetSystemVariable("CTAB", "Layout2");


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

Anonymous
Not applicable

Dear Sir:

My problem is I have 4 layouts, I want insert some information(eg.text) in each layout, but the following code only can insert it to first layout,

how to insert it to the others layout?

 

// Open the Block table for read
      BlockTable acBlkTbl;
      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                   OpenMode.ForRead) as BlockTable;
 
      // Open the Block table record Paper space for write
      BlockTableRecord acBlkTblRec;
      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace],
                                      OpenMode.ForWrite) as BlockTableRecord;      

         DBText acText = new DBText();
          acText.Position = acPtIns;
          acText.Height = 0.5;
          acText.TextString = "test";
     
          acBlkTblRec.AppendEntity(acText);
          acTrans.AddNewlyCreatedDBObject(acText, true);
          

 

0 Likes
Message 4 of 4

_gile
Consultant
Consultant
Accepted solution

You can access layouts from the layout dictionary and get each layout (except "Model") BlockTableRecord.

 

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                foreach (DBDictionaryEntry entry in layoutDict)
                {
                    if (entry.Key != "Model")
                    {
                        var layout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                        var btr = (BlockTableRecord)tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite);
                        var text = new DBText();
                        text.Position = insPt;
                        text.Height = 0.5;
                        text.TextString = "test";
                        btr.AppendEntity(text);
                        tr.AddNewlyCreatedDBObject(text, true);
                    }
                }
                tr.Commit();
            }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes