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.
Solved! Go to Solution.
Solved by CadUser46. Go to Solution.
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.
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?
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.
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
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
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
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.