Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[VBA] Get back the current path of active document

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
8422 Views, 7 Replies

[VBA] Get back the current path of active document

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 ?

7 REPLIES 7
Message 2 of 8
MechMachineMan
in reply to: Anonymous

As you would easily see in the API Help:

 

api HELP.JPG

 

 

 

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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 8
rjay75
in reply to: Anonymous

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

 

Message 4 of 8
Owner2229
in reply to: Anonymous

Dim oPath As String = ThisDoc.Path

Try this one.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 8
rossano_praderi
in reply to: Anonymous

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 6 of 8
Anonymous
in reply to: 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

,

Message 7 of 8
MechMachineMan
in reply to: Anonymous

Won't that method become buggy eif you are to rename a part in the browser?

As far as I know the Displayname doesn't always necessarily match the end
segment of the filename so this may cause issue in the futures.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 8

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...Smiley Embarassed

 

....and as the same suggested by Mr.Rodney Thomas with few adaptations

 

 

 

 

Bregs

Rossano Praderi

 

 

 



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report