Issue creating a new part file in API

Issue creating a new part file in API

cstephens58F4Q
Contributor Contributor
443 Views
6 Replies
Message 1 of 7

Issue creating a new part file in API

cstephens58F4Q
Contributor
Contributor

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 Sub

 Let me know if you have any ideas. Thanks 

0 Likes
Accepted solutions (1)
444 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

cstephens58F4Q
Contributor
Contributor

Thanks for the quick anwser I knew it was something simple I overlooked

0 Likes
Message 4 of 7

cstephens58F4Q
Contributor
Contributor

@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)

 

0 Likes
Message 5 of 7

tyler.warner
Advocate
Advocate

Try this instead:
Inventor help link here.

oDoc.SaveAs(oPath & loc, False)

 

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 6 of 7

cstephens58F4Q
Contributor
Contributor

Yeah tried that same error

0 Likes
Message 7 of 7

tyler.warner
Advocate
Advocate

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 solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes