Folder creation

Folder creation

phila
Enthusiast Enthusiast
543 Views
6 Replies
Message 1 of 7

Folder creation

phila
Enthusiast
Enthusiast

Why does this create a folder with an added character?

 

 

It adds a "T" or a "C" depending on the name of folder the the drawing is in.  In this case, the folder named T-II creates "TPDF" and Commom creates "CPDF"

 

oFolder = ThisDoc.Path (InStrRev(ThisDoc.Path,"\")) & "PDF"

 

'Check for the PDF folder and create it if it does not exist

If Not System.IO.Directory.Exists(oFolder) Then

System.IO.Directory.CreateDirectory(oFolder)

End If

 

What is the correct way to do this?

0 Likes
544 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor

You could try with alternate syntax and see if that helps...

 

oActiveDocName = ThisApplication.ActiveDocument.FullFileName

 

 

 

'"This is cool"

'Search c with instrev would return 4 as it is 4th from the end

'Thus, subtract 3 from the 12 char length to get the pos from left; 9

 

oPos = Len(oActiveDocName) - InStrRev(oActiveDocName, "\")

 

'We know the location of the last \ now, so we use left to take all of the string infront of that.

 

'This will return the folder length without the last slash, to get the slash, simply change oPos below to oPos + 1

'ie'; C:\MyDocuments will be returned by this.

 

oFolder = Left(oActiveDocName, oPos)

 

MsgBox(oFolder)


--------------------------------------
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
0 Likes
Message 3 of 7

phila
Enthusiast
Enthusiast

Thank you for the reply.

I'm trying to learn/understand code writing, how it works, and how to apply it. All help and explaination is much appreciated.

 

Still don't completly understand your explaination on how it works and why it would be used over something more simplistic.

More study needed to get a good understanding of what it does and why to use it.

 

I found other iLogic code here on the forum where they were saving to a folder and if it didn't exist, create it.

 

This what I ended up with that does work.

 

oFolder = ThisDoc.Path & "\PDF FILES"

 

'Check for the PDF FILES folder and create it if it does not exist

If Not System.IO.Directory.Exists(oFolder) Then

System.IO.Directory.CreateDirectory(oFolder)

End If

 

Does this create or allow problems?

 

 

 

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor
It's just using a more inventor specific method. ThisDocument.Path is
iLogic addin specific

--------------------------------------
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
0 Likes
Message 5 of 7

phila
Enthusiast
Enthusiast

I tried Thisdocument.path instead of ThisDoc.Path and get an error needing to declare it. Could do that easily, just adds another line to do it.

The code uses ThisDoc.Path and ThisDoc,FileName. Neither are declared as far as I can tell in the overall code, but still work.

 

Is ThisDoc used in VB and just happen to work in Ilogic without declaring it?

 

 

0 Likes
Message 6 of 7

MechMachineMan
Advisor
Advisor
It's an iLogic snippet; the iLogic add-in for inventor contains 'shortcut'
snippets which make you type a little less. If you look in inventor
programming help it gives you full/proper methods and properties that would
work without the inventor add-in called if you ever expand to making
add-ins or external .exe's that access Inventor functionality.

Ie; ThisDoc is the shortcut for ThisApplication.ActiveDocment which is
actually an inventor shortcut for a call to the inventor app... which would
have to be called by something like m_InvApp = ApplicationId
(2938-9843-183838-1¥2¥)...... or at leat I'm pretty sure of haha

--------------------------------------
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
0 Likes
Message 7 of 7

phila
Enthusiast
Enthusiast

Thanks again for the clarification.

0 Likes