Hello: I'm trying to figure out how to get a selection set from model space into my newly created paperspace:
When my application runs, the user often will open an existing drawing. Often time, there could be several drawings in model space and the user is generating a new drawing to go into this same model space. After, they need to get the new drawing into a custom template (new paperspace).
I created a BOM command that currently loads the custom template into a new paperspace. I still need to include code that will ask the user to select the objects from model space that they want to go into the new paperspace. This part I can do...
Here's the part I need help with...How do I get the objects the user selects into the new paperspace???
I think perhaps I will need to do a zoom extents; after that, I will need to write code that works like the MView... is this correct? am I on the right track?
here's my current BOM command (if it will help):
<CommandMethod("BOM")> (modified code originally derrived from Fatty)_
Sub BOM()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
Dim num As Double = iModulesPerUnit 'this number represents the distance between the leds given the product chosen
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim idLayout As ObjectId = ObjectId.Null
'PARSE OUT WINDOWS AUTHENTICATION AUTHORIZATION TO GET THE FIRST,LAST INITIAL OF THE USER'S LOGIN
Dim sUserLoginInit As String
sUserLoginInit = UCase(wiUserLogin.Substring(0, 2))
Dim iIncrementText As Integer = 0
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord
Dim myBTE As DatabaseServices.SymbolTableEnumerator
Dim myLayout As New DatabaseServices.Layout
Dim sLayoutName As String = ""
Dim sLayoutNameParsedRight As String
Dim sLayoutNameParsedRightRev As String
Using docLock As DocumentLock = ed.Document.LockDocument()
Using trans As Transaction = ed.Document.TransactionManager.StartTransaction()
Dim filename As String = "C:\Documents and Settings\rproctor\Local Settings\Application Data\Autodesk\AutoCAD 2008\R17.1\enu\Template\SLOAN_TEMPLATE_rev.dwt"
Dim layoutname As String = "Layout"
Dim sNewLayoutName As String = "SLOAN_LED"
Dim dbSource As New Database(False, False)
Try
dbSource.ReadDwgFile(filename, System.IO.FileShare.Read, True, Nothing)
Dim idDbdSource As ObjectId = dbSource.LayoutDictionaryId
Dim dbdLayout As DBDictionary = DirectCast(trans.GetObject(idDbdSource, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, False, False), DBDictionary)
For Each deLayout As DictionaryEntry In dbdLayout
Dim sLayout As String = deLayout.Key.ToString()
If sLayout.ToUpper() = layoutname.ToUpper() Then
idLayout = DirectCast(deLayout.Value, ObjectId)
Exit For
End If
Next
If idLayout <> ObjectId.Null Then
Dim idc As New ObjectIdCollection()
idc.Add(idLayout)
Dim im As IdMapping = New IdMapping()
Dim dbdict As DBDictionary = DirectCast(trans.GetObject(db.LayoutDictionaryId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False, False), DBDictionary)
dbdict.UpgradeOpen()
db.WblockCloneObjects(idc, db.LayoutDictionaryId, im, DuplicateRecordCloning.MangleName, False)
Dim ip As IdPair = im.Lookup(idLayout)
idLayout = ip.Value
Dim lm As LayoutManager = LayoutManager.Current
lm.CurrentLayout = layoutname
dbdict.DecomposeForSave(DwgVersion.Current)
'LOOK TO SEE IF LAYOUT NAMED SLOAN_ESTIMATE ALREADY EXISTS
'if yes, look to see if sloan_estimate1 exists
'keep going till get unique layout name
myBT = db.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
myBTE = myBT.GetEnumerator
'ASSIGN UNIQUE LAYOUT NAME
While myBTE.MoveNext
myBTR = myBTE.Current.GetObject(DatabaseServices.OpenMode.ForRead)
If myBTR.IsLayout Then
myLayout = myBTR.LayoutId.GetObject(DatabaseServices.OpenMode.ForRead)
' MsgBox(myBTR.Name & vbCr & myLayout.LayoutName)
If InStr(myLayout.LayoutName, "SLOAN_ESTIMATE") = 1 Then
'if there's already a layout that has at least part of this name
' If InStr(1, myLayout.LayoutName, "SLOAN_ESTIMATE") = 1 Then
'see if there's anything concatenated with "SLOAN_ESTIMATE" LENGTH OF "SLOAN_ESTIMATE"=14
If myLayout.LayoutName.Length >= 14 Then
If sLayoutName = "" Then
sLayoutNameParsedRight = myLayout.LayoutName.Substring(14, myLayout.LayoutName.Length - 14)
If sLayoutNameParsedRight = "" Then
sLayoutNameParsedRight = "0"
End If
sLayoutName = "SLOAN_ESTIMATE" & (sLayoutNameParsedRight + 1)
Else
'Do a check of the new assignment
'if we had already assigned a new layout name, need to make sure there's not another like it
'check the number for the layout
sLayoutNameParsedRight = myLayout.LayoutName.Substring(14, myLayout.LayoutName.Length - 14)
If sLayoutNameParsedRight = "" Then
sLayoutNameParsedRight = "0"
End If
'here's the number it assigned to the last time. is it the same?
sLayoutNameParsedRightRev = sLayoutName.Substring(14, sLayoutName.Length - 14)
If sLayoutNameParsedRight = sLayoutNameParsedRightRev Then 'if it equals it, need to assign a new name
sLayoutName = "SLOAN_ESTIMATE" & (sLayoutNameParsedRight + 1)
End If
End If
End If
End If
End If
End While
If sLayoutName = "" Then
sLayoutName = "SLOAN_ESTIMATE"
End If
LayoutManager.Current.RenameLayout("Layout", sLayoutName)
ed.Regen()
End If
Dim layoutObj As Layout = DirectCast(trans.GetObject(idLayout, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Layout)
Dim layoutBtr As BlockTableRecord = trans.GetObject(layoutObj.BlockTableRecordId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, True)
Dim entId As ObjectId
Dim iIncrement As Integer = 0
For Each entId In layoutBtr
Dim ent As Entity = trans.GetObject(entId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, True)
'Debug.Print("ent type: " & vbTab & ent.GetType.ToString)
If TypeOf ent Is MText Then
Dim txt As MText
txt = CType(ent, MText)
' Debug.Print("text" & vbTab & txt.Contents.ToString)
If InStr(txt.Contents.ToString, "X", CompareMethod.Text) Then
Select Case iIncrement
Case 0
'FIRST TEXT BLOCK
'FILLS IN PRODUCT, COLOR, IOC, CAN DEPTH
'1st line:
txt.Contents = Replace(txt.Contents.ToString, "X", sModuleType.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", sLEDColor.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", iModulesPerUnit.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", inchesOnCenter.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", sVinylUsed.ToString, , 1)
'2nd line
txt.Contents = Replace(txt.Contents.ToString, "X", sModuleType.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", sLEDColor.ToString, , 1)
'3rd line
txt.Contents = Replace(txt.Contents.ToString, "X", UCase(sCanDepth).ToString, , 1)
iIncrement = iIncrement + 1
Case 1
''2ND TEXT BLOCK
''FILLS IN PRODUCT, COLOR, IOC, CAN DEPTH
txt.Contents = Replace(txt.Contents.ToString, "X", dCountTotal.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", sModuleType.ToString, , 1)
txt.Contents = Replace(txt.Contents.ToString, "X", sLEDColor.ToString, , 1)
iIncrement = iIncrement + 1
End Select
End If
End If
If TypeOf ent Is DBText Then
Dim txt As DBText
txt = CType(ent, DBText)
If InStr(txt.TextString.ToString, "X", CompareMethod.Text) Then
Debug.Print("DBText" & vbTab & txt.TextString.ToString)
If iIncrementText = 0 Then
txt.TextString = Replace(txt.TextString.ToString, "X", sUserLoginInit.ToString, , 1)
End If
If iIncrementText = 1 Then
txt.TextString = Replace(txt.TextString.ToString, "X", Format(Now, "short date"), , 1)
End If
If iIncrementText = 2 Then
txt.TextString = Replace(txt.TextString.ToString, "X", sCustomer.ToString, , 1)
End If
If iIncrementText = 3 Then
txt.TextString = Replace(txt.TextString.ToString, "X", sCompanySignName.ToString, , 1)
End If
iIncrementText = iIncrementText + 1
End If
End If
Next
trans.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.StackTrace)
'MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Finally
trans.Dispose()
dbSource.Dispose()
End Try
End Using
End Using
End Sub
Attatched is a pic how my BOM command currently runs. You can see that the pic isn't anywhere near the center of the viewport. The second pic shows how I need it to look.
Any thoughts, dirrection is truly appreciated.
proctor