Create a new part with specific template

Create a new part with specific template

Anonymous
Not applicable
864 Views
4 Replies
Message 1 of 5

Create a new part with specific template

Anonymous
Not applicable

Hello,

 

With this code Inventor create a new part with standart template.

Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oPartDoc As PartDocument
Set oPartDoc = oApp.Documents.Add(kPartDocumentObject, _
oApp.GetTemplateFile(kPartDocumentObject))

 

But i need to create a new part with specific template name "piece SHOP.ipt"

I don't find how.

Is someone can help me?

thank

0 Likes
Accepted solutions (1)
865 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

try this:

Dim doc As AssemblyDocument = ThisDoc.Document

Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim path As String
Set path = oApp.DesignProjectManager.ActiveDesignProject.TemplatesPath

Dim fullFileName As String
Set fullFileName = System.IO.Path.Combine(path, "piece SHOP.ipt")

Dim oPartDoc As PartDocument
Set oPartDoc = oApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, fullFileName)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank for your help,

That doesn't work, there is a problem with "Path" said "Object required"

i don't find the solution.

Sub test()
Dim doc As AssemblyDocument
AssemblyDocument = ThisDoc.Document

Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim Path As String

Set Path = oApp.DesignProjectManager.ActiveDesignProject.TemplatesPath

Dim fullFileName As String
Set fullFileName = System.IO.Path.Combine(Path, "piece SHOP.ipt")

Dim oPartDoc As PartDocument
Set oPartDoc = oApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, fullFileName)
End Sub
0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Anonymous.  I assume you are trying to create a VBA macro with this code, right?

Well, the term 'ThisDoc' is not recognized in VBA, because it is defined within the iLogic add-in, for one thing, plus I don't think you even need to retrieve a currently open assembly document, if you are simply trying to create a new part file from its template.  Another point about VBA is that you don't need to use the 'Set' term in front of a line that is setting the value of a String (or a Double, Integer, or other simple data types), but you do for other types of variables.

Try this version.  I tested this on my own system (with a different file name) and it works for me.

Sub StartNewPieceShopPart()
    Dim oApp As Inventor.Application
    Set oApp = ThisApplication
    
    oTemplatesPath = oApp.DesignProjectManager.ActiveDesignProject.TemplatesPath
    oTemplateFile = "piece SHOP.ipt"
    oTemplate = oTemplatesPath & "\" & oTemplateFile
    
    Dim oPartDoc As PartDocument
    Set oPartDoc = oApp.Documents.Add(kPartDocumentObject, oTemplate)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Anonymous
Not applicable

Hi @WCrihfield ,

it's work.

thank you for this code and your explanations.

 

0 Likes