Author Topic: Want to dynamically create template in my new layout  (Read 3614 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
Want to dynamically create template in my new layout
« on: May 16, 2008, 01:34:49 PM »
Hello: Our company has a template that loads into cad for use with their drawings and I'd like to dynamically build this template so that it displays nicely in the viewport of a new layout I create. I create the new layout before generating a drawing that's created in model space; after which, I create a table and want it to display in the upperleft hand corner of my new layout; however, I don't know how to:

a) make it display it in my new layout?
b) make it display in the leftmost corner of my new layout.


here's my code for creating the table: I say to create in paperspace...but don't know how to tell it to go into my new layout:

Code: [Select]

        Dim myTransMan As DatabaseServices.TransactionManager
        Dim myTrans As DatabaseServices.Transaction
        Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document
        Dim myBT As DatabaseServices.BlockTable
        Dim myBTR As DatabaseServices.BlockTableRecord
        'Dim myBTE As DatabaseServices.SymbolTableEnumerator


        'Get the active document and begin a Transaction
        myDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        myTransMan = myDWG.TransactionManager
        myTrans = myTransMan.StartTransaction

        'Open the BlockTable for Read
        myBT = myDWG.Database.BlockTableId.GetObject( _
            DatabaseServices.OpenMode.ForRead)
       [color=red] myBTR = myBT(DatabaseServices.BlockTableRecord.PaperSpace).GetObject( _
            DatabaseServices.OpenMode.ForWrite)[/color]

        'Draw the Table
        Dim myTable As New DatabaseServices.Table
        ' myTable.Position = New Geometry.Point3d(6.478, 100, 0)
        ' myTable.Position = New Geometry.Point3d(20, 50, 0)
        myTable.InsertRows(1, 2, 3)

        'myTable.InsertColumns(1, 12, 1)

        'myTable.Height = 5
        myTable.Width = 120

        myTable.SetValue(0, 0, " 1) LAID OUT AT " & iModulesPerUnit & " PER " & UCase(sUnits) & ", " & inchesOnCenter & " ON CENTER", DatabaseServices.ParseOption.ParseOptionNone)
        myTable.SetAlignment(0, 0, CellAlignment.MiddleLeft)
        myTable.SetTextHeight(0, 0, 2)
        myTable.SetGridVisibility(0, 0, GridLineType.AllGridLines, Visibility.Invisible)
        '**************************
        myTable.SetValue(1, 0, " 2) EACH MODULAR 60 POWER SUPPLY CAN RUN UP TO ## XX MODULES", DatabaseServices.ParseOption.ParseOptionNone)
        myTable.SetAlignment(1, 0, DatabaseServices.CellAlignment.TopLeft)
        myTable.SetAlignment(1, 0, CellAlignment.MiddleLeft)
        myTable.SetTextHeight(1, 0, 2)
        myTable.SetGridVisibility(1, 0, GridLineType.AllGridLines, Visibility.Invisible)
        '**************************
        myTable.SetValue(2, 0, " 3) LAYOUT BASED ON A " & UCase(sCanDepth) & " CAN DEPTH", DatabaseServices.ParseOption.ParseOptionNone)
        myTable.SetAlignment(2, 0, DatabaseServices.CellAlignment.TopLeft)
        myTable.SetAlignment(2, 0, CellAlignment.MiddleLeft)
        myTable.SetTextHeight(2, 0, 2)
        myTable.SetGridVisibility(2, 0, GridLineType.AllGridLines, Visibility.Invisible)
        '**************************
        myTable.SetValue(3, 0, " 4) THESE DIMENSIONS ARE CALCULATED IN " & UCase(sUnits), DatabaseServices.ParseOption.ParseOptionNone)
        myTable.SetAlignment(3, 0, DatabaseServices.CellAlignment.TopLeft)
        myTable.SetAlignment(3, 0, CellAlignment.MiddleLeft)
        myTable.SetTextHeight(3, 0, 2)
        myTable.SetGridVisibility(3, 0, GridLineType.AllGridLines, Visibility.Invisible)

        myBTR.AppendEntity(myTable)
        myTrans.AddNewlyCreatedDBObject(myTable, True)

        'Commit the Transaction
        myTrans.Commit()

        myTrans.Dispose()
        myTransMan.Dispose()


Any thoughts would truly be appreciated.
Thanks,
Proctor

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8799
  • AKA Daniel
Re: Want to dynamically create template in my new layout
« Reply #1 on: May 19, 2008, 01:34:11 PM »
In Arx you can do a pLayout->getBlockTableRecordId() , but I don’t see that option in .Net.
A suggestion would be to activate the layout and use the currentSpaceId, just a shot…  :-o

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Want to dynamically create template in my new layout
« Reply #2 on: May 19, 2008, 01:45:33 PM »
In Arx you can do a pLayout->getBlockTableRecordId() , but I don’t see that option in .Net.
A suggestion would be to activate the layout and use the currentSpaceId, just a shot…  :-o
Layouts have a BlockTableRecordId property.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8799
  • AKA Daniel
Re: Want to dynamically create template in my new layout
« Reply #3 on: May 19, 2008, 01:52:24 PM »
In Arx you can do a pLayout->getBlockTableRecordId() , but I don’t see that option in .Net.
A suggestion would be to activate the layout and use the currentSpaceId, just a shot…  :-o
Layouts have a BlockTableRecordId property.

Ohhh Yeah, There it is… time to get spectacles   :lol:

Proctor

  • Guest
Re: Want to dynamically create template in my new layout
« Reply #4 on: May 19, 2008, 05:37:21 PM »
Hello - thanks so much for your help.

