- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How can write rule for Sheet metal assembly export dxf with file name Part Number_sheet thickness_quantity
Hi
I want rule of Sheet metal assembly export dxf with Blue Bend line but, File name is part Number_Thickness_Quantity.
İt is possible by rule
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi,
You can try the next rule. I did have some problem with getting the qty. but the rest should work.
Sub main() Dim doc As AssemblyDocument = ThisDoc.Document For Each oDoc As Document In doc.AllReferencedDocuments If (oDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For Dim fileName As String = getFileName(oDoc) Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold() Else oCompDef.FlatPattern.Edit() End If Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&BendUpLayerColor=0;0;255&BendDownLayerColor=0;0;255&InvisibleLayers=IV_TANGENT" oCompDef.DataIO.WriteDataToFile(sOut, fileName) oCompDef.FlatPattern.ExitEdit() Next End Sub Private Function getFileName(oDoc As PartDocument) As String Dim fileNameDoc = System.IO.Path.GetFileName(oDoc.FullFileName) Dim partNumber = iProperties.Value(fileNameDoc, "Project", "Part Number") Dim thickness As Double = Parameter("flatpattern.ipt", "Thickness") thickness = Math.Round(thickness * 10) Dim newFileName As String = String.Format("{0}_{1}",partNumber, thickness) Return IO.Path.Combine("c:\temp\", newFileName) End Function
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Firtstly Thanks for your repply.
I tried the your code, but it wasnt work.
"Parameter: The document named "flatpattern.ipt" was not found." it show error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I guessit was to later yesterday. there i found the bug and fixed it. Check the code below. An other thing that i forgot to mention. i multiply the thickness by 10. I did that because its better if you dont use points in file names. For example if your part would be 1.5mm thick you would get a file name like "PartNumber_1.5.dxf". this code will translate that to "PartNumber_15.dxf"
Sub main() Dim doc As AssemblyDocument = ThisDoc.Document For Each oDoc As Document In doc.AllReferencedDocuments If (oDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For Dim fileName As String = getFileName(oDoc) Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold() Else oCompDef.FlatPattern.Edit() End If Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&BendUpLayerColor=0;0;255&BendDownLayerColor=0;0;255&InvisibleLayers=IV_TANGENT" oCompDef.DataIO.WriteDataToFile(sOut, fileName) oCompDef.FlatPattern.ExitEdit() Next End Sub Private Function getFileName(oDoc As PartDocument) As String Dim fileNameDoc = System.IO.Path.GetFileName(oDoc.FullFileName) Dim partNumber = iProperties.Value(fileNameDoc, "Project", "Part Number") Dim thickness As Double = Parameter(fileNameDoc, "Thickness") thickness = Math.Round(thickness * 10) Dim newFileName As String = String.Format("{0}_{1}",partNumber, thickness) Return IO.Path.Combine("c:\temp\", newFileName) End Function
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for your attentions. @JelteDeJong
The your rule give:
Error in rule: dxf, in document: 0001-0.iam
c (Exception from HRESULT: 0x80004005 (E_FAIL))
More İnfo
System.Runtime.InteropServices.COMException (0x80004005): System.Runtime.InteropServices.COMException (0x80004005): Belirtilmemiş hata (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.FlatPattern.Edit()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule) (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.FlatPattern.Edit()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That message doesn't say much. So that does not help. but i added a try/catch block. this will show the file that is creating the problem. maybe it helps. try this rule.
Sub main() Dim doc As AssemblyDocument = ThisDoc.Document For Each oDoc As Document In doc.AllReferencedDocuments If (oDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For Try Dim fileName As String = getFileName(oDoc) Dim oCompDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold() Else oCompDef.FlatPattern.Edit() End If Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&BendUpLayerColor=0;0;255&BendDownLayerColor=0;0;255&InvisibleLayers=IV_TANGENT" oCompDef.DataIO.WriteDataToFile(sOut, fileName) oCompDef.FlatPattern.ExitEdit() Catch ex As Exception MsgBox("Exception was thrown while exporting file: " & oDoc.FullDocumentName ) End Try Next End Sub Private Function getFileName(oDoc As PartDocument) As String Dim fileNameDoc = System.IO.Path.GetFileName(oDoc.FullFileName) Dim partNumber = iProperties.Value(fileNameDoc, "Project", "Part Number") Dim thickness As Double = Parameter(fileNameDoc, "Thickness") thickness = Math.Round(thickness * 10) Dim newFileName As String = String.Format("{0}_{1}",partNumber, thickness) Return IO.Path.Combine("c:\temp\", newFileName) End Function
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.
Blog: hjalte.nl - github.com