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: 

ILogic-save as rule

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
JamieSENG
2212 Views, 5 Replies

ILogic-save as rule

Previous made post but haven't had any replies so trying my luck in this category.

For initial post:
Hi all. Having a problem using ilogic at the moment with an issue that's been with us for some time now. When the company I work for needs to have work outsourced it requires an idw or dwg to be converted to autocad dwg format namely 2000/2000lt. Until I came across ilogic "save as" rule it was a matter of opening each drawing and saving it manually to a folder on my desktop. As you'll imagine it was very time consuming but then out of luck a friend refered me to ilogic and it's save as rule which until now as worked fine. Now the amount of drawings I have to convert are taking me around a day to do (if I'm lucky).

Would I be greedy by thinking there's a way around this using ilogic and a larger rule.

What would be perfect for me would be a rule alike the "save as" rule that saves all active windows in inventor to a sub folder resulting in one "run rule" click as opposed to going through each drawing and running the rule every time.

Worth noting also is the drawings I need to convert a also drawings which are archived so a trigger rule won't work. Also not all the drawings need to be converted so I see a run rule being the better option.

If anyone is having a similar issue or as found another solution it would be great to hear it.

Thanks in advance.
5 REPLIES 5
Message 2 of 6
NL-Laurens
in reply to: JamieSENG

Hi Jamie,

 

You can write a VBA function (Tools > VBA Editor) that loops tru all the files in a specific directory, opening each file and saving it to the same folder as DWG.

 

For file looping inside directory:

 

http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba

 

For saving IDW to DWG:

 

http://forums.autodesk.com/t5/Inventor-Customization/Inventor-IDW-To-AutoCAD-2000-DWG/td-p/2644227

 

I hope you'll find your answers,

 

Good luck!

 

Laurens

Message 3 of 6
JamieSENG
in reply to: JamieSENG

Hi Laurens

That's not quite what I'm trying to achieve. You see the way the vaults been used at my place means that all different projects are coupled into one project. So unfortunately leaving the drawings muddled up in different folders. It needs organising no doubt but for now until it quietens down I'm looking for a alternative method.

Although the idea of the vba is exactly need to do the job as the basic save options aren't sufficient.

Do you have any coding experience that may help me get started?

Basically I think what I need to do Is loop the "save as" rule to execute all open windows. Although there's more to it that's partially the main of it. Besides the above id need to keep save as that file name for each file.

Any ideas..?
Message 4 of 6
rjay75
in reply to: JamieSENG

Here's something to get you started.

This was cobbled together using some the Export DWG sample in the API help file.

 

You have to use the DWG translater to save as autocad files. Before you run it you want to use the Export to DWG command to save your Autocad options. Use the name of the exported file in the strIniFile variable.

 

Save this code in a new external rule file.

 

Imports SysIO = System.IO
Sub Main()
	'See if there are any open views
	If (ThisApplication.Views.Count > 0) Then
	
		'Setup Translator to dwg
		Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	
		Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
		oContext.Type = kFileBrowseIOMechanism
	
		' Create a NameValueMap object
		Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	
		' Create a DataMedium object
		Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
	
				
		'Go through each view and save if it's a drawing document
		For Each view As View In ThisApplication.Views
			If view.Document.DocumentType = kDrawingDocumentObject Then
				'Get the directory file is saved in. Can replace this with specific directory
				Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName)
				'Get name of file without the extension and add _acad2k to it.
				oDataMedium.MediumType = kFileNameMedium
				oDataMedium.FileName = dwgDir & "\\" & _
SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) & _
"_acad2k.dwg" ' Check whether the translator has 'SaveCopyAs' options If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then 'Use Export To DWG to save drawing configuration and set here Dim strIniFile As String = "C:\\Temp\\DWGOut.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile 'Save File DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium) End If End If Next End If End Sub

 

Message 5 of 6
ryandeamnesiaxoda
in reply to: rjay75

Hello Rodney Thomas Good morning! sorry to bother but seeing that this issue could be resolved to export an idw to dwg, I would like to know how you can do that at the time you are recording the file asks you the destination of this as if you were doing a Save as.
Thank you very much in advance!
Message 6 of 6
rjay75
in reply to: ryandeamnesiaxoda

Below is the rule modified to display the save as dialog to select the filename and location.

 

 

Imports SysIO = System.IO
Sub Main()
	'See if there are any open views
	If (ThisApplication.Views.Count > 0) Then
	
		'Setup Translator to dwg
		Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	
		Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
		oContext.Type = kFileBrowseIOMechanism
	
		' Create a NameValueMap object
		Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	
		' Create a DataMedium object
		Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
	
				
		'Go through each view and save if it's a drawing document
		For Each view As Inventor.View In ThisApplication.Views
			If view.Document.DocumentType = kDrawingDocumentObject Then
				'Get the directory file is saved in. Can replace this with specific directory
				Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName)
				'Prompt User for name of file
				Dim saveDlg = GetFileDlg(dwgDir)
				saveDlg.ShowSave()
				'Cancel Process if no name selected
				If String.IsNullOrEmpty(saveDlg.FileName) Then Exit For
				Dim newFileName = saveDlg.FileName
				'If name is the same as document name append acad to it.
				If newFileName.Equals(view.Document.FullFileName) Then
					newFileName = dwgDir & "\\" & _
                                    SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) & _
                                     "_acad.dwg"
				End If
				
				'Get name of file without the extension and add _acad2k to it.
				oDataMedium.MediumType = kFileNameMedium
				oDataMedium.FileName = newFileName
				
				' Check whether the translator has 'SaveCopyAs' options
				If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then
					'Use Export To DWG to save drawing configuration and set here
					Dim strIniFile As String = "C:\\Temp\\DWGOut.ini"
					' Create the name-value that specifies the ini file to use.
					If SysIO.File.Exists(strIniFile) Then
						oOptions.Value("Export_Acad_IniFile") = strIniFile
					Else
						MessageBox.Show("The settings ouput file " + strIniFile + " cannot be found.", "Export INI")
Exit For End If 'Save File DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium) End If End If Next End If End Sub Private Function GetFileDlg(defaultPath As String) As Inventor.FileDialog Dim fDlg As Inventor.FileDialog ThisApplication.CreateFileDialog(fDlg) fDlg.Filter = "Autocad Drawing Files (*.dwg)|*.dwg" fDlg.DialogTitle = "Save As Autocad Drawing" If Not String.IsNullOrEmpty(defaultPath) Then fDlg.InitialDirectory = defaultPath End If Return fDlg End Function

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report