- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need a little help refining part of my code, I don't have a good handle on getting items from propertysets, and the translation stuff I've just grabbed from other snippets I've found. I've shown my process and the sub for creating dxfs below:
1) Start with a multisheet .idw with multiple views of multiple parts.
2) Some of these parts are sheet metal, but some are not. All views should already be placed in the correct orientation, flat pattern, and/or model state.
3) Some of the views are of the same .ipt but in different model states with correspondingly different part numbers.
4) I want the code to export only the geometry of each view as a dxf to use as a laser cutting file.
5) The dxf should be named the part number from iproperties, which isn't necessarily the file name (see parts with model states)
The issues I am having:
1) This changes all views of an .ipt with multiple model states to the same model state (and part number) in all views, on all sheets.
2) For each view, it exports a dxf for each sheet ie if parts A and B are only on sheet 1, and parts C and D are only on sheet 2, I will still get the following dxfs:
A_Sheet_1
A_Sheet_2
B_Sheet_1
B_Sheet_2
C_Sheet_1
C_Sheet_2
D_Sheet_1
D_Sheet_2
3)DXFs export incorrectly: each is of the entire sheet with drawing borders and text, not just the view geometry and file name includes the sheet reference.
Sub Save_DXF Dim oDoc As DrawingDocument = ThisDrawing.Document Dim dlgFolder = New FolderBrowserDialog dlgFolder.SelectedPath = ThisDoc.Path 'Set Root Path from where to start from dlgFolder.ShowDialog Dim oPath As String = dlgFolder.SelectedPath Dim DXFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap 'The below line might give issues depending on inventor version. Check forums if you are encountering issues. If DXFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then Dim strIniFile As String strIniFile = "C:\CAD_2007.ini" oOptions.Value("Export_Acad_IniFile") = strIniFile End If Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium Dim oSheet As Sheet Dim oView As DrawingView Dim filename As String Dim partnumber As String For Each oSheet In oDoc.Sheets oSheet.Activate For Each oView In oSheet.DrawingViews refDoc = ThisDrawing.ActiveSheet.View(oView.Name).ModelDocument partnumber = refDoc.PropertySets.Item(3).Item("Part Number").Value MessageBox.Show(partnumber, "Title") oDataMedium.FileName = oPath & "\" & partnumber & ".dxf" MsgBox(oDataMedium.FileName) DXFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium) Next Next End Sub
Solved! Go to Solution.