- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I have some code from others contributions that has helped me to create a dxf from parts in assemblies and to export parameters, however after much trying I have to concede I don't have any real programming skills to bring all the code together I need.
This will greatly help my clients fabrication department in generating dxf's , managing dxfs and in nesting dxfs.
I need code to take part HM12345.ipt and generate HM12345_(Revision)_(Thickness), from an open assembly.
Revision comes from the property 'Revision'
Thickness comes from the parameter 'Thickness' in sheet metal parts
I also need to set every checked out part in the assembly to export the parameter 'Thickness' prior to running the main routine.
My final dxf filename would look like this. HM12345_00_3.0mm.dxf
Also in the routine attached I think the code is getting the revision number of the assembly not of each part.
I need the revision number of each part to appear in the file name of each part.
So the workflow would be
1. Set all parts parameter 'Thickness' set to export in open assembly
2. Create Sub folder with same number as Assembly and the text DXF, ie HM12345_DXF
3. Generate DXF's with concatenated part number as above in that folder
If someone could help it would be greatly appreciated
Thanks Peter
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous ,
Hoping that below iLogic may be helpful to accomplish your task.
'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"
'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
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
'check that model is saved
If(System.IO.File.Exists(iptPathName)) Then
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Open(iptPathName, True)
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))
Try
oRevName =iProperties.Value(oFileName, "Project", "Revision Number")
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oThick As Double
oThick = oCompDef.Parameters.UserParameters.Item("Thickness").ModelValue
oDataMedium.FileName = oFolder & "\" & oFileName & "_"&oRevName & "_" & oThick.ToString() & "mm" & ".dxf"
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
oPartDoc.Close
End If
End If
Next
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I get the following error when I run this routine. Any help would be greatly appreciated.
Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I get the following error when I run this routine, any help would be greatly appreciated. Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous ,
Please provide sample assembly with part files to test the behavior and make sure that files are non confidential.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Try this one. We can also add counting the parts per assembly and write the Quantity to name file.
Sub Main Dim oDoc As Document = ThisApplication.ActiveDocument If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Export(oDoc) Exit Sub End If Cycle(oDoc) End Sub Sub Cycle(oDoc As AssemblyDocument) For Each aDoc As Document In oDoc.ReferencedDocuments If aDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Export(aDoc) ElseIf aDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Cycle(aDoc) End If Next End Sub Sub Export(oDoc As PartDocument) Dim FName As String = GetFName(oDoc.FullFileName) Dim sPN As String = iProperties.Value(FName, "Project", "Part Number") Dim Rev As String = iProperties.Value(FName, "Project", "Revision Number") Dim oCD As SheetMetalComponentDefinition = oDoc.ComponentDefinition If Not oCD.HasFlatPattern Then oCD.Unfold() oCD.FlatPattern.ExitEdit() End If If Rev = Nothing Then Rev = "00" Dim dThick As Double Try dThick = Math.Round(oCD.Parameters("Tloušťka").Value * 10, 1) Catch Exit Sub End Try If dThick < 0.05 Then Exit Sub Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2013&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_ARC_CENTERS" FName = oDoc.FullFileName Dim FNP As Integer = InStrRev(FName, "\", -1) Dim sPath As String = Left(FName, FNP) FNP = InStr(sPath, "\") sPath = "C:\DXF" & Mid(sPath, FNP) If Not System.IO.Directory.Exists(sPath) Then System.IO.Directory.CreateDirectory(sPath) Dim sNewName As String = sPath & sPN & "_" & Rev & "_" & CStr(dThick) & "mm" & ".dxf" oCD.DataIO.WriteDataToFile(sOut, sNewName) End Sub Function GetFName(FullName As String) As String Dim FNP As Integer = InStrRev(FullName, "\", - 1) Dim FName As String = Mid(FullName, FNP + 1, Len(FullName) - FNP) Return FName End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Here is the test assembly.
It should create two DXFs,.
My other o routines run with this assy
The routine runs, but it does not seem to create the dxf's and it does not set the thickness parameter to 'export'
Thank you very much for your help
Kind Regards
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous ,
For some reason, assembly attachement is missing in previous post.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I added as a zip file on the attachments tab
Hope it come thru this time
Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I added as a zip file on the attachments tab
Hope it come thru this time
Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I added as a zip file on the attachments tab
Hope it come thru this time
Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Thanks for that.
I ran the routine, there is no visual indication that the routine has run. I checked DXF creating under the Vault workspace and there is no created DXFs.
I ran my old routine and it ran ok.
I checked the parts after running the routine the parameter 'thickness' had not been set to export.
So it is not working for me at the moment.
Thanks Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Just change this row
dThick = Math.Round(oCD.Parameters("Thickness").Value * 10, 1)
In this row is path to dxf file. Change it as needed
sPath = "C:\DXF" & Mid(sPath, FNP)
And what you mean by "set thickness to export"??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Great, this works well.
Thanks for your help, this is a great start for us.
Greatly appreciated.
Kind Regards Peter