To preface this request, I would like to say that we don't currently have vault. We will eventually get vault, but it will take quite a while. This will save a huge amount of time in the interim.
I have already successfully created a rule that:
1. updates the active drawing in various ways
2. saves
3. creates a pdf in the same location as the drawing file
4. closes the drawing
I am very happy with this progress, but if I am able to go a step further, it would same a ton of time for future workflows. Here is my goal:
The drawing is saved in a project folder, and will be 1 to 5 sub-folders deep
(ex1. Example Project Folder 123\02 Sector 1\03 Frame\01 Frame Plates\Frame Plate 01.dwg)
(ex2. Example Project Folder 456\01 GA\GENERAL ARRANGEMENT.dwg)
I want the PDF saved in a different folder structure that mimics where the drawing is located.
I would like the rule to backtrack up the file structure until it finds a folder called "$Fabrication Data" and then navigate to or create the required sub-folders to mimic the original location. The PDF save location would be as follows:
(ex1. Example Project Folder 123\$Fabrication Data\02 Sector 1\03 Frame\01 Frame Plates\Frame Plate 01.pdf)
(ex2. Example Project Folder 456\$Fabrication Data\01 GA\GENERAL ARRANGEMENT.pdf)
Solved! Go to Solution.
Solved by Ralf_Krieg. Go to Solution.
Hello
You can try this function.
Private Function GetPath(oDrawDoc As DrawingDocument) As String
Dim sFullDocumentPath As String = IO.Path.GetDirectoryName(oDrawDoc.FullDocumentName)
Dim aPathParts() As String = Strings.Split(sFullDocumentPath, "\")
For i=0 To UBound(aPathParts)
sNewPath = snewpath & aPathparts(i) & "\"
If IO.Directory.Exists(sNewPath & "\$Fabrication Data") Then
sNewPath=sNewPath & "$Fabrication Data\"
End If
Next
Return snewpath
End Function
Call it from your sub via
Dim MyDrawDoc as DrawingDocument=ThisDoc.Document
Dim mySavePath as String = GetPath(myDrawDoc)
AFAIK the save methods to export a PDF creates all folders that are missing in the given save path (if you have proper rights).
For some reason I can't get this to work. I tried running just the piece you supplied and put in a line to display the sNewPath value in a message box, no message box would appear. No error is displayed when the code is run, but it seems to prevent itself from finishing.
Hello
Tested it again and for me it worked. I wrote it in a little test rule with soma additional checks.
Sub Main
Dim oApp As Inventor.Application = ThisApplication
If oApp.Documents.Count = 0
MsgBox("A drawing document must be open and active",,"iLogic")
Exit Sub
End If
If Not oApp.ActiveDocumentType=DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A drawing document must be open and active",,"iLogic")
Exit Sub
End If
Dim MyDrawDoc As DrawingDocument=ThisDoc.Document
If MyDrawDoc.FullDocumentName = "" Then
MsgBox("The drawing document needs to be saved before", , "iLogic")
Exit Sub
End If
Dim mySavePath As String = GetPath(MyDrawDoc)
MsgBox(mySavePath)
End Sub
Private Function GetPath(oDrawDoc As DrawingDocument) As String
Try
Dim sFullDocumentPath As String = IO.Path.GetDirectoryName(oDrawDoc.FullDocumentName)
Dim aPathParts() As String = Strings.Split(sFullDocumentPath, "\")
For i=0 To UBound(aPathParts)
sNewPath = snewpath & aPathparts(i) & "\"
If IO.Directory.Exists(sNewPath & "\$Fabrication Data") Then
sNewPath = sNewPath & "$Fabrication Data\"
bFound = True
End If
Next
'onlöy return path if folder $Fabrication Data was found
If bfound=True Then
Return snewpath
Else
Return Nothing
End If
Catch ex As Exception
MsgBox(ex)
Return Nothing
End Try
End Function
I see 🙂 it works very well! I got it implemented with my publishing code. Now the only issue is that it wont create missing folders xD Very very close here! Your code was brilliant, I was just not understanding.
I inserted this into Sub Main:
If Not System.IO.Directory.Exists(mySavePath) Then System.IO.Directory.CreateDirectory(mySavePath) End If
Now all is perfect! I really appreciate the help!!
I would like to display a warning message if the PDF already exist. The user would then have the option "yes" to proceed with publishing or "No" to stop the rule for running. I tried this and it ran, but it overrode the existing PDF and didnt display a warning first:
If System.IO.Directory.Exists(oDataMedium.FileName) Then Answer = MessageBox.Show("PDF ALready Exists. Override?", "WARNING", MessageBoxButtons.YesNo) If Answer = vbNo Then Return Else End If
Hello
If you want to know a file exist, then don't ask for directory exist.
If System.IO.File.Exists(oDataMedium.FileName) Then Answer = MessageBox.Show("PDF Already Exists. Override?", "WARNING", MessageBoxButtons.YesNo)
If Answer = vbNo Then
Return
Else
End If
Can't find what you're looking for? Ask the community or share your knowledge.