Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've put some code together with the intention to save sheetmetal parts to the sheetmetal folder and normal parts to the parts folder.
So the code works well for a sheetmetal part but gives an error in a normal part.
I was assuming that because the normal part doesn't have a flatpattern that the code would run accordingly , but i'm afraid that was a too simple approach.
I could not find any other references about how to differentiate parts between sheet metal parts, so any help is really appreciated 🙂
Code right now as follow:
'**** Find path of the project '[ Dim IPJ as String Dim IPJ_Name As String Dim IPJ_Path As String Dim FNamePos As Long 'set a reference to the FileLocations object. IPJ = ThisApplication.FileLocations.FileLocationsFile 'get the location of the last backslash seperator FNamePos = InStrRev(IPJ, "\", -1) 'get the project file name with the file extension IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos) 'get the project name (without extension) IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4) 'get the path of the folder containing the project file IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name)) '] ' **** Read text from .txt files in the settings folder '[ oRead1 = System.IO.File.OpenText(IPJ_Folder_Location & "\Settings\Jobnumber.txt") Jobnumber = oRead1.ReadLine() oRead2 = System.IO.File.OpenText(IPJ_Folder_Location & "\Settings\Project.txt") Project = oRead2.ReadLine() oRead3 = System.IO.File.OpenText(IPJ_Folder_Location & "\Settings\SO_number.txt") SO_number = oRead3.ReadLine() oRead4 = System.IO.File.OpenText(IPJ_Folder_Location & "\Settings\Company.txt") Company = oRead4.ReadLine() '] oPN = iProperties.Value("Project", "Part Number") '*** Save/ make folders and place document with PN as filename in correct folder '[ Dim oPath As String Dim oFolderPRT As String Dim oFolderSM_PRT As String oPath = ThisDoc.WorkspacePath oFolderPRT = (oPath & "\Output\" & Jobnumber & "\Parts\") oFolderSM_PRT = (oPath & "\Output\" & Jobnumber & "\SheetMetalParts\") '***Check for the folders and create them if they don't not exist. If Not System.IO.Directory.Exists(oFolderPRT) Then System.IO.Directory.CreateDirectory(oFolderPRT) End If If Not System.IO.Directory.Exists(oFolderSM_PRT) Then System.IO.Directory.CreateDirectory(oFolderSM_PRT) End If '*** Save copy of active document 'ThisDoc.Document.SaveAs(oFolder & oPN & ".ipt" , True) Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument 'ensure this part has a flat pattern Dim oSMDef As SheetMetalComponentDefinition oSMDef = oDoc.ComponentDefinition i = MessageBox.Show("Part saved as Sheetmetal ONLY if Flatpattern is generated but NOT active", "Please confirm! ",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If i = vbYes Then Goto Yes Else If i = vbNo Then Goto NO End If Yes: If oSMDef.FlatPattern Is Nothing Then 'Save in Parts folder ThisDoc.Document.SaveAs(oFolderPRT & oPN & ".ipt" , True) MessageBox.Show("File: " & oPN & ".ipt"& vbLf & "Succesfully saved in : " & oFolderPRT , "Succes") 'Goto Endrule Else ThisDoc.Document.SaveAs(oFolderSM_PRT & oPN & ".ipt" , True) End If Goto Endrule NO:MessageBox.Show("No Files are saved!", "ERROR") Endrule: ']
Solved! Go to Solution.