.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Visual Basic.NET plot multiple drawings

3 REPLIES 3
Reply
Message 1 of 4
dan503
2306 Views, 3 Replies

Visual Basic.NET plot multiple drawings

Hey Everyone,
I have been using vb.net for about3 or 4 months now. i have made a program that reads the location of drawings from a word file and then copies and renames the file. i am interested in having my program print the drawings using autocad. Here is a copy of the code i am using.

' Autodesk AutoCAD 2000 or above and Universal Document Converter
' should be installed on your PC

' Define constants
Const acExtents = 1
Const acScaleToFit = 0

' Run AutoCAD as COM-server
On Error Resume Next
Dim App As Object
'Dim App As New AutoCAD.AcadApplication
Dim Drawing As Object
Dim Layout As Object
Dim ActiveSpace As Object
Dim n As Integer = 0
Dim DrawType As String = ""
Dim FilePath As String = ""
Dim MyDwg As String = ""
Dim Dwg As Object
Dim DwgClass As String = ""
Dim k As Integer = 0
Dim strFilePath As String = ""



App = CreateObject("AutoCAD.Application")

For n = 0 To DataGridView1.RowCount - 1 'Determines what File Type the user selected it was, and whether or not the user select a file type.
If DataGridView1.Item(2, n).Value = "False" And DataGridView1.Item(3, n).Value = "False" And DataGridView1.Item(4, n).Value = "False" Then 'Determines whether or not the user select a file type.
MsgBox("You must select what type of drawing " & DataGridView1.Item(0, n).Value & " is.", CType(vbOKOnly + vbCritical, MsgBoxStyle))
Exit Sub
End If
Next n
For n = 0 To DataGridView1.RowCount - 1 'Determines what File Type that the user selected
MyDwg = DataGridView1.Item(0, n).Value
MsgBox(MyDwg)
If DataGridView1.Item(2, n).Value = "True" Then
DrawType = ".dwg"
ElseIf DataGridView1.Item(3, n).Value = "True" Then
DrawType = ".idw"
ElseIf DataGridView1.Item(4, n).Value = "True" Then
DrawType = ".pdf"
Else
MsgBox("You must select what type of drawing " & DataGridView1.Item(0, n).Value & " is.", CType(vbOKOnly + vbCritical, MsgBoxStyle))
Exit Sub
End If

Dwg = Split(MyDwg, "-") 'Splits the Drawing Name (MyDwg) into an array
DwgClass = Dwg(2)
Trim$(DwgClass)
MsgBox(DwgClass)
For k = 0 To UBound(CType(Dwg, Array))
Dwg(k) = Trim$(Dwg(k))
Next k
If DwgClass Like "###" Then '### stands for 3 numeric values
MyDwg = Dwg(0) & "-" & Dwg(1) & "-" & Dwg(2)
ElseIf DwgClass Like "###[A-Z]" Then '### stands for 3 numeric values and [A-Z] is a wildcard of only these letters and are Capital
MyDwg = Dwg(0) & "-" & Dwg(1) & "-" & Dwg(2)
Else
MsgBox("There seems to be a problem with the drawings class.", vbOKOnly + vbCritical)
End If
MsgBox(DwgClass)
Select Case Microsoft.VisualBasic.Left$(DwgClass, 1)
Case "2"
strFilePath = strelement & My.Settings.PIDText & MyDwg & DrawType 'My.Settings.PIDText gets folder structure from config file)
Case "3"
strFilePath = strelement & My.Settings.VesselText & MyDwg & DrawType 'My.Settings.VesselText gets folder structure from config file
Case "4"
strFilePath = strelement & My.Settings.StructuralText & MyDwg & DrawType 'My.Settings.StructuralText gets folder structure from config file
Case "5"
strFilePath = strelement & My.Settings.PipingText & MyDwg & DrawType ''My.Settings.PipingText gets folder structure from config file
Case "6"
strFilePath = strelement & My.Settings.ISOText & MyDwg & DrawType 'My.Settings.ISOText gets folder structure from config file
Case "7"
strFilePath = strelement & My.Settings.InstElecText & MyDwg & DrawType 'My.Settings.InstElecText gets folder structure from config file
Case "8"
strFilePath = strelement & My.Settings.MembraneTubesText & MyDwg & DrawType 'My.Settings.MembraneTubesText gets folder structure from config file
Case Else
MsgBox(DwgClass & " - This Is An Invalid Drawing Class", CType(vbOKOnly + vbCritical, MsgBoxStyle))
End Select

App.Preferences.System.SingleDocumentMode = False

Drawing = App.Documents.Open(strFilePath, False)
If Drawing = Not Nothing Then

' Change AutoCAD preferences for scaling the drawing to page
If Drawing.ActiveSpace = 0 Then

ActiveSpace = Drawing.PaperSpace
Layout = ActiveSpace.Layout

Else

ActiveSpace = Drawing.ModelSpace
Layout = ActiveSpace.Layout

End If

Layout.PlotType = acExtents
Layout.UseStandardScale = True
Layout.StandardScale = acScaleToFit

' Plot the drawing
Call Drawing.Plot.PlotToDevice("Dell AIO Printer A920.pc3")

' Close drawing
Drawing.Close(False)
Drawing = Nothing

End If
System.Threading.Thread.Sleep(30000) 'added so that there is a chance for the drawing to print out before the other one starts.
Next n

I cant use the AutoCAD API because this is suppose to work for multiple versions of autocad. I am sure That there is a better way but i do not know how. Can anyone help me.
Thanks,
Dan
3 REPLIES 3
Message 2 of 4
dan503
in reply to: dan503

Sorry I forgot to add, this code works for ploting 1 file but i want to plot multiple files. If i don't have the sleep function then the file that is printed is the last file on the list. Is there a way that I can tell when autocad is ready to recieve another plot command. Thanks,
Dan503
Message 3 of 4
Mohamed Allabakash
in reply to: dan503

Hi i am doing a parametric program using VBA,Vlisp,AutoCAD. am converting to Vb.Net and CAD2006. can you please help me to insert the external drawings (sideview.dwg, Topview.dwg) in active drawing file Using VB.Net......

It will help me a lot

Thanks in Advance
Message 4 of 4
dheselwood
in reply to: dan503

You need to change the BACKGROUNDPLOT system variable to 0 otherwise Acad will try and print over the previous.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost