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: 

trim drawing filename

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Dan_Margulius
644 Views, 5 Replies

trim drawing filename

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 

 

5 REPLIES 5
Message 2 of 6

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



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

Thank you,
I will check this method.
I understand that there is no trimming in ilogic?
Thanks
Dan
Message 4 of 6

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.

 http://help.autodesk.com/view/INVNTOR/2013/ENU/?caas=caas/vhelp/help-dev-autodesk-com/v/Inventor/enu...

 

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



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

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

Message 6 of 6

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.

http://forums.autodesk.com/t5/inventor-general-discussion/ilogic-rules-work-when-run-separately-not-...

 

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



--------------------------------------
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  

Autodesk Design & Make Report