Vb.Net - Export Sketch To Dxf File

Vb.Net - Export Sketch To Dxf File

isocam
Collaborator Collaborator
343 Views
2 Replies
Message 1 of 3

Vb.Net - Export Sketch To Dxf File

isocam
Collaborator
Collaborator

Can anybody help?

 

Does anybody know how to export a part sketch to a dxf file?

 

I have the following VBA code, but it needs to be converted to work with a Vb.Net application.

 

Dim oExtrude As ExtrudeFeature

Set oExtrude = oDoc.ComponentDefinition.Features.Item(1)

Dim oBaseFace As Face

Set oBaseFace = oExtrude.EndFaces.Item(1)

Call oDoc.SelectSet.Select(oBaseFace)

Dim Cm As CommandManager

Set Cm = ThisApplication.CommandManager

Call Cm.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, Dxffilename)

ThisApplication.CommandManager.ControlDefinitions.Item("GeomToDXFCommand").Execute

 

Many thanks in advance!

 

Darren

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

Michael.Navara
Advisor
Advisor

I don't understand what do you try to do. Do you want to export source sketch of ExterudeFeature or the resulting face?

If you want to export the source sketch, the code can looks like this iLogic sample

Dim oExtrude As ExtrudeFeature = ThisDoc.Document.ComponentDefinition.Features.Item(1)
Dim sketch As PlanarSketch = oExtrude.Definition.Profile.Parent
Dim fileName As String = "C:\Temp\Sketch.dxf"
sketch.DataIO.WriteDataToFile("DXF", fileName)

 

Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @isocam.  That is obviously not the whole code, because there is no code shown for where the 'oDoc' variable gets defines or a value set to it, and no code showing where the 'Dxffilename' variable is defined or value set to it.  So, I am not sure if you want this to be a single routine, or a 2-part routine.  I like to keep my export routines separate from the rest of my code, so I have a 2-part example below where the 'Main' section, where the face is obtained, and a file name is defined, is customized to your code above.

 

I usually use a different route for this type of thing though, to avoid having to use selection and executing a command.  My process starts a Transaction, creates a new sketch on the face, where all face profiles are projected to the sketch plane, then turned to regular geometry (instead of construction), then export the sketch, similar to what Michael suggested, then abort the transaction to get rid of the sketch.  This is likely what that command does behind the scenes anyways.

 

 

Sub Main
	Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
	If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
	Dim oExtFeats As ExtrudeFeatures = oDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtFeats.Count = 0 Then Return
	Dim oExtrude As ExtrudeFeature = oExtFeats.Item(1)
	Dim oBaseFace As Face = oExtrude.EndFaces.Item(1)
	Dim sDXF_FullFileName As String = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".dxf")
	ExportFaceToDXF(oBaseFace, sDXF_FullFileName)
End Sub

Sub ExportFaceToDXF(oFace As Face, sDXF_FullFileName As String)
	If oFace Is Nothing Or String.IsNullOrEmpty(sDXF_FullFileName) Then Return
	Dim oDoc As Inventor.Document = oFace.Parent.ComponentDefinition.Document
	oDoc.SelectSet.Clear
	oDoc.SelectSet.Select(oFace)
	Dim oCmdMgr As CommandManager = ThisApplication.CommandManager
	oCmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, sDXF_FullFileName)
	oCmdMgr.ControlDefinitions.Item("GeomToDXFCommand").Execute
End Sub

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes