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: 

API close drawing + part

2 REPLIES 2
Reply
Message 1 of 3
Jefkee
280 Views, 2 Replies

API close drawing + part

Hi,

 

I have a Q: how can i close a drawing + part using ilogic?

 

Why:

I have this rule to export partslists from .dwg to a Excel template that is launched from my TOP-assembly.

 

What it does is:

- Open the drawing that contains the partslists

- Export partslist via API (trigger on open document)

 

What it  need to do is close the drawing afterworth, but i cannot find the right way to do this.. can someone help me?

 

 

Thanks!!

Inventor 2013
2 REPLIES 2
Message 2 of 3
Curtis_Waguespack
in reply to: Jefkee

Hi Jefkee,

 

Here is a quick iLogic example that you can run from the assembly file. It will save and close the assembly, and then open a drawing file of the same name. For example Roadrunner_Catcher.iam expects a drawing file named Roadrunner_Catcher.idw

 

Once the drawing is open the parts list is exported as an XLS  (example: Roadrunner_Catcher.xls ) and then the drawing is closed.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim oControlDef As ControlDefinition
oControlDefs = ThisApplication.CommandManager.ControlDefinitions

'save the current file (assumes the assembly is active)
ThisDoc.Save
'change the extension to *.idw
sDrawName = ThisDoc.ChangeExtension(".idw") 
'get parts list XLS file path and name
sXLS = ThisDoc.ChangeExtension(".xls") 
'close the current file (assembly file) 
oControlDefs.Item("AppFileCloseCmd").Execute
'open the drawing file, false opens the file without generating the graphics
ThisApplication.Documents.Open(sDrawName, True)

' - - - - - - - export Parts List code - - - - - - - - - - - - - - - - - - - 
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument 
'look at the first sheet of the drawing
Dim oSheet As Inventor.Sheet
oSheet = oDrawDoc.Sheets(1) 
'get the 1st Partslist on the sheet.
Dim oPartslist As PartsList
oPartsList = oSheet.PartsLists(1)
'create a new NameValueMap object
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'choose to autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = True
'check for existing XLS file and delete it if found
Try
'delete XLS file
Kill (sXLS)
Catch
'catch error if XLS file doesn't exist
End Try
'export the Partslist to Excel.
oPartslist.Export(sXLS,PartsListFileFormatEnum.kMicrosoftExcel, oOptions)   
' - - - - - - - export Parts List code - - - - - - - - - - - - - - - - - - 

'close the drawing file
oControlDefs.Item("AppFileCloseCmd").Execute

 

Message 3 of 3
Jefkee
in reply to: Curtis_Waguespack

Hi,

 

Thanks for replying on this matter! I tried the rule, but didn't have time to come back on it.

The rule works, but i gives me an error after closing my drawing.

 

Is this normal? Or did i do somthing wrong?

 

Code:

Dim oControlDef As ControlDefinition
oControlDefs = ThisApplication.CommandManager.ControlDefinitions


'close the drawing file
oControlDefs.Item("AppFileCloseCmd").Execute

 

Error:

Edit Rule

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

 

 

Inventor 2013

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

Post to forums  

Autodesk Design & Make Report