Inventor Drawing iLogic to save as model user parameter file name

Inventor Drawing iLogic to save as model user parameter file name

Anonymous
Not applicable
790 Views
6 Replies
Message 1 of 7

Inventor Drawing iLogic to save as model user parameter file name

Anonymous
Not applicable

Hi All,

drawing rule:

SyntaxEditor Code Snippet

FilePath = "W:\M&R Plating"

If (Not System.IO.Directory.Exists(FilePath)) Then
	System.IO.Directory.CreateDirectory(FilePath)
End If

ThisDoc.Document.SaveAs(FilePath & "\" & ThisDoc.FileName(False) & ".pdf", True)
ThisDoc.Document.SaveAsInventorDWG(filePath & "\" & ThisDoc.FileName(True), True) 

 How can I replace ThisDoc.FileName above with the user parameter partNumber from the .ipt file?

2018-11-29 10_27_24-Autodesk Inventor Professional 2019 - [Scorer Head].pngThank you

0 Likes
791 Views
6 Replies
Replies (6)
Message 2 of 7

JamieVJohnson2
Collaborator
Collaborator

Get the Parameter by its name from the active document's ComponentDefinition's Parameters collection.  Then use the parameter's value as the variable in your code.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Jamie, thanks for your help.  I'm trying to do this from the drawing file and access the model's parameter.  I'm fairly new to this, so correct me if i'm off base, but this would not be the active document, correct?

0 Likes
Message 4 of 7

Anonymous
Not applicable

SyntaxEditor Code Snippet

Dim partNum As String
partNum = Parameter("Scorer Head.ipt", "partNumber")
MessageBox.Show(partNum)


FilePath = "W:\M&R Plating"

If (Not System.IO.Directory.Exists(FilePath)) Then
	System.IO.Directory.CreateDirectory(FilePath)
End If

ThisDoc.Document.SaveAs(FilePath & "\" & ThisDoc.FileName(False) & ".pdf", True)
'ThisDoc.Document.SaveAs(ThisDoc.FileName(True), True)
'ThisDoc.Document.SaveAsInventorDWG(FilePath & "\" & ThisDoc.FileName(True), True) 
ThisDoc.Document.SaveAsInventorDWG(FilePath & "\" & partNum, True)

 

This displays the parameter correctly in the message box, but it won't pull the value into the saveas path. 

 

i get this error:  The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Message 5 of 7

JamieVJohnson2
Collaborator
Collaborator

Looks like your close here then.  What needs to happen next is you need to construct a file path string that uses partNum for your saveas command.  While your method should work, I have separated it from the saveas command to be sure it is what I wanted.

  Example:

dim strFileExtension as string = system.io.Path.GetExtension(ThisDoc.FileName) 'should return something like '.idw'

Dim strNewFilePath as string = FilePath & "\" & partNum & strFileExtention

'make sure file path is correct before assuming:

msgbox(strNewFilePath)

ThisDoc.Document.SaveAsInventorDWG(strNewFilePath, True)

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 6 of 7

Anonymous
Not applicable

Hi Jamie,  I appreciate the help.  It still doesn't seem to like using a variable as the file path for SaveAsInventorDWG.  It works perfectly if i use SaveAs and type in the .idw or .dwg...the problem here is it defaults the dwg to exporting a acad dwg and i am needing inventor dwg.  This also works fine:

SyntaxEditor Code Snippet

ThisDoc.Document.SaveAsInventorDWG(FilePath & "\" & ThisDoc.FileName(True), True) 

 i think this is a bug and may have to just stick to using .idw 

0 Likes
Message 7 of 7

Anonymous
Not applicable

Counter intuitive, but this worked!

 

SyntaxEditor Code Snippet

Dim partNum As String
partNum = Parameter("Scorer Head.ipt", "partNumber")

FilePath = "W:\M&R Plating"

If (Not System.IO.Directory.Exists(FilePath)) Then
	System.IO.Directory.CreateDirectory(FilePath)
End If

ThisDoc.Document.SaveAs(FilePath & "\" & partNum & ".pdf", True)
ThisDoc.Document.SaveAsInventorDWG(FilePath & "\" & partNum & ".DWG", True)

trigger = iTrigger0
0 Likes