- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I hope someone can help.
I created an iLogic program that exports all sheets in an inventor drawing to separate pdf files with a specific file name for each sheet. The name is made up as follows 'Drawing No. Drawing type, Sheet No. and revision' it looks like this 12345-SK-01_01. When the pdf's are created only the sheet number is incremented to create a individual file name.
The problem I am having is that when I try to use this program to create 'dwg' versions of the drawing the file name is not being created correctly.
What is happening is that the initial files name is produced and then 'sheet 1, 2, 3.....'is being added onto the end of the file name for however many sheets there are in the drawing. it then increments the sheet number within the file name and then continues to add 'sheet 1, 2, 3....' to each exported drawing file name.
so what I end up with is 100 drawing being created for a 10 sheet inventor drawing.
Example file naming;
12345-SK-01_01_Sheet _1.dwg
12345-SK-01_01_Sheet _2.dwg
12345-SK-01_01_Sheet _3.dwg......
12345-SK-02_01_Sheet _1.dwg
12345-SK-02_01_Sheet _2.dwg
12345-SK-02_01_Sheet _3.dwg.....
See attached images.
Also I added message boxes to show the generated file name and path. These do appear to be being created correctly. The _Sheet_1... is being added by something else within inventor?????......... maybe.......
I have added the code below.
The only difference between this code and the code to produce the pdf's is that pdf was replace with dwg and
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
was replaced with.
oDwgAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
I realise this a is a simplistic approach but I don't profess to be a programmer.
I hope someone can because I don't have much more hair left to pull out...
Thanks in advance.
Chris
Sub Main() FileName = ThisDoc.FileName(True) 'with extension FileExtension = Right(FileName, 3) If FileExtension = "dwg" Then Save_As_dwg Else ErrorMessage End If 'MessageBox.Show("Stop 1","") End Sub Sub Save_As_dwg oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension 'oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oDwgAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") oDocument = ThisApplication.ActiveDocument oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Dim oPrintMgr As DrawingPrintManager = ThisDrawing.Document.PrintManager 'Gets the Workspace Path WorkspacePath = ThisDoc.WorkspacePath() 'MessageBox.Show("WorkspacePath Set") WorkspacePathLength = Len(WorkspacePath) 'Gets just the Path of the file PathOnly = ThisDoc.Path 'Removes the Workspace Path from FullPath DirectoryPath = Strings.Right(PathOnly, PathOnly.Length - WorkspacePathLength) 'Sets the Dirctory that the dwg should be saved in dwgPath = ThisDoc.Path ' oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet 'MessageBox.Show("Sheet Range Set") 'Checks to see if that directory exists, if not, it is created Dim oName As String Dim oJobNo As String Dim oType As String Dim oRev As String For Each oSheet As Sheet In ThisDrawing.Document.Sheets oSheet.Activate 'Generate sheet name 'oName' oDoc = ThisDoc.Document SheetNumber = Mid(oDoc.ActiveSheet.Name, InStr(1, oDoc.ActiveSheet.Name, ":") + 1) 'Add zero prior to Sheet No SheetNo = If(SheetNumber < 10, "0" + CStr(SheetNumber), CStr(SheetNumber)) SheetNumber = SheetNumber + 1 ' oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet oJobNo = iProperties.Value("Custom", "Job_No.") oType = iProperties.Value("Custom", "Drawing_type") oRev = iProperties.Value("Project", "Revision Number") 'Create drawing number oName = (oJobNo & "-" & oType & "-" & SheetNo & "_" & oRev) MessageBox.Show("The generated drawing number is " & oName) dwgName = dwgPath & "\" & oName & ".dwg" MessageBox.Show("The new dwg name is " & dwgName) 'Set the dwg target file name oDataMedium.FileName = dwgName 'MessageBox.Show("File Name Set") oMsgAns = MsgBox("Do you want to continue the print", vbYesNo, "Colour select") If oMsgAns = vbNo Then Return End If 'Saves the dwg in the desired location oDwgAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'ThisDoc.Document.SaveAs(dwgName , True) 'MessageBox.Show("New dwg created") Next End Sub Sub ErrorMessage i = MessageBox.Show("This is not a drawing file. No dwg will be created.", "Create dwg", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) End Sub
I
Solved! Go to Solution.