- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Im sure im overlooking something small but I am trying to get a part file created before I edit it with passed variables. The issue Im having is the line below is giving me the error "Error BC30469 Reference to a non-shared member requires an object reference. "
Dim oDoc As PartDocument = Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplatesPath & "standard.ipt", False)
Below is this full portion of code:
Public Sub CreateStandardPart(x_length As Double, y_length As Double, z_length As Double, loc As String, oPath As String)
'Create a new part with your desired part template
Dim oProjectMgr As DesignProjectManager
Dim oProject As DesignProject
oProject = oProjectMgr.ActiveDesignProject
Dim oTemplatesPath As String
oTemplatesPath = oProject.TemplatesPath
Dim oDoc As PartDocument = Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplatesPath & "standard.ipt", False)
oDoc.OpenFile()
oDoc.SaveAs(loc & oPath, True)
oDoc.Close(False)
End SubLet me know if you have any ideas. Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @cstephens58F4Q. It looks like you are missing the step where you set a value to your oProjectMgr variable. Try this:
Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS)
.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@WCrihfield again on this section of code. Any reason you could see why I would be getting the attached error in this line of code: oDoc.SaveFileAs(oPath & loc)
error:
System.MissingMemberException: 'Public member 'SaveFileAs' on type '_DocumentClass' not found.'
Issue area:
Public Sub CreateStandardPart(x_length As Double, y_length As Double, z_length As Double, loc As String, oPath As String)
MsgBox("here with x length = " & x_length)
'Create a new part with your desired part template
'Dim oApp As Class = g_inventorApplication
Dim oProjectMgr As DesignProjectManager = g_inventorApplication.DesignProjectManager
Dim oProject As DesignProject
oProject = oProjectMgr.ActiveDesignProject
Dim oTemplatesPath As String
oTemplatesPath = oProject.TemplatesPath
Dim oDoc As PartDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplatesPath & "/English/OC Standard.ipt", True)
oDoc.Activate()
oDoc.SaveFileAs(oPath & loc)
End Sub
Here is how I am calling out oPath:
SaveFileDialog1.Filter = "Assembly|*.iam"
SaveFileDialog1.InitialDirectory = "C:\Temp"
SaveFileDialog1.Title = "Save Melter Model"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName IsNot "" Then
SaveFileDialog1.OpenFile()
oFile = SaveFileDialog1.FileName
End If
'''''
''Sets directory for future use
'''''
Dim oPath_ As String = oFile
Dim oPat As Integer = InStrRev(oPath_, "\")
Dim oPath As String = Mid(oPath_, 1, oPat)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try this one & see if you're still getting the error. I changed the name & path variables slightly because I wasn't sure what was being entered into the Sub. This will overwrite the file in the specified folder if it already exists, so you'd have to write a check if you don't want that to be the case.
Public Sub CreateStandardPart(x_length As Double, y_length As Double, z_length As Double, loc As String, oPath As String)
MsgBox("here with x length = " & x_length)
Dim oFileName As String = "Save Melter Model.ipt"
Dim oFilePath As String = "C:\Temp\"
'Create a new part with your desired part template
'Dim oApp As Class = g_inventorApplication
Dim oProjectMgr As DesignProjectManager = g_inventorApplication.DesignProjectManager
Dim oProject As DesignProject = oProjectMgr.ActiveDesignProject
Dim oTemplatesPath As String = oProject.TemplatesPath
Dim oDoc As PartDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplatesPath & "/English/OC Standard.ipt", True)
Try
oDoc.SaveAs(oFilePath + oFileName, False)
Catch ex As Exception
MsgBox("Copy didn't work!.... see error message below:" & vbNewLine & ex.Message)
Exit Sub
End Try
End Sub
If this helped you, please click LIKE.