Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open file from default templates

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
CadUser46
2754 Views, 8 Replies

Open file from default templates

First let me confess to being a total programming noob.  Keen but lacking lots of answers.  There are lots of things i want to do but cant seem to get past the first hurdle.  Looked at various threads and use the help files but still it never works out.

 

Im trying to open the default standard.idw from the templates.  How do i tell it to either look at the app options setting or look at the path in the project?  (project would be preferable)

 

Here is my code.

 

Sub OpenDrawing()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "Standard.idw", True)

End Sub

 

I just get the message C:\Media\Documents|Inventor|Workspace\Standard.idw was not found.  If you wouldnt mind spelling out the answer i'd really appreciate it so i could begin to understand these prgramming terms.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
8 REPLIES 8
Message 2 of 9
YuhanZhang
in reply to: CadUser46

Hope below VBA sample helps:

 

Sub NewDrawingDocOnTemplate()
    Dim sDrawingTemplate As String
    sDrawingTemplate = ThisApplication.FileManager.GetTemplateFile(kDrawingDocumentObject, kDefaultSystemOfMeasure, kDefault_DraftingStandard)
    
    Debug.Print sDrawingTemplate
    
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, sDrawingTemplate, True)
End Sub

The FileManager.GetTemplateFile will find a template with full file name in the path that the Application Options->"Default templates" specifies.

 

You can also use the relative file name as a template which should be existing in your work space.

 

And also you can specify a full file name which is not in any of above two directories as template.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 9
CadUser46
in reply to: YuhanZhang

Rocky, thanks for that but can you explain some more.  It seems to assume you only have one .idw in your template area.  I have two and its picking the first one in the list and its not the one i want.

 

Also what do you mean by relative file name?


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 4 of 9
YuhanZhang
in reply to: CadUser46

The SystemOfMeasure parameter would indicate from which folder to find the template:

 

    kDefaultSystemOfMeasure --- ..\Autodesk\Inventor 2012\Templates\
    kEnglishSystemOfMeasure --- ..\Autodesk\Inventor 2012\Templates\English\
    kMetricSystemOfMeasure  --- ..\Autodesk\Inventor 2012\Templates\Metric\

 

And the DraftingStandard parameter would indicate which specific drawing template would be picked:

   kISO_DraftingStandard ---ISO.idw
   kDIN_DraftingStandard ---DIN.idw

   ...

 

So if you have several template files in same folder, please make sure you specify the above parameter correctly.

 

For the relative name, just as you did in your code, if you just input "Standard.idw", then it will search the template in your workspace. If would fail if the template file not found.

 

Hope this clears.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 9
CadUser46
in reply to: YuhanZhang

Hiyuhanzhang thanks for the help.  I have ended up with below after some trial and error.  Can you tell me is there anyway to interogate the project file to get the path from there instead of the application options?  I dont think its possible but i have to check as it would be more robust than the app options.

 

Sub Test2()

Dim oDoc As Inventor.Documents
Set oDoc = ThisApplication.Documents

Dim oFileOp As FileOptions
Set oFileOp = ThisApplication.FileOptions

Dim oFilePath, oFile As String
oFilePath = oFileOp.TemplatesPath
'MsgBox oFilePath
oFile = "Standard Resources.idw"

Dim oNewDoc As DrawingDocument
Set oNewDoc = oDoc.Add(kDrawingDocumentObject, oFilePath & oFile, True)

End Sub


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 6 of 9
YuhanZhang
in reply to: CadUser46

Below sample code will make use of the DesignProject options instead of application options.

Sub GetTemplateInProj()
    ThisApplication.Documents.CloseAll False
    
    ' get my own design project
    Dim oProj As DesignProject
    Set oProj = ThisApplication.DesignProjectManager.DesignProjects.ItemByName("MyProj")
    
    oProj.Activate True
    
    ' set the template path to the project location where I have my own templates
    oProj.TemplatesPath = "C:\Rocky Zhang\"
    
    ' new document with my own template
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, oProj.TemplatesPath & "ThreeViews.idw", True)
End Sub

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 7 of 9
Anonymous
in reply to: YuhanZhang

Hi, 

 

i'm having a similar problem. The thing is that i don't have the Configure Default Templates button i can only change the folder and every time i try to open an autocad .dwg it says it doesn't find the standard.idw file. So i want to change the default template to the ISO.idw that does open without any problem.

 

Maybe i don't have the button because i'm using a student version, could that be it???? 

 

Here goes the image from my application options > file tab

 

 

Captura1.JPG

 

Message 8 of 9
YuhanZhang
in reply to: Anonymous

The Configure Default Template button was introduced since Inventor 2013, so that is why you can't see it in Inventor 2012, not because of the student version.

 

The Configure Default Template allows you to switch the Drawing Standard easily, so the default template for drawing can be configured by it. But for Inventor 2012 and previous releases, you need to Repair or re-install Inventor to change the default template for drawing, so you can use Repair or re-install Inventor to change the Drawing Standard template. But if you are going to use ISO.idw to replace the Standard.idw, you can try to copy it from %PUBLICDOCUMENTS%\Autodesk\Inventor 2012\Templates\Metric\ folder to %PUBLICDOCUMENTS%\Autodesk\Inventor 2012\Templates\ folder and rename it to Standard.idw, and make sure you set the %PUBLICDOCUMENTS%\Autodesk\Inventor 2012\Templates\ as the Default Templates in the Options.

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 9 of 9
2544216342
in reply to: YuhanZhang

当我的2d工程图纸对应的3d ipt文件发生改变后我就需要重新选择路径时,我想问“替换模型参考”对应的发明人Api要如何实现此动作?

2544216342_0-1598408315830.png

 

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

Post to forums  

Autodesk Design & Make Report