Calling Inventor Save dialogue using iLogic

Calling Inventor Save dialogue using iLogic

Anonymous
Not applicable
1,904 Views
5 Replies
Message 1 of 6

Calling Inventor Save dialogue using iLogic

Anonymous
Not applicable

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

 

0 Likes
Accepted solutions (1)
1,905 Views
5 Replies
Replies (5)
Message 2 of 6

clutsa
Collaborator
Collaborator
Accepted solution
oFileDlg is the problem


' 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'<-----------------------here is 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"'<-----------------here you set "nothings" filter
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)'<--------------move this line up ;)


'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

 


 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 3 of 6

bradeneuropeArthur
Mentor
Mentor
You should use the metadata object to predefine your filename.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 6

Anonymous
Not applicable

Thanks Clutsa and Bradeneurope. All sorted! Your help is much appreciated.

Regards

Richard

0 Likes
Message 5 of 6

MechMachineMan
Advisor
Advisor

Hi @Anonymous.

 

Your original rule being all in one procedure makes it very difficult to follow, and makes following the logic quite a bit more difficult than it needs to be, as well as makes lines that perform the same appear multiple times.

 

Below is an example of what the code could look like when properly utilizing procedures to split things up into more manageable and reusable chunks. It's probably in your best interest to at least take a gander and see what you can learn from it as it will make coming back to your code much easier in the future.

 

Cheers!

 

' THIS RULE WILL OUTPUT THE CURRENT PART FILE INTO AN IDW DRAWING
Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum



Sub Main()
	'Exit Sub
	Dim oPartDoc As PartDocument
	oPartDoc = ThisDoc.Document
	
	DWGCreate = MsgBox("Are you ready to export file?", vbYesNo, "Export Drawing")
	If DWGCreate = vbNo Then
		MsgBox("Cancelling Rule...")
		Exit Sub
	End If
	
'File Saving
'[
	If oPartDoc.FullFileName = "" Then
		oFileName = CreateFileDlg("", "*.ipt", ThisDoc.WorkspacePath(), True)
		If oFileName <> "" Then
			oPartDoc.SaveAs(oFileName, False)
		Else
			MsgBox("No part file name found. Aborting rule!")
			Exit Sub
		End If
	End If
	
	Dim oDrawingDoc As DrawingDocument
	oTemplateFile = "O:\KS FAB\ILOGIC RULES\KS INVENTOR TEMPLATES\Standard Section Templates\DRAWING KS STANDARD SECTION.idw"
	If System.IO.File.Exists(oTemplateFile) = False Then
		MsgBox("Template File Not Found!" & vbLf & vbLf & "Please select one now!")
		oTemplateFile = CreateFileDlg(ThisDoc.FileName(False) & ".idw", "*.idw", ThisDoc.WorkspacePath(), False)
		If oTemplateFile = "" Then
			MsgBox("No good template selected. Aborting Rule!")
			Exit Sub
		End If
	End If
	oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, oTemplateFile , True)
	
	If oDrawingDoc.Sheets.Count < 2 Then
		MsgBox("Drawing Template with 2+ sheets expected. Aborting rule!")
		Exit Sub
	End If
		
	oDwgFilename = CreateFileDlg(ThisDoc.FileName(False) & ".idw", "*.idw", ThisDoc.WorkspacePath(), True)
	
	If oDwgFileName <> "" Then
		oDrawingDoc.SaveAs(oDwgFileName, False)
	Else
		MsgBox("Save name for DWG not selected. Aborting rule!")
		Exit Sub
	End If
']	
	oDrawingDoc.Activate()

'ViewScale Setup
'[
	extents_length = SheetMetal.FlatExtentsLength
	'extents_width = SheetMetal.FlatExtentsWidth
	
	Dim DrawingViewScale As Double
	Dim IsoViewScale As Double
	
	If SheetMetal.FlatExtentsLength < 250 mm Then
		DrawingViewScale = 1/4
		IsoViewScale = 1/2
	Else If SheetMetal.FlatExtentsLength >= 250 mm And SheetMetal.FlatExtentsLength < 750 mm Then
		DrawingViewScale = 1/5
		IsoViewScale = 1/4
	Else If SheetMetal.FlatExtentsLength >= 750 mm And SheetMetal.FlatExtentsLength < 1250 mm Then
		DrawingViewScale = 1/10
		IsoViewScale = 1/8
	Else If SheetMetal.FlatExtentsLength >= 1250 mm And SheetMetal.FlatExtentsLength < 5000 mm Then
		DrawingViewScale = 1/20
		IsoViewScale = 1/10
	End If
']	
	Call PopulateSheet1(oDrawingDoc.Sheets.Item(1), oPartDoc, DrawingViewScale, IsoViewScale)
	
	Call PopulateSheet2(oDrawingDoc.Sheets.Item(2), oPartDoc, DrawingViewScale)
	
	NoCut = InputBox("How many parts would you like to cut?", "Part Qty", "2")
	PartQty = NoCut
	
End Sub

Sub PopulateSheet1(oSheet As Sheet, oPartDoc As Document, DrawingViewScale As Double, IsoViewScale As Double)
			
	Dim oPoint1 As Point2d
	Dim oBaseView As DrawingView
	oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(9,6)
	oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, DrawingViewScale, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle)
	MessageBox.Show("1 view created", "View")

	Dim oPoint2 As Point2d
	Dim oTopView As DrawingView
	oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(9,15)
	oTopView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint2, DrawingViewScale, kTopViewOrientation, kHiddenLineRemovedDrawingViewStyle)
	MessageBox.Show("2 view created", "View")
	
	Dim oPoint5 As Point2d
	Dim oIsoView As DrawingView
	oPoint5 =  ThisApplication.TransientGeometry.CreatePoint2d(23, 15)
	oIsoView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint5, IsoViewScale, kIsoTopLeftViewOrientation, kShadedDrawingViewStyle)
	MessageBox.Show("3 view created", "View")
End Sub

Sub PopulateSheet2(oSheet, oPartDoc, DrawingViewScale)
	Dim oBaseViewOptions As NameValueMap
	oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oBaseViewOptions.Add("SheetMetalFoldedModel", False) 
	
	Dim oPoint20 As Point2d
	Dim oFlatView As DrawingView
	oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(9,15)
	oFlatView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint2, DrawingViewScale, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle,,, oBaseViewOptions)
End Sub

Function CreateFileDlg(oDefaultFileName As String, oFilterStr As String, oInitialDirectory As String, boolSaveDlg As Boolean)
	Dim oFileDlg As Inventor.FileDialog
	ThisApplication.CreateFileDialog(oFileDlg)
	
	oFileDlg.Filter = "Autodesk Inventor Part Files (" & oFilterStr & ")|" & oFilterStr
	oFileDlg.InitialDirectory = oInitialDirectory
	oFileDlg.FileName = oDefaultFileName
	oFileDlg.CancelError = True
  On Error Resume Next
  	If boolSaveDlg = True
		oFileDlg.ShowSave()
	Else
		oFileDlg.ShowOpen()
	End If
	
	If Err.Number <> 0 Then
		MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
	ElseIf oFileDlg.FileName <> "" Then
		Return oFileDlg.FileName
	End If
  On Error Goto 0
End Function

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 6

Anonymous
Not applicable

Thanks Justin,

Much better structure. Much easier to debug. 

I've just started doing this API stuff again afetr a long time off. 

Your help is much appreciated.

Regards

Richard

0 Likes