Custom File naming syntax (beginner!) help

Custom File naming syntax (beginner!) help

paulZKN98
Advocate Advocate
220 Views
2 Replies
Message 1 of 3

Custom File naming syntax (beginner!) help

paulZKN98
Advocate
Advocate

Hi everyone, I am a beginner to ilogic and have thus far only copy and pasted code from others.  I'm trying to write my own code to perform the following function: I would like a default filename scheme for drawings as "partnumber"-"description".idw.  upon the first save.  Example 1234-1234-Bottom Bracket.idw

Here is what my code looks like, if anyone can provide guidance I would be much appreciated. 

 

"ThisDoc.FileName(False) 'without extension" = (iProperties.Value("Project", "Part Number"))(iProperties.Value("Project", "Description"))

I am very excited to be getting into this, I've wanted to branch out into ilogic for some time now but but time hasn't allowed it.  Many many thanks!!

 

 

 

0 Likes
221 Views
2 Replies
Replies (2)
Message 2 of 3

Zach.Stauffer
Advocate
Advocate

ThisDoc.FileName is a read-only property, you can't set it from code. If you are creating a drawing from scratch then you need to make your filename first as a string and have Inventor create the drawing for you.

 

The correct syntax to create the filename would look something like this:

Dim filename = iProperties.Value("Project", "Part Number") & "-" & iProperties.Value("Project", "Description") & ".idw"

 

To create a new drawing you use the ThisApplication object.

Dim drawing as DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObject)

drawing.SaveAs(filename, False) 

 

0 Likes
Message 3 of 3

yan.gauthier
Advocate
Advocate

Hi,

 

Ilogic uses VB.Net, what you are trying to do is called contatenation. It the process of combining several strings into one.

 

VB.Net uses "&" as its concatenation operator: 

filename = iProperties.Value("Project", "Part Number") & " - " & iProperties.Value("Project", "Description")

Also, You cannot change a file name on the fly. It's only upon creating it that you can set its name. If it was possible, we would need a way to update every files that refers to this filename.

0 Likes