minimal distance in file name

minimal distance in file name

michielXWZ7U
Enthusiast Enthusiast
286 Views
1 Reply
Message 1 of 2

minimal distance in file name

michielXWZ7U
Enthusiast
Enthusiast

Hi guys, i am using this wonderfull code to export my file to a .dxf. my files are generated in the format 'material'-Thickness (measured for the default sheet metal style)'-1x-'part name'

 

 

'check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
        MessageBox.Show("This Rule " & iLogicVb.RuleName & " only works on Assembly Files.", "WRONG DOCUMENT TYPE",MessageBoxButtons.OK,MessageBoxIcon.Error)
        Return
End If

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'get user input
RUsure = MessageBox.Show ( _
"" _
& vbLf & "Zorg ervoor dat je bestand is opgeslagen." _
& vbLf & " " _
& vbLf & "zorg ervoor dat je materiaal is toegevoegd?" _
& vbLf & "even geduld a.u.b.", "iLogic - Export Sheet Metal ",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
oFolderDXF = oPath & "\" & "DXF Files" & "\" & oAsmName
oFolderSTEP = oPath & "\" & "STEP Files" & "\" & oAsmName

'- - - - - - - - - - - - -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
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDrawDoc.ComponentDefinition
        
If oCompDef.Bends.Count = 0 Then

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolderDXF) Then
System.IO.Directory.CreateDirectory(oFolderDXF)
End If

'Set the DXF target file name
oThickness = oRefDoc.ComponentDefinition.thickness.expression
oMaterial = oRefDoc.ComponentDefinition.material.name
oDataMedium.FileName = oFolderDXF & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & ".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=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_UP;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_TOOL_CENTER_UP;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_UP;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" 
oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oCompDef.FlatPattern.ExitEdit

End If
Catch
End Try 

Try
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDrawDoc.ComponentDefinition
If oCompDef.Bends.Count > 0 Then

'Check for the STEP folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolderSTEP) Then
System.IO.Directory.CreateDirectory(oFolderSTEP)
End If

'Set the step target file name
oDataMedium.FileName = oFolderSTEP & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & ".stp"

oDrawDoc.SaveAs(oFolderSTEP & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & (".stp") , True)
End If
Catch
End Try
oDrawDoc.Close
End If


Next

 

 

 Now i have this wonderful code to measure the minimal distance of a part

 

 

Dim Thickness As Double  = MinOfMany(Measure.ExtentsLength, Measure.ExtentsWidth, Measure.ExtentsHeight)

 

 

I would like to adjust the first code so that the .dxf files are saved in the format 'material' - 'thickness (measured in the format of the second formula' - 1x - part name

 

With kind regards,

 

Michiel

 

 

0 Likes
287 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

does this work for you:

'check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
        MessageBox.Show("This Rule " & iLogicVb.RuleName & " only works on Assembly Files.", "WRONG DOCUMENT TYPE",MessageBoxButtons.OK,MessageBoxIcon.Error)
        Return
End If

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'get user input
RUsure = MessageBox.Show ( _
"" _
& vbLf & "Zorg ervoor dat je bestand is opgeslagen." _
& vbLf & " " _
& vbLf & "zorg ervoor dat je materiaal is toegevoegd?" _
& vbLf & "even geduld a.u.b.", "iLogic - Export Sheet Metal ",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
oFolderDXF = oPath & "\" & "DXF Files" & "\" & oAsmName
oFolderSTEP = oPath & "\" & "STEP Files" & "\" & oAsmName

'- - - - - - - - - - - - -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
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDrawDoc.ComponentDefinition
        
If oCompDef.Bends.Count = 0 Then

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolderDXF) Then
System.IO.Directory.CreateDirectory(oFolderDXF)
End If

'Set the DXF target file name
oThickness = MinOfMany(Measure.ExtentsLength, Measure.ExtentsWidth, Measure.ExtentsHeight)
oMaterial = oRefDoc.ComponentDefinition.material.name
oDataMedium.FileName = oFolderDXF & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & ".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=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_UP;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_TOOL_CENTER_UP;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_UP;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" 
oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oCompDef.FlatPattern.ExitEdit

End If
Catch
End Try 

Try
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDrawDoc.ComponentDefinition
If oCompDef.Bends.Count > 0 Then

'Check for the STEP folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolderSTEP) Then
System.IO.Directory.CreateDirectory(oFolderSTEP)
End If

'Set the step target file name
oDataMedium.FileName = oFolderSTEP & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & ".stp"

oDrawDoc.SaveAs(oFolderSTEP & "\" & oMaterial & " - " & oThickness & " - 1 stuk - " & oFileName & (".stp") , True)
End If
Catch
End Try
oDrawDoc.Close
End If


Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes