Get text part from the Drawing file name and without extension

Get text part from the Drawing file name and without extension

ARamos08
Participant Participant
4,372 Views
5 Replies
Message 1 of 6

Get text part from the Drawing file name and without extension

ARamos08
Participant
Participant

Hi all,

 

I have my inventor Drawings that are saved like this: PESTM-DW-02022020123456.idw

It is just a random number base on date and time.

 

For my Title Block I want just part from the text file like this: DW-02022020123456.

It is always the same text metric without the file extension.

 

Is there any way I cant trim the file name ?2020-06-02_100220.jpg

 

 

Accepted solutions (2)
4,373 Views
5 Replies
Replies (5)
Message 2 of 6

lena.talkhina
Alumni
Alumni

Hello @ARamos08 !

 

Welcome to Autodesk Inventor community!

Great to see your questions hear. Hope you find a solution soon.

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.



Лена Талхина/Lena Talkhina
Менеджер Сообщества - Русский/Community Manager - Russian

0 Likes
Message 3 of 6

arkelec
Collaborator
Collaborator
Accepted solution

iLogic can get the filename without the extension:

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2015... 

 

You'll need to create a custom property (mine is called c_File_Name), then read that in the title block.

iProperties.Value("Custom", "c_File_Name") = iFileName
iFileName = ThisDoc.FileName(False) 'without extension

  

Not sure about the leading characters "PESTM" though.  I think in VB.net, you can select text by excluding a number of characters from either end of a string.

 

You might struggle with this if you are new to iLogic.  I do.

 

 

0 Likes
Message 4 of 6

mcgyvr
Consultant
Consultant

@ARamos08 wrote:

Hi all,

 

I have my inventor Drawings that are saved like this: PESTM-DW-02022020123456.idw

 

For my Title Block I want just part from the text file like this: DW-02022020123456.

 

 


Is the "PESTM-" always going to be a consistent 6 characters that you want to remove from the beginning? Or could it be 5 or 7 or whatever? If it could be more do you always just want to remove up to and including the first "-"?

 

If PESTM- is always going to be consistent 6 characters then this code will trim that out..

'Create a new custom iprop of the filename without extension and remove the first 6 characters of the string
iProperties.Value("Custom", "FileNameNoExt") = ThisDoc.FileName(False).Remove(0, 6)


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 6

skipmcnoob
Explorer
Explorer

Could you describe this step by step? I'm having trouble following your example.

 

Where should I add custom property rule? To my part template or to my drawing template? 

How can I call this custom property in my drawing title block section instead of the default file name that includes the extension?

 

Help with this would be appreciated.

Cheers!

0 Likes
Message 6 of 6

arkelec
Collaborator
Collaborator
Accepted solution

Hi @skipmcnoob 

 

1.  In your part/assembly, create the custom iProperty  "c_File_Name" (click iProperties>Custom)

 

Create iProp 01.png

 

2.  Save the file.

 

3.  Populate the custom iProp with using the code:

Sub Main ()

	Dim oDoc As Document = ThisApplication.ActiveDocument

	iFileName = ThisDoc.FileName(False) 'without extension
	iProperties.Value("Custom", "c_File_Name") = iFileName

End Sub

 

4.  In the drawing, add some text:

 

Add iProp in DWG 01.png

 

5.  Select in the left hand drop down box "Custom Properties - Model".

 

6.  Select in the right hand drop down box your custom iProp "c_File_Name".

 

The Filename from the part is now shown, without the filetype extension.  You can integrate this into your title block by using the same principle, either with new text or modify the existing text field.

 

Hope this helps.

 

P.S.  There is code available to automatically add the custom iProp in the part or assembly file, if it doesn't already exist, but if you add the custom iProp to your templates, you won't need it.