Hi,
I want export my files in the same path that my document.
But it doesn't work.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim LocationName As String
Dim LocationType As LocationTypeEnum
Dim oPath As String
Set oPath = oDoc.LocationName
Why it doesn't work ?
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
As you would easily see in the API Help:
LocationName is not a valid method on the 'document' class of objects. The only 2 available methods are FullFileName, FullDocumentName and DisplayName. DisplayName has no Path information, FullDocumentName will also denote the various LODs, therefore you must use FullFileName.
That means you will get the full string of the file path and must do string operations to extract the part that you need.
In VBA theres no direct function to get it. But from this StackOverflow post this may help.
Public Function DirFromPath(strFullPath) As String DirFromPath = Left(strFullPath, InStrRev(strFullPath, "\")) End Sub
Dim oPath As String = ThisDoc.Path
Try this one.
Hi,
I think is more simple if I give you this small piece of code....
Sub test() MsgBox (mpath(ThisApplication.ActiveDocument)) End Sub Function mpath(oDoc As Inventor.Document) As String mpath = Replace(oDoc.FullDocumentName, oDoc.DisplayName, "") End Function
Dear Owner2229, you have suggested an Ilogic code and it's correct and work fine (as ilogic) but It's not VBA as requested....
Bregs
Rossano Praderi
Thanky you,
With you piece of code, the macro works good.
mpath = Replace(oDoc.FullDocumentName, oDoc.DisplayName, ""
Below, an extract of the code
'Set partnumber for the filename
Dim oPartNumber As Property
Dim PartNumber As String
Set oPartNumber = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number")
PartNumber = CStr(oPartNumber.Value)
'Set saving path = active file path
Dim FullFileName As String
FullFileName = oDocument.FullFileName
mpath = Replace(oDocument.FullDocumentName, oDocument.DisplayName, "")
oDataMedium.FileName = mpath & PartNumber & ".pdf"
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
,
Absolutely true, let me do a correction....
Function mpath(oDoc As Inventor.Document) As String mpath = Left(oDoc.File.FullFileName, InStrRev(oDoc.File.FullFileName, "\")) End Function
Sorry for my mistake...
....and as the same suggested by Mr.Rodney Thomas with few adaptations
Bregs
Rossano Praderi
Can't find what you're looking for? Ask the community or share your knowledge.