I was able to get the blockTableRecordId from the layout that I want to place my table in but not sure how to use it.

Wouldn't it somehow go in this line?:
Code: [Select]
myBTR = myBT(DatabaseServices.BlockTableRecord.PaperSpace).GetObject( _
            DatabaseServices.OpenMode.ForWrite)

the parameter for myBT says it wants item key as string as objectid

Thanks again for the help,
Proctor


       

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8799
  • AKA Daniel
Re: Want to dynamically create template in my new layout
« Reply #5 on: May 19, 2008, 09:27:48 PM »
Can you translate this to VB?

Code: [Select]
public class Commands
  {
    [CommandMethod("doit")]
    public void doit()
    {
      Database db = HostApplicationServices.WorkingDatabase;
      using (Transaction tr = db.TransactionManager.StartTransaction())
      {
        LayoutManager manager = LayoutManager.Current;
        ObjectId LayOutId = manager.GetLayoutId(manager.CurrentLayout);

        Layout layout = (Layout)tr.GetObject(LayOutId, OpenMode.ForRead);

        BlockTableRecord btr = (BlockTableRecord)tr.GetObject
                               (layout.BlockTableRecordId, OpenMode.ForWrite);

        Line line = new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0));

        btr.AppendEntity(line);
        db.TransactionManager.AddNewlyCreatedDBObject(line, true);
        tr.Commit();
      }
    }

Proctor

  • Guest
Re: Want to dynamically create template in my new layout
« Reply #6 on: May 20, 2008, 12:07:51 PM »
Daniel - thanks for helping me to learn.

I converted to Vb....and it works beautifully!! However, it places the table underneath the viewport (see attached).
Do you know how I can find out the position - say for example of the upperleft corner of the viewport and how to be placed at this point?

Thank you again for your help!!!
Proctor

Code: [Select]
    <CommandMethod("BOM")> _
        Sub BOM()
        Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Using tr As Transaction = db.TransactionManager.StartTransaction()

            myDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim myLayout As New DatabaseServices.Layout

            Dim myLM As LayoutManager = LayoutManager.Current
            myLayout = myLM.CreateLayout("SLOAN_ESTIMATE").GetObject(DatabaseServices.OpenMode.ForWrite)
            myLM.CurrentLayout = "SLOAN_ESTIMATE"

            myLayout.TabOrder = 0

            Dim LayOutId As ObjectId = myLM.GetLayoutId(myLM.CurrentLayout)
            Dim layout As Layout = DirectCast(tr.GetObject(LayOutId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Layout)
            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(layout.BlockTableRecordId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), BlockTableRecord)

            'Draw the Table
            Dim myTable As New DatabaseServices.Table
            myTable.InsertRows(1, 2, 3)

            myTable.Width = 120

            myTable.SetValue(0, 0, " 1) LAID OUT AT " & iModulesPerUnit & " PER " & UCase(sUnits) & ", " & inchesOnCenter & " ON CENTER", DatabaseServices.ParseOption.ParseOptionNone)
            myTable.SetAlignment(0, 0, CellAlignment.MiddleLeft)
            myTable.SetTextHeight(0, 0, 2)
            myTable.SetGridVisibility(0, 0, GridLineType.AllGridLines, Visibility.Invisible)
            '**************************
            myTable.SetValue(1, 0, " 2) EACH MODULAR 60 POWER SUPPLY CAN RUN UP TO ## XX MODULES", DatabaseServices.ParseOption.ParseOptionNone)
            myTable.SetAlignment(1, 0, DatabaseServices.CellAlignment.TopLeft)
            myTable.SetAlignment(1, 0, CellAlignment.MiddleLeft)
            myTable.SetTextHeight(1, 0, 2)
            myTable.SetGridVisibility(1, 0, GridLineType.AllGridLines, Visibility.Invisible)
            '**************************
            myTable.SetValue(2, 0, " 3) LAYOUT BASED ON A " & UCase(sCanDepth) & " CAN DEPTH", DatabaseServices.ParseOption.ParseOptionNone)
            myTable.SetAlignment(2, 0, DatabaseServices.CellAlignment.TopLeft)
            myTable.SetAlignment(2, 0, CellAlignment.MiddleLeft)
            myTable.SetTextHeight(2, 0, 2)
            myTable.SetGridVisibility(2, 0, GridLineType.AllGridLines, Visibility.Invisible)
            '**************************
            myTable.SetValue(3, 0, " 4) THESE DIMENSIONS ARE CALCULATED IN " & UCase(sUnits), DatabaseServices.ParseOption.ParseOptionNone)
            myTable.SetAlignment(3, 0, DatabaseServices.CellAlignment.TopLeft)
            myTable.SetAlignment(3, 0, CellAlignment.MiddleLeft)
            myTable.SetTextHeight(3, 0, 2)
            myTable.SetGridVisibility(3, 0, GridLineType.AllGridLines, Visibility.Invisible)


            btr.AppendEntity(myTable)
            db.TransactionManager.AddNewlyCreatedDBObject(myTable, True)
            tr.Commit()

        End Using
    End Sub

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8799
  • AKA Daniel
Re: Want to dynamically create template in my new layout
« Reply #7 on: May 20, 2008, 01:08:40 PM »
I have never played around with this, but you ought to be able to get the properties of the viewport to find its size and position.
As far as who is on top, you might be able to goof around with the draworder. Something else I haven’t messed with yet.  :mrgreen:

Proctor

  • Guest
Re: Want to dynamically create template in my new layout
« Reply #8 on: May 21, 2008, 10:23:24 AM »
Thanks again for all the help....i'll take a look at the viewport properties and also draworder.

Proctor