.NET

Reply
Active Contributor
bkenyon13
Posts: 45
Registered: ‎04-20-2012
Message 1 of 2 (130 Views)
Accepted Solution

Issue adding Xrefs

130 Views, 1 Replies
05-21-2012 09:52 AM

Hello,

I am having an issue with adding xrefs to drawings.  The way I have this setup is the user inputs information and the number of sheets.  This then sets up a sheet set with the information and then for each value for the number of sheets the user gets a dialog askign for a number, name, and description for that sheet.

 

so if the user puts in 5 as the number of sheets, the user gets that dialog 5 times.

 

also I have a dialog that asks the user if they are adding xrefs to the sheets, if they answer yes then it adds the xrefs to each sheet that is created (this is where I have an issue).

 

This works perfect for the first sheet that is added, how ever after you fill in the information and submit for the second sheet autocad gives a fatal exception error and closes. not sure if I am missing on turning something off, closing, or stoping something before the next sheet is created.

 

here is the code I have at this point:

'checks to see if the dialog was yes
        If xrefd.DialogResult = Windows.Forms.DialogResult.Yes Then
            'shows the dialog
            efd.ShowDialog()
            'shows the dialog
            pfd.ShowDialog()
            'runs for each value in total sheets
            For i As Integer = 1 To info.TotalSheetNum.Value
                'shows the dialog
                sheetinfo.ShowDialog()
                'checks to see if the sheet number is 1
                If sheetinfo.SheetNum.Text = "1" Then
                    'sets the sheet set default values
                    SetSheetSetDefaults(ssdb, info.NameTxt.Text, "Description", ssf, "M:\CAD Management\CAD Files\Template\lrgsht1a.dwt", "01 INDEX PLAN")
                Else
                    'sets the sheet set default values
                    SetSheetSetDefaults(ssdb, info.NameTxt.Text, "Description", ssf, "M:\CAD Management\CAD Files\Template\lrgsht2.dwt", "01 INDEX PLAN")
                End If
                'checks to see if the sheet number is CS-01
                If sheetinfo.SheetNum.Text = "CS-01" Then
                    'sets the sheet set default values
                    SetSheetSetDefaults(ssdb, info.NameTxt.Text, "Description", ssf, "M:\CAD Management\CAD Files\Template\lrgsht1a.dwt", "01 INDEX PLAN")
                Else
                    'sets the sheet set default values
                    SetSheetSetDefaults(ssdb, info.NameTxt.Text, "Description", ssf, "M:\CAD Management\CAD Files\Template\lrgsht2.dwt", "01 INDEX PLAN")
                End If
                'adds the sheet to the sheet set
                AddSheet(ssdb, sheetinfo.SheetName.Text, sheetinfo.SheetDesc.Text, sheetinfo.SheetNum.Text, sheetinfo.SheetName.Text)
                'reads the newly create dwg file
                db.ReadDwgFile(ssf & sheetinfo.SheetName.Text & ".dwg", System.IO.FileShare.ReadWrite, False, "")
                'gets the xrefs specified
                Dim xrefid As ObjectId = db.OverlayXref(efd.Filename, efd.Filename)
                Dim xrefid2 As ObjectId = db.OverlayXref(pfd.Filename, pfd.Filename)
                'adds the xrefs to the new dwg file
                Using trans As Transaction = db.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
                    Dim btr As BlockTableRecord = TryCast(bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite), BlockTableRecord)
                    Dim bref As New BlockReference(Point3d.Origin, xrefid)
                    Dim bref2 As New BlockReference(Point3d.Origin, xrefid2)
                    btr.AppendEntity(bref)
                    btr.AppendEntity(bref2)
                    trans.AddNewlyCreatedDBObject(bref, True)
                    trans.AddNewlyCreatedDBObject(bref2, True)
                    trans.Commit()
                End Using
                'saves and closes the new dwg file with xrefs
                db.SaveAs(ssf & sheetinfo.SheetName.Text & ".dwg", DwgVersion.Current)
                db.CloseInput(True)
                db.Dispose()
            Next
        End If

 

Active Contributor
bkenyon13
Posts: 45
Registered: ‎04-20-2012
Message 2 of 2 (127 Views)

Re: Issue adding Xrefs

05-21-2012 10:22 AM in reply to: bkenyon13

Sorry was being a little stupid.

 

realized that I should probably create a new database for each new dwg that I was creating.

 

moved:

dim db as new database(true,false)

 

under:

for each i as integer = 1 in info.totalnumtxt.value

 

works like a charm now

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.