iProperty Notes with a dxf. file.

iProperty Notes with a dxf. file.

Anonymous
Not applicable
648 Views
2 Replies
Message 1 of 3

iProperty Notes with a dxf. file.

Anonymous
Not applicable

Hi All,

I have used some code that I have seen a few different versions of on this forum to write out all the sheetmetal parts in an assembly to a .DXF file for use in production but I also need some iProperties to be written to the .DXF as well. I want the output DXF to look something like the attached screenshot where the first 2 notes (MAT= ALUMINIUM, GGE= 0.6) are from the active sheetmetal style and QTY is the part count of this component in the BOM. NOTES is the Part Number iProperty.

I can't find a way to write these properties to the dxf using this method. Anybody out there in forum land got any ideas?

Thanks for your help.

Cheers

Richard

'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

Try
CustomName =iProperties.Value(oFileName, "Custom", "PF_PRT_ZNR")
Catch
CustomName ="XXX" 'Wert, wenn iPropertie PF_PRT_ZNR nicht existiert
End Try

oDataMedium.FileName = oFolder & "\" & CustomName  & " " & 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_PR​OFILE"
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

 

0 Likes
649 Views
2 Replies
Replies (2)
Message 2 of 3

MechMachineMan
Advisor
Advisor

Are you making sure you are modifying the DXF lines properly, as per this document:

 

http://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf

 

Also, this thread has some similar discussion on it:

 

https://forums.autodesk.com/t5/inventor-customization/export-idw-to-dxf/td-p/7539297/page/2


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 3

Anonymous
Not applicable

    Dim realTextToAdd = TextToAdd + vbNewLine + " 0" + vbNewLine
    Dim textLen As Integer = realTextToAdd.Length()
    ‘ GET FILENAME AND PATH
    FileName = ThisDoc.FileName(False)
    oPath = ThisDoc.Path
    ‘ GET REV No. from iPROPERTIES
	oRevNum = iProperties.Value("Project", "Revision Number")
    If oRevNum = "0" Or oRevNum = "" Then oRevNum = "1"
‘ SET DXF FILE NAME TO FILENAME + REV
    sFname = oPath & "\" & FileName & "_" & oRevNum & ".dxf"   
‘ NOT QUITE SURE WHAT ReadAllText IS DOING????? DOES IT MAKE  A      ‘ CONTINUAL STRING OF ALL THE TEXT IN THE DXF FILE CHOSEN???
    Dim readText As String = System.IO.File.ReadAllText(sFname)
‘ CREATE A STRING OF THE TEXT IN THE DXF FILE BETWEEN THE ENTITIES AND ENDSEC WORDS IN THE DXF FILE    
    Dim re As New System.Text.RegularExpressions.Regex("(?<=ENTITIES((?!ENDSEC).)*)ENDSEC", System.Text.RegularExpressions.RegexOptions.Singleline)
“ NOT SURE WHAT IS GOING ON HERE?
    Dim i As Integer = 0
    For Each match In re.Matches(readText)        
        readText = readText.Insert(match.Index + textLen * i, realTextToAdd)      
        i = i + 1
    Next   
    System.IO.File.WriteAllText(sFname, readText)
0 Likes