Export to dxf without tangent and bending line

Export to dxf without tangent and bending line

kresh.bell
Collaborator Collaborator
2,202 Views
7 Replies
Message 1 of 8

Export to dxf without tangent and bending line

kresh.bell
Collaborator
Collaborator

Hi,

this is a great iLogic for me to export to dxf. Is it possible to edit it in such a way that dxf geometry has no tangent line and bending line?

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument

oAsmDoc = ThisApplication.ActiveDocument

oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)



'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then

	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	
	Exit Sub
	
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic  - Batch Output DXFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then

	Return
	
	Else
	
End If

oPath = ThisDoc.Path

oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

oContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'get DXF target folder path
oFolder = oPath & "\" & oAsmName & " DXF Files"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then

    System.IO.Directory.CreateDirectory(oFolder)
	
End If
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator

oRefDocs = oAsmDoc.AllReferencedDocuments

Dim oRefDoc As Document


'work the the drawing files for the referenced models
'this expects that the model has been saved
		For Each oRefDoc In oRefDocs
			
			iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"

    		'check that model is saved
			If(System.IO.File.Exists(iptPathName)) Then
			
                Dim oDrawDoc As PartDocument
				
                oDrawDoc = ThisApplication.Documents.Open(iptPathName, True)
				
            	oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
				
				Try
				
                	'Set the DXF target file name
                	oDataMedium.FileName = oFolder & "\" & oFileName & ".dxf"
				
					Dim oCompDef As SheetMetalComponentDefinition
				
					oCompDef = oDrawDoc.ComponentDefinition
					
					If oCompDef.HasFlatPattern = False Then
					
						oCompDef.Unfold
						
					Else
					
   						oCompDef.FlatPattern.Edit
						
					End If

					Dim sOut As String
				
					sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"

					
					oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
				
					'just for check its works coretcly
					'i=MessageBox.Show(oDataMedium.FileName, "Title",MessageBoxButtons.OKCancel)
					
					'MessageBox.Show(i,"title",MessageBoxButtons.OK)
				
					'If i=2 Then
				
						'Exit Sub
				
					'End If

					oCompDef.FlatPattern.ExitEdit
				
				Catch
				
				End Try
                
				oDrawDoc.Close
				
			Else
					
			End If
			
		Next

thanks

Kresh

0 Likes
Accepted solutions (2)
2,203 Views
7 Replies
Replies (7)
Message 2 of 8

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hello, try this ilogic code from assembly.
This file will look for parts that are made of metal sheet in your assembly.
Create a temporary drawing file without TitleBlock and place a view of the displayed sheet in 1: 1 scale
You will see the tangent lines of fold, then save as dwg and finally close the temporary file.

 

Dim openDoc As AssemblyDocument = ThisDoc.Document
InventorVb.DocumentUpdate()

For Each oDoc As Document In openDoc.AllReferencedDocuments
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		Dim oPath As String = oDoc.FullFileName
		Dim oFileName As String = Left(oPath, (InStrRev(oPath, ".", -1, vbTextCompare) - 1))
		Dim oDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
		If oDef.HasFlatPattern = False Then 
			oDef.Unfold
			oDef.FlatPattern.ExitEdit
			oDoc.Close
		End If
		
		Dim oBaseViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap ' Create a new NameValueMap object
		oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'True = folded view False = flat pattern view

		Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,Nothing,True)'False
		Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)' view insert point
		Dim oView As DrawingView = oDrawDoc.Sheets.Item(1).DrawingViews.AddBaseView(oDoc, oPoint1, 1, _
		ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle,,, oBaseViewOptions)
		oView.DisplayBendExtents = True
		oDrawDoc.SaveAs(oFileName & ".dwg", True)
		oDrawDoc.Close(True)
	End If
Next

 I hope this is useful for your task. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 8

kresh.bell
Collaborator
Collaborator

Again there is a bend line and tangent line, and save as dwg, not dxf. My nesting software automatically imports dxf files and confuses it with band line and tangnet line

0 Likes
Message 4 of 8

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

 

Dim openDoc As AssemblyDocument = ThisDoc.Document
InventorVb.DocumentUpdate()

For Each oDoc As Document In openDoc.AllReferencedDocuments
	 On Error Resume Next
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		ThisApplication.Documents.Open(oDoc.FullFileName, True)

		Dim oFilename As String = Left(oDoc.FullFileName, (InStrRev(oDoc.FullFileName, ".", -1, vbTextCompare) - 1))  &  ".dxf"

		Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

		If oCompDef.HasFlatPattern = False Then 
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If

		Dim oFlatPattern As FlatPattern = oCompDef.FlatPattern
		Dim oFace As Face = oFlatPattern.TopFace

		Dim oCommand As CommandManager = ThisApplication.CommandManager

		oCommand.DoSelect(oFace)
		oCommand.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oFilename) 
		oCommand.ControlDefinitions.Item("GeomToDXFCommand").Execute2(True)

		oCompDef.FlatPattern.ExitEdit
		oDoc.Close
	End If
Next

 I'm sorry, I've understood you the other way around.
Try this code from an assembly.
It will take all the reference components that are of sheet metal and will export its flatpattern to dxf, without folding lines and without tangent lines.
I hope it is useful for you. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 8

kresh.bell
Collaborator
Collaborator

really great, tnx

0 Likes
Message 6 of 8

Rusty.Kight
Participant
Participant

First of all, thank you for this code!  It works really well.  Here's my problem:

 

The parts in my assembly have very generic filenames.  Each part has a parameter named "Job" where the top level pushes a job number to.  Each part also has a suffix parameter.  From there (using iLogic in each part), I build a part number iprop specific to the job going through our high volume, custom fabrication shop. 

 

I would like to name the dxf's files specific to either the part parameters i've mentioned, or possibly the part number iprop, if possible.  I've had trouble "getting at" these parameters or iprops from this code in the top assembly level.  Any ideas on how to do that?  Thanks again!

0 Likes
Message 7 of 8

nicolamora
Contributor
Contributor

Wow, you code is great!! Well done. 

Is it possible to change the location of the DXF files in c:\temp

0 Likes
Message 8 of 8

radcamftp
Community Visitor
Community Visitor

Hi, Thank you this code works. but I need slight modifications to this. how to save these drawings in a folder where the assembly file is located?

0 Likes