• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Contributor
    Posts: 45
    Registered: ‎04-20-2012

    Issue with Images

    64 Views, 1 Replies
    05-30-2012 10:05 AM

    Hello,

    I am having an issue when running a command that I created to copy page setups from one drawing to other drawings.

    this command also sets a selected page setup current for those drawings.

     

    I ran the command and tested it and all seemed to work fine however I had a snag that if the drawing I was copying to had images they would get removed.  I then re did my code and tested and I have seemed to resolve the issue.

     

    This is the interesting part is that I gave this command to a co-worker to use and when they use it, it is still removing the images from the drawings that they are copying the page setups to.

     

    on my computer it works fine, on theirs it will remove the images

     

    can someone give some input on what is causing this issue.  my code is posted below.

     

    Code:

    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.PlottingServices
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class ListDwgs
        Inherits System.Windows.Forms.Form
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ListDwgs))
            Me.adddwg = New System.Windows.Forms.Button
            Me.copy = New System.Windows.Forms.Button
            Me.Cancel = New System.Windows.Forms.Button
            Me.ListBox1 = New System.Windows.Forms.ListBox
            Me.MenuStrip1 = New System.Windows.Forms.MenuStrip
            Me.Settings1 = New System.Windows.Forms.ToolStripMenuItem
            Me.MenuStrip1.SuspendLayout()
            Me.SuspendLayout()
            '
            'adddwg
            '
            Me.adddwg.Location = New System.Drawing.Point(11, 274)
            Me.adddwg.Name = "adddwg"
            Me.adddwg.Size = New System.Drawing.Size(75, 23)
            Me.adddwg.TabIndex = 1
            Me.adddwg.Text = "Add DWGs"
            Me.adddwg.UseVisualStyleBackColor = True
            '
            'copy
            '
            Me.copy.Location = New System.Drawing.Point(226, 274)
            Me.copy.Name = "copy"
            Me.copy.Size = New System.Drawing.Size(75, 23)
            Me.copy.TabIndex = 2
            Me.copy.Text = "Copy"
            Me.copy.UseVisualStyleBackColor = True
            '
            'Cancel
            '
            Me.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Cancel.Location = New System.Drawing.Point(459, 274)
            Me.Cancel.Name = "Cancel"
            Me.Cancel.Size = New System.Drawing.Size(75, 23)
            Me.Cancel.TabIndex = 3
            Me.Cancel.Text = "Cancel"
            Me.Cancel.UseVisualStyleBackColor = True
            '
            'ListBox1
            '
            Me.ListBox1.FormattingEnabled = True
            Me.ListBox1.Location = New System.Drawing.Point(8, 27)
            Me.ListBox1.Name = "ListBox1"
            Me.ListBox1.Size = New System.Drawing.Size(527, 238)
            Me.ListBox1.TabIndex = 5
            '
            'MenuStrip1
            '
            Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.Settings1})
            Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
            Me.MenuStrip1.Name = "MenuStrip1"
            Me.MenuStrip1.Size = New System.Drawing.Size(547, 24)
            Me.MenuStrip1.TabIndex = 6
            Me.MenuStrip1.Text = "MenuStrip1"
            '
            'Settings1
            '
            Me.Settings1.Name = "Settings1"
            Me.Settings1.Size = New System.Drawing.Size(61, 20)
            Me.Settings1.Text = "Settings"
            '
            'ListDwgs
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(547, 309)
            Me.Controls.Add(Me.ListBox1)
            Me.Controls.Add(Me.Cancel)
            Me.Controls.Add(Me.copy)
            Me.Controls.Add(Me.adddwg)
            Me.Controls.Add(Me.MenuStrip1)
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.Name = "ListDwgs"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Copy Page Setups to Drawings"
            Me.MenuStrip1.ResumeLayout(False)
            Me.MenuStrip1.PerformLayout()
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        End Sub
        Friend WithEvents adddwg As System.Windows.Forms.Button
        Friend WithEvents copy As System.Windows.Forms.Button
        Friend WithEvents Cancel As System.Windows.Forms.Button
        Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
        Private Sub adddwg_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles adddwg.Click
            Dim ofd As New Windows.Forms.OpenFileDialog
            ofd.Multiselect = True
            ofd.DefaultExt = "dwg"
            ofd.ShowDialog()
            Dim fname As String = ofd.FileName
            For Each fname In ofd.FileNames
                ListBox1.Items.Add(fname)
            Next
        End Sub
        Private Sub copy_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles copy.Click
            Try
                Dim psdb As New Database(False, True)
                psdb.ReadDwgFile(My.Settings.PSDwg, FileOpenMode.OpenForReadAndReadShare, False, "")
                Using trans As Transaction = psdb.TransactionManager.StartTransaction
                    For Each item In ListBox1.Items
                        Dim db As New Database(False, False)
                        db.ReadDwgFile(item.ToString, FileOpenMode.OpenForReadAndAllShare, False, "")
                        Using trns As Transaction = db.TransactionManager.StartTransaction
                            Dim psd As DBDictionary = trans.GetObject(psdb.PlotSettingsDictionaryId, OpenMode.ForRead)
                            Dim id As ObjectId
                            Dim pd As DBDictionary = trns.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead)
                            For Each entry As DBDictionaryEntry In pd
                                pd.UpgradeOpen()
                                pd.Remove(entry.Value)
                                pd.DowngradeOpen()
                            Next
                            For Each psent As DBDictionaryEntry In psd
                                id = psd.GetAt(psent.Key)
                                Dim ps As PlotSettings = id.GetObject(OpenMode.ForRead)
                                Using curps As PlotSettings = New PlotSettings(False)
                                    curps.CopyFrom(ps)
                                    curps.AddToPlotSettingsDictionary(db)
                                    curps.DowngradeOpen()
                                End Using
                            Next
                            Dim pid As ObjectId
                            pid = pd.GetAt(My.Settings.PSSet)
                            Dim psn As PlotSettings = DirectCast(pid.GetObject(OpenMode.ForRead), PlotSettings)
                            Dim psl As PlotSettings = New PlotSettings(False)
                            psl.CopyFrom(psn)
                            Dim bt As BlockTable = DirectCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
                            Dim btr As BlockTableRecord = DirectCast(bt(BlockTableRecord.PaperSpace).GetObject(OpenMode.ForRead), BlockTableRecord)
                            Dim lyobjId As ObjectId = (btr.LayoutId.GetObject(OpenMode.ForRead).ObjectId)
                            Dim lytps As PlotSettings = DirectCast(lyobjId.GetObject(OpenMode.ForWrite), PlotSettings)
                            lytps.CopyFrom(psl)
                            trns.Commit()
                        End Using
                        db.SaveAs(item.ToString, DwgVersion.Current)
                        db.CloseInput(True)
                        db.Dispose()
                    Next
                End Using
                psdb.CloseInput(True)
                psdb.Dispose()
            Catch ex As System.Exception
                MsgBox(vbLf & ex.Message)
            End Try
            Me.Close()
        End Sub
        Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
        Friend WithEvents Settings1 As System.Windows.Forms.ToolStripMenuItem
        Private Sub settings1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Settings1.Click
            Dim setngs As New Form2
            setngs.ShowDialog()
        End Sub
    End Class

     

    Please use plain text.
    Active Contributor
    Posts: 45
    Registered: ‎04-20-2012

    Re: Issue with Images

    05-30-2012 12:25 PM in reply to: bkenyon13

    DUH!! Stupid Moment.

     

    Sorry for the waste of a post, but the code that I posted works fine.

     

    It turns out that on the other persons computer the dll that handles the command was not getting updated with the revised one, because I was copying it to the wrong location.

     

    Note:

    Always make sure you are copying the revised file to the correct location.

    Please use plain text.