Ilogic: Exporting .pdf file from drawing to separate location

Ilogic: Exporting .pdf file from drawing to separate location

Anonymous
Not applicable
2,726 Views
9 Replies
Message 1 of 10

Ilogic: Exporting .pdf file from drawing to separate location

Anonymous
Not applicable

Hello,

 

I would like to know if this is possible using Ilogic:

 

Exporting a .pdf from an .idw on save to a different location based off of a description in the title block. So if the title in the title block has the word "ten" in it for example. It would export the pdf on save to a different folder called "ten". If it has the word "eight", it would export it into an "eight" folder. And so on. 

 

Right now we have an ilogic rule to just export the .pdf into the same location as the .idw was saved in. This code is:

 

SyntaxEditor Code Snippet

'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'Sets the Dirctory that the PDF should be saved in
PDFPath = "L:\$WorkingFolder\Designs\"  & DirectoryPath

'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

 Would there be a simple way to modify this code to do what I'm looking for?

 

I hope this makes sense, and thanks for your help!

0 Likes
Accepted solutions (1)
2,727 Views
9 Replies
Replies (9)
Message 2 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous

 

Welcome to the forum. 

 

Note that you can search and ask programming questions of this type on the Inventor Customization forum where the audience is more programming focused:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

See the example below for one way to do this.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

oName = UCase(ThisDoc.FileName(False)) 'without extension

If oName.Contains("TEN") Then
	oFolder = "\Ten"
ElseIf oName.Contains("EIGHT") Then
	oFolder = "\Eight"
End If
	

'Sets the Dirctory that the PDF should be saved in
PDFPath = "L:\$WorkingFolder\Designs\"  & DirectoryPath & oFolder

'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

 

 

EESignature

Message 3 of 10

Anonymous
Not applicable

Thanks for the answer, that works great! Although, as we are using actual part numbers for the .ipt, would I be able to link this new piece of code to the Title section of the title block (attached image) that is calling it from the Iproperties from the .ipt?

 

 

0 Likes
Message 4 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

Assuming the titleblock is using the part number iproperty from the model, something like this should work.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'get model path and name for first view in drawing
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

'get part number iprop from model doc
oPartNumber = iProperties.Value(modelName, "Project", "Part Number")

'make all CAPS for exact string contains comparison
oPartNumber = UCase(oPartNumber) 


If oPartNumber.Contains("TEN") Then
	oFolder = "\Ten"
ElseIf oPartNumber.Contains("EIGHT") Then
	oFolder = "\Eight"
Else 
	oFolder = "\Other"
End If


'Sets the Dirctory that the PDF should be saved in
PDFPath = "L:\$WorkingFolder\Designs\"  & DirectoryPath & oFolder

'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

EESignature

0 Likes
Message 5 of 10

Anonymous
Not applicable

What would be the substitute for UCase if instead of using just letters in the title, it would be a letter and number (i.e. G100) that it would be searching for?

0 Likes
Message 6 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

I'm not sure I fully follow. G100 does not contain the word ten or eight?

 

In the example files that I tested with,  the model part had a part number iproperty value of "1478-eight-aa"... so UCase just sets the variable in the code to be "1478-EIGHT-AA"

 

This line in the code is looking for all caps :

 

If oPartNumber.Contains("EIGHT") Then

 

So using Ucase on the part number just makes sure we don't need to worry about variations such as Eight, eight, eIGHT, and so on.

 

So the numeric or alpha should both work.

 

Note that there might be better ways to do this, so if you provide more examples about the typical values you expect to see, something might come to mind.

 

Edit: Note that I misclicked and accepted a post as a solution on accident, so if you see something about that just ignore it, just me goofing up... I fixed that already.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

EESignature

0 Likes
Message 7 of 10

Anonymous
Not applicable

Sorry, I should have been more specific. All of our .ipt files follow a specific numbering system for a naming convention. I had just used "Ten" and "Eight" as an example. What I would like to see is the Ilogic rule calling the "title" field from the iproperties of the part (which I believe you've already added). The product that we make have a different name to them, G100, or G200 as examples. So if we add the name "G100 - Corner Post" to the title field in the Iproperties, the Ilogic rule would see the "G100" and automatically export the .pdf file into a separate folder called "G100".

 

I hope I'm not making this worse. Thanks for your time!

0 Likes
Message 8 of 10

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Anonymous wrote:

 

I hope I'm not making this worse. 


 

Hi @Anonymous,

 

nope.... I think that makes it easier, which was kind of what I had a hunch about.

 

So you said "Title" in your last post, but my previous example used the iproperty "Part Number"... this example used "Title" though, but the syntax is about the same.

 

So you could do this and just get the left 4 characters of the title.. if that is consistent

 

'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'get model path and name for first view in drawing
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

'get iprop from model doc
oiProp = iProperties.Value(modelName, "Summary", "Title") 
'Get the left 4 chars of the title to use as the fodler name
oFolder = Left(oiProp,4)

'Sets the Dirctory that the PDF should be saved in
PDFPath = "L:\$WorkingFolder\Designs\"  & DirectoryPath  & "\" & oFolder


'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

Or you can use something like this to break the title string at the dash, and then use the first part as the folder name... again assuming the use of the dash is consistent. If you had a Title value of G100_Corner Post this would fail. Note that if you had a value of G100 - Corner Post - Left Side it would still work, as it breaks it at each dash, but uses the first string in the string array

 

'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'get model path and name for first view in drawing
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

'get iprop from model doc
oiProp = iProperties.Value(modelName, "Summary", "Title") 

'split up the value where the dash occurs
Dim sArray As String()
sArray = oiProp.Split("-")

i = LBound(sArray)

'get the first string in the string array
'Trim removes 'whitespace' aka spaces
oFolder = Trim(sArray(i))

'Sets the Dirctory that the PDF should be saved in
PDFPath = "L:\$WorkingFolder\Designs\"  & DirectoryPath  & "\" & oFolder

'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 9 of 10

Anonymous
Not applicable

Awesome! That works perfectly. Thanks alot for youre help!

0 Likes
Message 10 of 10

FrancescoSansotteraUEF4J
Participant
Participant
'Get the Full Path of the file
FullPath = ThisDoc.Path

'Gets the Workspace Path
WorkspacePath= ThisDoc.WorkspacePath()

'Gets the Length of the WorkspacePath String
WorkspacePathLength = Len(WorkspacePath)

'Gets just the Path of the file
PathOnly = ThisDoc.Path

'Removes the Workspace Path from FullPath
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)

'Sets the Dirctory that the PDF should be saved in
PDFPath = "S:\UT\approvato\disegni\"  & DirectoryPath

'Checks to see if that directory exists, if not, it is created
If(Not System.IO.Directory.Exists(PDFPath)) Then
	System.IO.Directory.CreateDirectory(PDFPath)
End If

'Saves the PDF in the desired location
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)

 

 

Errore alla riga 21 nella regola: PDF TO SOL PIU, nel documento: B0006357-TUBO BRACCIO.idw

Il formato del percorso specificato non è supportato.

0 Likes