I have an iLogic code to export flat pattern dxf of all the sheet metal parts in an assembly to a specific folder in my local drive.

I have an iLogic code to export flat pattern dxf of all the sheet metal parts in an assembly to a specific folder in my local drive.

jatinBRF9Q
Participant Participant
293 Views
1 Reply
Message 1 of 2

I have an iLogic code to export flat pattern dxf of all the sheet metal parts in an assembly to a specific folder in my local drive.

jatinBRF9Q
Participant
Participant

I have got a code from this forum, which I modified a little bit to direct the export in a folder present in my local drive. There is something I could not figure out is, naming the exported file. The following code exports the file named as: Filename_rev(revision number of the assembly); instead I want to the part number's revision number in the file name. I know it's too basic for some of you but I am fairly new to VBA as I am a mechanical engineer by profession. If somebody could also add an iLogic expression to open drawing of the sheet metal components and export the pdf with the same naming conventions that that would be wonderful.

 

Here is the code:

'define the active document as an assembly file
Dim oInvApp As Inventor.Application = ThisApplication
'make sure that the active document is an assembly file
If oInvApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("The following logic would only work for an assembly including sheet metals.", "iLogic")
Exit Sub
End If
 
 
Dim RuleName1 As String
EXTERNALrule = "Export all Flats"
 
Dim RuleName2 As String
INTERNALrule = "Rule0"
 
Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oRevNum = iProperties.Value("Project", "Revision Number")
oPath = ThisDoc.Path
 
'Getting User input
RUsure = MessageBox.Show ( _
"This will create a DXF files for all the components of the assembly made of sheet metal." _
& vbLf & "This rule assumes that the part file will be saved." _
& vbLf & "Only sheet metal parts for which the specification structure is set to the normal value will be exported" _
& vbLf & " " _
& vbLf & "This iLogic will take some time while processing the command.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
 
'- - - - - - - - - - - - -Component - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
'process the drawing files for the referenced models
'at the same time, it is expected that the model has been saved
For Each oRefDoc As Document In oRefDocs
'check if the document is a sheet metal part
If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
'check if the normal structure of the specification is set
If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
'make sure that the model is saved
If Not System.IO.File.Exists(oRefDoc.FullFileName) Then Continue For
Dim oPDoc As PartDocument = oInvApp.Documents.Open(oRefDoc.FullFileName, True)
Dim oSheetDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim ThicknessSM As Inventor.Parameter = oSheetDef.Thickness
Dim Thickness As String=ThicknessSM.Value *10 & "mm" 
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName)- 3)
On Error Resume Next
oStyle = oSheetDef.ActiveSheetMetalStyle.Name
Dim oTO As TransientObjects = oInvApp.TransientObjects
oDataMedium = oTO.CreateDataMedium
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
 
'get the path to the target folder DXF
oFolder = "C" & ":\" & "!!!_dxf"
If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder)
oDataMedium.FileName = oFolder & "\" & oFileName & oRevNum & ".dxf"
' oDataMedium.FileName = oFolder & "\" & oFileName & "  " & "-" & Thickness & "- " & activepart.ActiveMaterial.Name & ".dxf"
 
If oSheetDef.HasFlatPattern = False Then
oSheetDef.Unfold
Else
oSheetDef.FlatPattern.Edit
End If
Dim sOut As String
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37641&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
sOut = "FLAT PATTERN DXF?AcadVersion=2018&MergeOuterContour=True&MergeProfilesIntoPolyline=True&RebaseGeometry=True&Feature" _
           + "&FeatureProfilesLayer=IV_FEATURE_PROFILES&FeatureProfilesLayerColor=0;255;255&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerColor=0;255;255" _
   + "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
oSheetDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oSheetDef.FlatPattern.ExitEdit
oPDoc.Close()
Next 
 
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
0 Likes
Accepted solutions (1)
294 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor
Accepted solution

Hi @jatinBRF9Q 

You can pick up the revision number of the reference document using the below lines and here is a helpful article in where this is sourced from. 

Dim partRevNo As String = oRefDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value

 For opening the drawing you will need to construct the fullfilename of the drawing then open and use a pdf export. Have a look at String replace or change extension function.

 

For pdf export you will find multiple post on this forum to do this from the drawing.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan