Export a flat surface to DXF without using command manager

Export a flat surface to DXF without using command manager

MJBusseyMS
Participant Participant
630 Views
7 Replies
Message 1 of 8

Export a flat surface to DXF without using command manager

MJBusseyMS
Participant
Participant

Is there a way through the Inventor API to export a specified surface in a part or assembly context without using the command manager? 

0 Likes
631 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

Maybe this will help..

 

Public Sub WriteSheetMetalDXF()
    ' Get the active document.  This assumes it is a part document.
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' Get the DataIO object.
    Dim oDataIO As DataIO
    Set oDataIO = oDoc.ComponentDefinition.DataIO

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"

    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, "C:\temp\flat2.dxf"
End Sub

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

0 Likes
Message 3 of 8

WCrihfield
Mentor
Mentor

Hi @MJBusseyMS .

@DRoam actually already created a post in Inventor Ideas for this issue, which stemmed from their earlier post here on this forum.

Ideas Post is here. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

Or this:

Public Sub PublishDXF()
    ' Get the DXF translator Add-In.
    Dim DXFAddIn As TranslatorAddIn
    Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\tempDXFOut.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\tempdxfout.dxf"

    'Publish document.
    Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

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

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor

@bradeneuropeArthur, where does the information and formatting for that line of code come from.

sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"

I've seen similar lines several times before, but am unfamiliar with its logic and specific purpose/use.

Is there a way of extracting that information from the similar manual process, or from another coded process?

Is it from another code language like XML, HTML, C# or similar?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @MJBusseyMS 

 

Here's an example ilogic rule, it might need some error checking to ensure that the face is a planer face so that the sketch can be made,  (never mind that, I forgot the pick filter was filtering for planer surfaces only ) or other things, but this should get you pointed in the right direction.

 

Out of curiosity, why does using the command manager not work for your needs?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oCompDef As PartComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oPrompt1 As String 
oPrompt1 = "Select a face to export..."

Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick _
	(SelectionFilterEnum.kAllPlanarEntities, oPrompt1)
	
If oFace Is Nothing Then 
	Return 'exit rule
End If	
	
' Create a new sketch.  
'True specifies To include the edges of the face in the sketch.
Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Add(oFace, True)

' Get the DataIO object.
Dim oDataIO As DataIO
oDataIO = oSketch.DataIO

''Check for the DXF folder and create it if it does not exist
oFolder = "C:\temp\DXF\"
If Not System.IO.Directory.Exists(oFolder) Then
	System.IO.Directory.CreateDirectory(oFolder)
End If

' Create the DXF file.
oDataIO.WriteDataToFile ("DXF",oFolder & "My_DXF.dxf")

oSketch.Delete

Process.Start(oFolder)

 

EESignature

Message 7 of 8

MJBusseyMS
Participant
Participant

Forge Design Automation uses Inventor Server for doing Inventor automation "at scale".  Inventor Server does not have any of the Inventor UI, and does not support command manager (it's not part of the Inventor Server API at all).  Therefore I need a way to export a surface without using it.

0 Likes
Message 8 of 8

lmc.engineering
Advocate
Advocate

I don't know much about Forge, but can you make use  of named Geomerty? Something like this mixed in with Curtis's code sample:

 

Sub main()
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
	Dim oFace As Face
	oFace = ReturnFaceFromNamedGeo(oDoc, "Face0")
	
	If oFace Is Nothing Then 
		Return 'exit rule
	End If	
	
	' Create a new sketch.  
	'True specifies To include the edges of the face in the sketch.
	Dim oSketch As PlanarSketch
	oSketch = oDef.Sketches.Add(oFace, True)

	' Get the DataIO object.
	Dim oDataIO As DataIO
	oDataIO = oSketch.DataIO

	''Check for the DXF folder and create it if it does not exist
	oFolder = "C:\temp\DXF\"
	If Not System.IO.Directory.Exists(oFolder) Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If

	' Create the DXF file.
	oDataIO.WriteDataToFile ("DXF",oFolder & "My_DXF.dxf")

	oSketch.Delete

	Process.Start(oFolder)
End Sub

Function ReturnFaceFromNamedGeo(oPart As PartDocument,EntityName As String, Optional SolidBodyNo As Integer = 1) As Face
    Dim oDef As PartComponentDefinition = oPart.ComponentDefinition
    Dim oFaces As Faces = oDef.SurfaceBodies(SolidBodyNo).Faces
    Dim AttSet As AttributeSet
    Dim AttSets As AttributeSets
    For Each oFace In oFaces
        AttSets = oFace.AttributeSets
        If AttSets.NameIsUsed("iLogicEntityNameSet") Then
            AttSet = AttSets.Item("iLogicEntityNameSet")
            For Each Att In AttSet
                If Att.Value() = EntityName Then
		      Return oFace
                End If
            Next
        End If
    Next
    Return Nothing
End Function
0 Likes