Results 1 to 3 of 3

Thread: Create line in new drawing2

  1. #1
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Create line in new drawing2

    Hi,
    What i want is to draw a line in the new drawing. For some reason the line is in the open drawing.

    The code will create a new drawing and draw the line but the line is in drawing1 and not drawing2.

    Here is the code that i have:

    Code:
    <CommandMethod("LineInNewDrawing")> Public Sub AccessSpaceModel()
    
                Dim acDwt As String = "acad.dwt"
                Dim acDocMgr As DocumentCollection = Application.DocumentManager
                Dim acDocDwt As Document = acDocMgr.Add(acDwt)
                acDocMgr.MdiActiveDocument = acDocDwt
    
                '' Get the current document and database
                Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
                Dim acCurDb As Database = acDoc.Database
                '' Start a transaction
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
    
                    '' Open the Block table for read
                    Dim acBlkTbl As BlockTable
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
    
                    '' Open the Block table record for read
                    Dim acBlkTblRec As BlockTableRecord
    
                    '   Get the ObjectID for Model space from the Block table
                    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                    'ElseIf pKeyRes.StringResult = "Paper" Then
    
                    '' Create a line that starts at 2,5 and ends at 10,7
                    Dim acLine As Line = New Line(New Point3d(2, 5, 0), New Point3d(10, 7, 0))
                    acLine.SetDatabaseDefaults()
    
                    '' Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acLine)
                    acTrans.AddNewlyCreatedDBObject(acLine, True)
    
                    '' Save the new line to the database
                    acTrans.Commit()
                End Using
            End Sub
    Thanks for any commits.
    Last edited by Ed Jobe; 2012-04-20 at 10:04 PM. Reason: Added code tags

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Create line in new drawing2

    Add the CommandFlags.Session flag to your CommandMethod attribute and lock the new document before starting the transaction:

    Code:
            <CommandMethod("LineInNewDrawing", CommandFlags.Session)> Public Sub AccessSpaceModel()
    
                Dim acDwt As String = "acadiso.dwt"
                Dim acDocMgr As DocumentCollection = Application.DocumentManager
                Dim acDocDwt As Document = acDocMgr.Add(acDwt)
                acDocMgr.MdiActiveDocument = acDocDwt
    
                '' Get the current document and database
                ''Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
                Dim acCurDb As Database = acDocDwt.Database
                '' Lock the document
                Using acDocDwt.LockDocument()
                    '' Start a transaction
                    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
    
                        '' Open the Block table for read
                        Dim acBlkTbl As BlockTable
                        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
    
                        '' Open the Block table record for read
                        Dim acBlkTblRec As BlockTableRecord
    
                        ' Get the ObjectID for Model space from the Block table
                        acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                        'ElseIf pKeyRes.StringResult = "Paper" Then
    
                        '' Create a line that starts at 2,5 and ends at 10,7
                        Dim acLine As Line = New Line(New Point3d(2, 5, 0), New Point3d(10, 7, 0))
                        acLine.SetDatabaseDefaults()
    
                        '' Add the new object to the block table record and the transaction
                        acBlkTblRec.AppendEntity(acLine)
                        acTrans.AddNewlyCreatedDBObject(acLine, True)
    
                        '' Save the new line to the database
                        acTrans.Commit()
                    End Using
                End Using
            End Sub
    Last edited by 'gile'; 2012-04-20 at 08:03 PM.

  3. #3
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Re: Create line in new drawing2

    Thanks

    One little thing...

Similar Threads

  1. Create coordinated single-line diagrams.
    By Wish List System in forum Revit MEP - Wish List
    Replies: 1
    Last Post: 2015-12-05, 08:09 PM
  2. 2012: Create line based symbolic line familie help?
    By dkeinys590960 in forum Revit Architecture - Families
    Replies: 15
    Last Post: 2014-10-28, 09:43 PM
  3. Create line with dimension from external file
    By daniel.demoro in forum Dot Net API
    Replies: 1
    Last Post: 2011-02-10, 08:08 PM
  4. I wish I could create custom line patterns with symbol/letters in the line pattern.
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 2
    Last Post: 2010-11-13, 12:43 AM
  5. how to create a travel distance line?
    By Justin Marchiel in forum Revit Architecture - General
    Replies: 8
    Last Post: 2006-10-06, 03:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •