
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have saved this rule to my part template which will turn the sheetmetal part into a set of drawings.
The problem I am having is that because the parts are all new parts when created from a template they have a Null string as their name. I am trying to get the user to save the file before generating the drawing, which will then be saved with the same name. I am using dialogues rather than the save method because our users sometimes have to navigate to different directories.
If I run my rule with a pre-saved part (ie. the part already has a name ) it is fine. But if it has not been saved I get the following error:-
System.NullReferenceException: Object reference not set to an instance of an object.
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
I have obviously missed an object reference but can't find where. Hope you guys can help.
Regards
Richard
' THIS RULE WILL OUTPUT THE CURRENT PART FILE INTO AN IDW DRAWING Imports Inventor.ViewOrientationTypeEnum Imports Inventor.DrawingViewStyleEnum Dim oDrawingDoc As DrawingDocument Dim oPartDoc As PartDocument Dim oSheet As sheet Dim oBaseView As DrawingView 'DWGCreate = MsgBox("Would you like to create a drawing for the current configuration?", vbYesNo, "Export Drawing") 'If DWGCreate = vbYes Then oPartDoc = ThisDoc.Document 'This statement requires that this rule will only run in part documents 'Error trap for file name DWGCreate = MsgBox("Are you ready to export file?", vbYesNo, "Export Drawing") 'iLogicForm.Show("Drawing Export", FormMode.Modal) 'jobnumber = iProperties.Value("Project", "Project") Dim oFile As System.IO.File Dim oWrite As System.IO.StreamWriter Dim oFileDlg As inventor.FileDialog = Nothing dwg_filename = ThisDoc.FileName(False) 'First time used to see if filename is "" MessageBox.Show("length File Name is :- " & Len(dwg_filename) , "iLogic: ErrTrap 1") If Len(dwg_filename) = 0 Then 'Need to load the save dialogue with save as switch set oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt" MessageBox.Show("File Name is :- " & dwg_filename , "iLogic: ErrTrap 2") oFileDlg.CancelError = True On Error Resume Next oFileDlg.ShowSave() If Err.Number <> 0 Then MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled") ElseIf oFileDlg.FileName <> "" Then MyFile = oFileDlg.FileName 'save the file oDrawingDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As End If End If dwg_filename = ThisDoc.FileName(False) & ".idw" 'Redefined with extension for dialogue filter. 'ThisDoc.Launch(dwg_filename) MessageBox.Show("File Name is :- " & dwg_filename , "iLogic: ErrTrap 1") 'Define IDW Template File Location oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "O:\KS FAB\ILOGIC RULES\KS INVENTOR TEMPLATES\Standard Section Templates\DRAWING KS STANDARD SECTION.idw", True) 'oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True) ' oSheet = oDrawingDoc.Sheets.Item(1) 'oDrawingDoc = ThisApplication.documents.Add(DocumentTypeEnum.kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject)) MessageBox.Show("Template Found" , "iLogic: ErrTrap 2") 'create a file dialog box 'Dim oFileDlg As inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) 'check file type and set dialog filter 'If oDrawingDoc.DocumentType = kPartDocumentObject Then 'oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt" 'Else If oDrawingDoc.DocumentType = kAssemblyDocumentObject Then 'oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam" If oDrawingDoc.DocumentType = kDrawingDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw" 'End If 'set the directory to open the dialog at oFileDlg.InitialDirectory = ThisDoc.WorkspacePath() 'set the file name string to use in the input box oFileDlg.FileName = dwg_filename 'work with an error created by the user backing out of the save oFileDlg.CancelError = True On Error Resume Next 'specify the file dialog as a save dialog (rather than a open dialog) oFileDlg.ShowSave() 'catch an empty string in the imput If Err.Number <> 0 Then MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled") ElseIf oFileDlg.FileName <> "" Then MyFile = oFileDlg.FileName 'save the file oDrawingDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As End If oDrawingDoc.Activate() oSheet = oDrawingDoc.Sheets.Item(1) extents_length = SheetMetal.FlatExtentsLength extents_width = SheetMetal.FlatExtentsWidth ' 'If SheetMetal.FlatExtentsLength < SheetMetal.FlatExtentsWidth Then 'extents_length = SheetMetal.FlatExtentsWidth 'extents_width = SheetMetal.FlatExtentsLength 'Else If SheetMetal.FlatExtentsLength > SheetMetal.FlatExtentsWidth Then 'extents_length = SheetMetal.FlatExtentsLength 'extents_width = SheetMetal.FlatExtentsWidth 'End If 'Set the View Scales Dim DrawingViewScale As Double If SheetMetal.FlatExtentsLength < 250 mm Then DrawingViewScale = 1/4 Else If SheetMetal.FlatExtentsLength >= 250 mm And SheetMetal.FlatExtentsLength < 750 mm Then DrawingViewScale = 1/5 Else If SheetMetal.FlatExtentsLength >= 750 mm And SheetMetal.FlatExtentsLength < 1250 mm Then DrawingViewScale = 1/10 Else If SheetMetal.FlatExtentsLength >= 1250 mm And SheetMetal.FlatExtentsLength < 5000 mm Then DrawingViewScale = 1/20 End If Dim IsoViewScale As Double If SheetMetal.FlatExtentsLength < 250 mm Then IsoViewScale = 1/2 Else If SheetMetal.FlatExtentsLength >= 250 mm And SheetMetal.FlatExtentsLength < 750 mm Then IsoViewScale = 1/4 Else If SheetMetal.FlatExtentsLength >= 750 mm And SheetMetal.FlatExtentsLength < 1250 mm Then IsoViewScale = 1/8 Else If SheetMetal.FlatExtentsLength >= 1250 mm And SheetMetal.FlatExtentsLength < 5000 mm Then IsoViewScale = 1/10 End If ' Create a new NameValueMap object Dim oBaseViewOptions As NameValueMap oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap 'True = folded view 'False = flat pattern view oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'DrawingViewScale = 1/5 'IsoViewScale = 1/5 oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(9,6) oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle) MessageBox.Show("1 view created", "View") oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(9,15) oTopView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint2, DrawingViewScale, kTopViewOrientation, kHiddenLineRemovedDrawingViewStyle) MessageBox.Show("2 view created", "View") ' 'Dim oLeftView As DrawingView 'oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(5,5) 'oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) ' 'Dim oRightView As DrawingView 'oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(30,5) 'oTopView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) Dim oIsoView As DrawingView oPoint5 = ThisApplication.TransientGeometry.CreatePoint2d(23, 15) oIsoView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint5, IsoViewScale, kIsoTopLeftViewOrientation, kShadedDrawingViewStyle) 'oIsoView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint5, DrawingViewStyleEnum.kShadedDrawingViewStyle) MessageBox.Show("3 view created", "View") 'Need to change sheet to "DXF" ''oSheet = ThisDrawing.Sheet("DXF:2") oSheet = oDrawingDoc.Sheets.Item(2) oPoint20 = ThisApplication.TransientGeometry.CreatePoint2d(9,15) oFlatView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint2, DrawingViewScale, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle,,, oBaseViewOptions) Dim addIns As ApplicationAddIns addIns = ThisApplication.ApplicationAddIns Dim addIn As ApplicationAddIn addIn = ThisApplication. _ ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") Dim iLogic As Object iLogic = addIn.Automation NoCut = InputBox("How many parts would you like to cut?", "Part Qty", "2") PartQty = NoCut 'Call iLogic.RunRule(oDrawingDoc, "Layout_Views") End If
Solved! Go to Solution.