Hi i want that my rules generate the name off the parts automatically
heres my post my problem is at line 30
Solved! Go to Solution.
Solved by sebastien_forman. Go to Solution.
Hello @hugo7,
How would the name be formated ? We can have any name you can think of.
Also, please copy paste the code here so we can implement it for you.
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"oDoc = ThisDoc.Document 'check if the part is a sheet metal part If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then oDoc = ThisApplication.ActiveDocument Dim oCompDef As SheetMetalComponentDefinition oCompDef = oDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If Dim sOut As String Dim oPath As String oPath = ThisDoc.Path & "\DXF Flat & Step" If Not System.IO.Directory.Exists(oPath) Then System.IO.Directory.CreateDirectory(oPath) End If Dim sFname As String sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;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;IV_BEND;IV_BEND_DOWN" sFname = oPath & "test"& ".dxf" oCompDef.DataIO.WriteDataToFile(sOut, sFname) 'MessageBox.Show("Your file was saved in the following dirctory: " + sFname) Else 'MessageBox.Show("Only sheet metal parts can be exported as DXF. Nice Try! :-)") End If
hello, try that
oDoc = ThisDoc.Document
' Check if the part is a sheet metal part
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Check if the part has a flat pattern
If Not oCompDef.HasFlatPattern Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If
Dim oPath As String
oPath = ThisDoc.Path & "\DXF Flat & Step"
' Check if the output directory exists, if not, create it
If Not System.IO.Directory.Exists(oPath) Then
System.IO.Directory.CreateDirectory(oPath)
End If
Dim sFname As String
sFname = oPath & "\"&ThisDoc.FileName &"_flat.dxf" ' Correctly formatted DXF file path
' Define parameters for DXF export
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;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;IV_BEND;IV_BEND_DOWN"
' Export the sheet metal part as a DXF file
oCompDef.DataIO.WriteDataToFile(sOut, sFname)
Else
' Display a message if the part is not a sheet metal part
MessageBox.Show("Only sheet metal parts can be exported as DXF.")
End If
Thank that works fine
now can you make this rule to save at the same doc ?
i need to generate a dxf and a .step or combine the 2 rules if its possible ?
' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oOptions.Value("ApplicationProtocolType") = 3 ' Other options... 'oOptions.Value("Author") = "" 'oOptions.Value("Authorization") = "" 'oOptions.Value("Description") = "" 'oOptions.Value("Organization") = "" oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium oData = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = ThisDoc.PathAndFileName(False) & ".stp" oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData) End If
try that 😉
Sub main()
' Get the active document
oDoc = ThisDoc.Document
' Check if the part is a sheet metal part
If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
' Set the active document as the current document
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition
' Check if the part has a flat pattern
If Not oCompDef.HasFlatPattern Then
oCompDef.Unfold
Else
oCompDef.FlatPattern.Edit
End If
' Define the output directory path
Dim oPath As String
oPath = ThisDoc.Path & "\DXF Flat & Step"
' Check if the output directory exists, if not, create it
If Not System.IO.Directory.Exists(oPath) Then
System.IO.Directory.CreateDirectory(oPath)
End If
' Define the DXF file name and path
Dim sFname As String
sFname = oPath & "\"&ThisDoc.FileName &"_flat.dxf" ' Correctly formatted DXF file path
' Define parameters for DXF export
Dim sOut As String
sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0;0;0;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;IV_BEND;IV_BEND_DOWN"
' Export the sheet metal part as a DXF file
oCompDef.DataIO.WriteDataToFile(sOut, sFname)
' Export STEP
ExportStep(oPath, ThisDoc.FileName)
Else
' Display a message if the part is not a sheet metal part
MessageBox.Show("Only sheet metal parts can be exported as DXF.")
End If
End Sub
Function ExportStep(ByVal oPath As String, ByVal fileName As String)
' Get the STEP translator Add-In
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Set the STEP file folder
oFolder = oPath
' Check for the STEP folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
' Check if the translator has save copy options
If oSTEPTranslator.HasSaveCopyAsOptions(ThisDoc.Document, oContext, oOptions) Then
' Set application protocol
oOptions.Value("ApplicationProtocolType") = 3 ' 3 = AP 214 - Automotive Design
' Set the context type
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a data medium
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
' Set the STEP file name and path
oData.FileName = oFolder & "\" & fileName & "-flat.stp"
' Save the part as a STEP file
oSTEPTranslator.SaveCopyAs(ThisDoc.Document, oContext, oOptions, oData)
End If
End Function
Can't find what you're looking for? Ask the community or share your knowledge.