Create dxfs from each view in a drawing

Create dxfs from each view in a drawing

RNate
Participant Participant
359 Views
2 Replies
Message 1 of 3

Create dxfs from each view in a drawing

RNate
Participant
Participant

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

 

0 Likes
Accepted solutions (1)
360 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Hi @RNate 

 

The approach you might need to look at is to detect the model document as sheetmetal document then open the part document, produce flatpattern and dxf the flat pattern. This uses the dxf translator within the document and this will be setup differently than the dxf translator in the drawing. You can probably find a post with this workflow on this forum. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @RNate.   I do not believe that we have the ability to export individual drawing views as independent DXF files.  Even the DrawingView.DataIO.WriteDataToFile method can only be used from Apprentice, and then it can only get a BitMap, and only if one is available.  Seems like I have seen folks try to scale their flat pattern view to actual size (1:1) on a sheet by itself before exporting the drawing document to DXF.  We can only export the whole drawing document as a DXF though.  The Sheet.DataIO.WriteDataToFile method can only output a DWF type file.

As @A.Acheson mentioned, exporting a flat pattern DXF for CNC related work is generally best done directly from a sheet metal type model document.  If going the drawing route, you could use a sheet with no border, and no title block, and a custom sheet size if necessary, but I believe each sheet of the drawing will usually generate another DXF file though, and scaling is very important.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes