Message 1 of 8
Save all idw's in same folder to dwg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm running underneath code from a form which can be accessed from a drawing. It will create a dwg of all idw's in the same folder as where the drawing is. It works but there are two things that go wrong.
- See attachment. In the dwg folder where it creates the dwg's it sometimes leaves the .bak file and when it does that the letters in the filename (part number) are not in capitals. It sometimes does it with one file as in the attachment but it can also do that with more than one file.
- After running this rule and closing the drawing (all Inventor files are closed) Inventor thinks there's still a file open. So when I try to change the project file Inventor says: 'The active project cannot be changed while Inventor files are open.'
I have a similar code running for making pdf's of all idw's and running this code has the same project file problem.
A different question I have is about the creation of the dwg files. It looks like the DWGAddIn is started and stopped with each file save. Is there a way to avoid this and speed up the process?
Any ideas? Thanks in advance!
This is the code:
SyntaxEditor Code Snippet
'-----Check path----- oPath = ThisDoc.Path '-----get DWG target folder path----- oDWGFolder = oPath & "\" & "DWG" '-----Check for the DWG folder and create it if it does not exist----- If Not System.IO.Directory.Exists(oDWGFolder) Then System.IO.Directory.CreateDirectory(oDWGFolder) End If '-----Search for idw's in folder----- Dim MyFiles As String() MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw") '-----Starts the Loop----- For Each MyFile As String In MyFiles ThisApplication.SilentOperation = True Dim partDoc As Document = ThisApplication.Documents.Open(MyFile, False) On Error Resume Next If partDoc.DocumentType = kDrawingDocumentObject Then Dim oPropSet As PropertySet Dim oProp As Inventor.Property Dim invPartNoProperty As Inventor.Property = partDoc. _ PropertySets.Item("Design Tracking Properties").Item("Part Number") PartNumber = invPartNoProperty.Value oRevNum = iProperties.Value("Project", "Revision Number") Dim DWGAddIn As TranslatorAddIn DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMediumDWG As DataMedium oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium '-----Filename definition----- oFileName = oDWGFolder & "\" & PartNumber & "r" & oRevNum & ".dwg" oDataMediumDWG.FileName = oFileName '-----Save to DWG----- DWGAddIn.SaveCopyAs(partDoc, oContext, oOptions, oDataMediumDWG) End If partDoc = Nothing ThisApplication.SilentOperation = False Next
---------------------------------------------------------------------------------------------------------