- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have written some code to create a project file based on information on a form the original code was VB6 and sense I upgraded it to VB10 when I click the cmdCreat button I get
System.NullReferenceException: Object reference not set to an instance of an object.
at CreateProjII.frmCreateProj.cmdCreate_Click(Object sender, EventArgs e)
Here is the form code
Option Explicit On
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Linq
Public Class frmCreateProj
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Me.Close()
End Sub
Public Sub cmdCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreate.Click
Dim oApp As Inventor.Application
oApp = ThisApplication
Dim oDocs As Inventor.Documents
oDocs = oApp.Documents
Dim filename As String
If txtFileNum.Text = "" Then
filename = txtProj.Text & "_" & txtComp.Text
Else
filename = txtFileNum.Text
End If
Dim IpjName As String
IpjName = txtIpjName.Text
Dim projnum As String
projnum = txtProj.Text
Dim compname As String
compname = txtComp.Text
Dim Title As String
Title = txtTitle.Text
Dim vendor As String
vendor = "Gerbcon"
'create project folders
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename)
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Templates")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Content Center Files")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Assemblies")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Parts")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Drawings")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\SentItems")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Quotes")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Imported components")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Notes")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Electrical")
My.Computer.FileSystem.CreateDirectory("H:\Current Engineering\" & filename & "\Drawings" \ " txtProj.txt-1")
'Copy the Iparts folder and rename it Standard Parts
My.Computer.FileSystem.CopyDirectory("C:\NewProject\Iparts2010", "H:\Current Engineering\" & filename & "\StandardParts")
My.Computer.FileSystem.CopyDirectory("C:\NewProject\BOM", "H:\Current Engineering\" & filename & "\BOMS")
'generate ProjInfo.xml inside Templates folder
Dim B As XElement = _
<Project>
<FileNumber><%= filename %></FileNumber>
<SONumber><%= projnum %></SONumber>
<Customer><%= compname %></Customer>
<JobTitle><%= Title %></JobTitle>
</Project>
B.Add(<AdditionalSOs>
<AddSO1><%= projnum %></AddSO1>
</AdditionalSOs>) 'create element to throw additional SO numbers into starting with current SO
B.Add(<AdditionalJobTitles>
<AddJobTitle1><%= Title %></AddJobTitle1>
</AdditionalJobTitles>) 'create element to throw additional Titles into starting with current title
B.Save("H:\Current Engineering\" & filename & "\Templates\ProjInfo.xml")
'Finally, copy and modify new .ipj file (project file)
My.Computer.FileSystem.CopyFile("C:\NewProject\Temp2017.ipj", "H:\Current Engineering\" & filename & "\" & IpjName & ".ipj")
MsgBox("PROJECT BUILD COMPLETE", vbOKOnly)
Me.Close()
End Sub
End Class
Solved! Go to Solution.