
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I have Cobbled together this script from various post on the forums a few monthes ago (thanks for all the snippets I pilfered from examples found here, Wish I could offer propper attribution to this work, but suffice it to say that is not all mine and I could not have done it alone). We have a workflow that involves sending Step files of flattened sheet metal parts to a vendor for the laser cutting of blanks that we subsequently form in house. The code that follows opens the part file in question when a drawing is checked in and initiates the unfold command, waits for user selections, finishes the command, executes a save copy as to .Stp, and then open the resulting step file for user reveiw.
This was "written" for 2013 and worked well for monthes with one minor annoyance. It would always open the step file in a second instance of Inventor instead of opening the file in the running instance. This was Less than ideal, because the it take a little while to launch the second instance, but on the whole it was a major improvment over the way we were doing it. Fast forward six months or so and we install inventor 2014. Now the script fails to open the .stp file because the windows hasn't assoiciated step files to inventor 2014. Ok, so I reassociate .stp file with 2014 on the dept machines and voila, everything is back to normal. Except on one machine were the the .stp file open in the RUNNING instance of inventor (this is cool, it's really what I wanted to happen from the beginning). All the machines have similar hardware and are runnning Win 7 Pro. What I need to know is, what is causing the different file open behavior, and How can I get ALL The machines to behave this way!
I have attached the code in question and have pasted it below as well if you do not want to download the file. Their are file path elements that are "hard coded" into the script that will require modification to run in a different network environment that ours, and the rule is run by an I trigger set in a drawing file to "After Document Save". I am gratefull in anvance for any insight that the members of this community can offer and have faith that the "better minds than mine" here will help me sort this out.
Code:
**************************************************************************************************************
Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 66261 StartFragment: 314 EndFragment: 66229 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet
'Show message box and get user input - bolean yes/no question=MessageBox.Show("Would you like to Check the Drawing In?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)'set condition based on answer Ifquestion=vbYesThen'define and execute Vault Check in active document command synchronously (this method waits for user to complete command)DimoDefAsControlDefinitionoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("VaultCheckInTop")Callodef.execute2(True)'get the drawing filepathDimDfilepathAsStringDfilepath=ThisDoc.Path'MessageBox.Show(Dfilepath, "Debug")'Define the open documentDimopenDocAsDocumentopenDoc=ThisDoc.Document'Make sure there is model file referenced in the open documentDimdocFileAsDocumentIfThisDoc.ModelDocumentIsNotNothingThendocFile=ThisDoc.ModelDocumentElseMessageBox.Show("This drawing has no model reference", "iLogic")ReturnEndIf'format model file name DimFNamePosAsLongFNamePos=InStrRev(docFile.FullFileName, "\", -1)DimdocFNameAsStringdocFName=Right(docFile.FullFileName, Len(docFile.FullFileName)-FNamePos)'MessageBox.Show(docFName, "Debug")'get the current drawing rev level and assign it to RevDimRevAsStringRev="Rev"+iProperties.Value("Project", "Revision Number")'MessageBox.Show(Rev, "Debug")'strip C:\VaultWorkingFolder and insert V:\ the append Rev to create step file name and pathDimNFNameAsStringDimFNameLong=Len(Dfilepath)-22DimdocFNameLong=Len(docFName)-4docFName=Left(docFName,docFNameLong)NFName="V:\"+Right(Dfilepath,FNameLong)+"\"+docFName+""+Rev'MessageBox.Show(NFName, "Debug")'get model name and path and launch documentmodelFullFileName=ThisDrawing.ModelDocument.FullFileNamemodelDirectoryName=IO.Path.GetDirectoryName(modelFullFileName)modelFileName=IO.Path.GetFileName(modelFullFileName)'MessageBox.Show(modelFullFileName, "modelFullFileName")'MessageBox.Show(modelDirectoryName, "modelDirectoryName")'MessageBox.Show(modelFileName, "modelFileName")ThisDoc.Launch(modelFullFileName)'define active document (.ipt file)DimoPartDocAsPartDocumentoPartDoc=ThisApplication.ActiveDocument'define and execute "convert to sheet metal" commandoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("PartConvertToSheetMetalCmd")oDef.Execute'check to see if flat pattern existsDimoCompDefAsSheetMetalComponentDefinitionoCompDef=oPartDoc.ComponentDefinition'if flat pattern exists then....IfoCompDef.HasFlatPattern=FalseThen'check for preliminary rev status and alert user that step files are not exported for rev ? or *IfRev="Rev?"ThenMessageBox.Show(".stp Files Are Not Created For Prelimary Drawings", "iLogic")'define and execute close .iptoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.executeElseIfRev="Rev*"ThenMessageBox.Show(".stp Files Are Not Created For Drawings With Pending ECR's", "iLogic")'define and execute close .iptoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.executeElse' dispalay new .stp filepath and nameMessageBox.Show("File Name & Path "+NFName, "iLogic")' Get the STEP translator Add-In. and create STEP fileDimoSTEPTranslatorAsTranslatorAddInoSTEPTranslator=ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")DimoContextAsTranslationContextoContext=ThisApplication.TransientObjects.CreateTranslationContextDimoOptionsAsNameValueMapoOptions=ThisApplication.TransientObjects.CreateNameValueMapIfoSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions)Then' Set application protocol.' 2 = AP 203 - Configuration Controlled Design' 3 = AP 214 - Automotive DesignoOptions.Value("ApplicationProtocolType")=3' Other options...'oOptions.Value("Author") = ""'oOptions.Value("Authorization") = ""'oOptions.Value("Description") = ""'oOptions.Value("Organization") = ""oContext.Type=IOMechanismEnum.kFileBrowseIOMechanismDimoDataAsDataMediumoData=ThisApplication.TransientObjects.CreateDataMediumoData.FileName=NFName&".stp"oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)'define and execute close .ipt fileoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.execute'Open new STEP FileThisDoc.Launch(NFName&".stp")EndIfEndIfElse'check for preliminary rev status and alert user that step files are not exported for rev ? or *IfRev="Rev?"ThenMessageBox.Show(".stp Files Are Not Created For Prelimary Drawings", "iLogic")'define and execute close .iptoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.executeElseIfRev="Rev*"ThenMessageBox.Show(".stp Files Are Not Created For Drawings With Pending ECR's", "iLogic")'define and execute close .iptoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.executeElse'define and execute Unfold command synchronously (this method waits for user to complete command)oDef=ThisApplication.CommandManager.ControlDefinitions.​Item("SheetMetalUnfoldCmd")Callodef.execute2(True)'dispalay new .stp filepath and nameMessageBox.Show("File Name & Path "+NFName, "iLogic")' Get the STEP translator Add-In. and create STEP fileDimoSTEPTranslatorAsTranslatorAddInoSTEPTranslator=ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")DimoContextAsTranslationContextoContext=ThisApplication.TransientObjects.CreateTranslationContextDimoOptionsAsNameValueMapoOptions=ThisApplication.TransientObjects.CreateNameValueMapIfoSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions)Then' Set application protocol.' 2 = AP 203 - Configuration Controlled Design' 3 = AP 214 - Automotive DesignoOptions.Value("ApplicationProtocolType")=3' Other options...'oOptions.Value("Author") = ""'oOptions.Value("Authorization") = ""'oOptions.Value("Description") = ""'oOptions.Value("Organization") = ""oContext.Type=IOMechanismEnum.kFileBrowseIOMechanismDimoDataAsDataMediumoData=ThisApplication.TransientObjects.CreateDataMediumoData.FileName=NFName&".stp"oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)'defines and executes the Undo command to remove the unfold featureoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppUndoCmd")odef.execute'define and execute close .ipt fileoDef=ThisApplication.CommandManager.ControlDefinitions.​Item("AppFileCloseCmd")odef.execute'Open new STEP FileThisDoc.Launch(NFName&".stp")EndIfEndIfEndIfElseIfquestion=vbNoThenReturnEndIf
Solved! Go to Solution.