Help: Save (not Save As) using iLogic

Help: Save (not Save As) using iLogic

Anonymous
Not applicable
979 Views
7 Replies
Message 1 of 8

Help: Save (not Save As) using iLogic

Anonymous
Not applicable

I would like to find a way to save (not save as) an Inventor drawing using iLogic.

 

Is there a way to "Save" so that the open file's name is updated?

 

Thanks,

 

Rich

0 Likes
Accepted solutions (1)
980 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Hi Rich,

 

It can be done with the following ilogic code.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
oDrawDoc.Save

If you find this was helpful please accept this as solutions / Press the kudos button Smiley Wink

 

Cheers,

SK

0 Likes
Message 3 of 8

Anonymous
Not applicable

 Hey SK,

 

Thank you for trying to help me out. The code by itself gave the following error:

 

"Error in rule: Rule10, in document: Drawing1

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

 

Here is the code I am trying to use. It works the same as when I try to use the "Save As" command.

 

Thanks,

 

Rich

 

'Dim title As String = "converted to title case"
'    Console.WriteLine(StrConv(title, VbStrConv.ProperCase))
DrawingName = iProperties.Value("custom","Drawing No.") & "_" & StrConv(iProperties.Value("custom","Desc. 1"), VbStrConv.ProperCase) & "_" & StrConv(iProperties.Value("custom","Desc. 2"), VbStrConv.ProperCase) & "_" & StrConv(iProperties.Value("custom","Navision PN"), VbStrConv.ProperCase)
DesiredPath = "C:\........specified location....."

NewFileName = DesiredPath & "\" & DrawingName & ".idw"


'check file name to see if it is used
	'if it is, ask the user to overwrite
	'if it's not, save the file

question = MessageBox.Show("Is this a good file name?:  " & DrawingName & ".idw", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If question=vbYes Then

	If System.IO.File.Exists(NewFileName) Then
	
		question = MessageBox.Show("File exists, do you want to overwrite?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	
			If question = vbYes Then 
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.ActiveDocument
				oDrawDoc.Saveo(Newfilename,True)
			Else If question =vbNo Then
				MessageBox.Show("File was not overwritten", "iLogic Message")
			End If
	
	Else 
		
		ThisDoc.Document.SaveAs(Newfilename,True)
	
	End If 

Else If question=vbNo Then
	MessageBox.Show("Please update: Drawing #, Desc. 1, Desc. 2, & Navision PN", "iLogic Message")
End If
0 Likes
Message 4 of 8

Anonymous
Not applicable

I think you have a typo?

oDrawDoc.Saveo(Newfilename,True) should be  oDrawDoc.Save (Newfilename,True)

0 Likes
Message 5 of 8

Anonymous
Not applicable

Thanks Waynefisher,

 

I saw that after posting but was unable to edit my post. Same error with the typo fixed.

 

 

Thanks,

 

Rich

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

I think the save should be oDrawDoc.Save nothing after that.

0 Likes
Message 7 of 8

Anonymous
Not applicable
Accepted solution

Hi Rich,

 

As Per your code you are trying to save the drawing file with different name. However I guess the active document was in the name of "Drawing 1" which was not already saved in the desired path.

 

To use save option the drawing file should be saved at least once before executing the save command.

 

The Syntax to save document is just

 

ThisApplication.ActiveDocument.save

There should not be any parameter to be assigned.

 

I've modified your code slightly which might be helpful for you.

 

'Dim title As String = "converted to title case"
'    Console.WriteLine(StrConv(title, VbStrConv.ProperCase))
DrawingName = iProperties.Value("custom","Drawing No.") & "_" & StrConv(iProperties.Value("custom","Desc. 1"), VbStrConv.ProperCase) & "_" & StrConv(iProperties.Value("custom","Desc. 2"), VbStrConv.ProperCase) & "_" & StrConv(iProperties.Value("custom","Navision PN"), VbStrConv.ProperCase)
DesiredPath = "C:\........specified location....."

NewFileName = DesiredPath & "\" & DrawingName & ".idw"


'check file name to see if it is used
	'if it is, ask the user to overwrite
	'if it's not, save the file

question = MessageBox.Show("Is this a good file name?:  " & DrawingName & ".idw", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If question=vbYes Then

	If System.IO.File.Exists(NewFileName) Then
	
		question = MessageBox.Show("File exists, do you want to overwrite?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	
			If question = vbYes Then 
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.ActiveDocument
				oDrawDoc.Save 'Modified Line 1
			Else If question =vbNo Then
				MessageBox.Show("File was not overwritten", "iLogic Message")
			End If
	
	Else 
		
		ThisDoc.Document.SaveAs(Newfilename,True)
	         ThisApplication.Documents.Open(NewFileName,True)'Modified Line 2
	End If 

Else If question=vbNo Then
	MessageBox.Show("Please update: Drawing #, Desc. 1, Desc. 2, & Navision PN", "iLogic Message")
End I 

 

Message 8 of 8

Anonymous
Not applicable

Thanks SK,

 

The issue was that there was already a document in the specified folder with the desired file name. 

 

A new drawing tab does open up with the new drawing number (the tabs are "Drawing 1", "new drawing #". Is there an easy way to fix this?

 

Thank you again,

 

****EDIT**** In case anyone tries to use the solution code. The code in the solution is missing an "f" in the last "End If" statement

 

 

Rich

0 Likes