Hello,
Our drawing names are build with preffix "mac" and then file name.
For example: "mac-md2234"
Whenever I output the pdf with ilogic I want to trim the string and get only "md2234"
without the "mac" .
How to do in Ilogic?
Thank you
Dan
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
Hi, the easier way to cut-off "mac-" from the filename is the follow...
' I'm using "ThisDoc.PathAndFileName(True)" as example ' this will replace the text "\mac-" with "\", check the pathname before use this method (.NET function) MsgBox(ThisDoc.PathAndFileName(True).Replace("\mac-","\")) ' visual basic function MsgBox(Replace(ThisDoc.PathAndFileName(True),"\mac-","\"))
If you have a more complex requirements, give to us more details.
Bregs
Rossano Praderi
Hi Dan,
the Ilogics editor is a mixture of integrated functions/commands, Vb.net and Visual Basic.
On my first answer I used what I think could be the best solution.
Also, I would like to give you a revised code where I use two functions mentioned within the Ilogics editor (both are Vb.NET functions).
oName = "c:\Test\mac-md2234.idw" 'oName = ThisDoc.PathAndFileName(True) ' Assign the PathAndFilename variable to oName oRep = "\mac-" ' this will replace the text "\mac-" with "\", check the pathname before use this syntax MsgBox(oName.Replace(oRep,"\")) ' visual basic function MsgBox(Replace(oName,oRep,"\")) ' Example with Left(), Right and Len() function, if you have a file name with variable ' length this example Is Not Right For you, these functions are also in Vb.net MsgBox(Left(oName,Len(oName)-14) & Right(oName,10))
Look at this link for "String Functions" and you will find the informations.
This Link is for more informations about Vb.Net functionalities.
http://msdn.microsoft.com/en-us/library/System.String(v=vs.110).aspx
I've some curiosities and may be you can help me.
Did you tried my code?
Is useful?
It's working?
My answer is helpful?
Bregs
Rossano Praderi
Hello,
I liked the trick with the Replace function.
I did not know it's possible. I picked the first way as it looks simpler but unfortunetly it is not working.
I get the message that it did change the name but there is no where to be found. Please check my screenshots.
At the end i will need my pdf file to use this funcrtion.
Best Regards,
Dan
Hi Dan,
I see your screenshots and something make me confused, with my first example you can only check if the filename/path are correct after using the "Replace" function. This example don't have nothing to do with saving or exporting the file.
If you would like to use the "Replace" functionality you should do something similar to the following examples.
Sub Main oName = ThisDoc.PathAndFileName(False).Replace("\mac-","\") & ".pdf" ' Assign the PathAndFilename variable to oName and then change the file extension Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(ThisDoc.PathAndFileName(True)) oDocument.SaveAs(oName, True)' Save the PDF in the same folder as idw 'SaveAsPdf(oDocument,oName) ' This Subroutine have more options End Sub Sub SaveAsPdf(oDocument As Inventor._Document, oFileName As String) oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = oDocument.Sheets.Count End If oDataMedium.FileName = oFileName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Publish Document End Sub
You will find more informations on this post.
I would like to suggest you to use this rule as external rule.
In this way you can modify the external rule without changing each file with the embedded rule.
iLogicVb.RunExternalRule("ruleFileName")
Bregs
Rossano Praderi