- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
We make and design machinery and use subcontractors to do the laser and/or bending of our designs. I'm looking for a quicker way to prepare the files to send to our subcontractors (step files for laser + bending and dxf files for laser and engraving).
We have a system in which we use the iproperties as follows:
Vendor: if value = "L" then the file needs to be lasered only, if value= "LP" then the file needs to be lasered and bent
If an assembly is ready, I would like to press a button so all the files that need to be sent to the subcontractor are being saved as an step or dxf file in a folder. They are saved by their name in the iProperty 'description'.
To do this I have created a rule. The part to save the ipt as a step file works, however the dxf's don't get created.
I have put in tracers via debugview and the code stops after "Tracer05". It is caught by the try
Here is the code:
Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
'Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)
trace.Writeline("Debug started ExtRule_DXF_STP_ExportLaser")
MsgBox("Beta versie" + vbLf + "CEP 12/9/2017" +vbLf + "Opgepast ! DXF export nog niet in orde voor L stukken !")
Dim oDescription As String
Dim oVendor As String
Dim Teller As Integer
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
'Check if oDoc is an ipt file..
If oDoc.DocumentType= kPartDocumentObject Then
Dim oPartDoc As PartDocument
oPartDoc = oDoc
Dim model As String = oPartDoc.DisplayName
model = model & ".ipt"
Try
oDescription = iProperties.Value(model,"Project", "Description")
oVendor = iProperties.Value(model, "Project", "Vendor")
teller = teller + 1
'Path dir and create if needed
Dim sPath As String
sPath = "C:\Temp\ExportLaser"
If Not System.IO.Directory.Exists(sPath) Then
System.IO.Directory.CreateDirectory(sPath)
End If
Dim sFileName As String
Dim bStepFile As Boolean = False
'If first letter of iprop Vendor = "L" then continue
If Left(oVendor,1) = "L" Then
trace.WriteLine("Laserstuk gedetecteerd !")
'If oVendor = "LP", file needs to be lasered and bent by subcontractor => create stepfile
If Left(oVendor,2) = "LP" Then
trace.WriteLine("LPlooistuk gedetecteerd !")
'doe export naar STP
sFileName = oDescription.ToString()+".stp"
oPartDoc.SaveAs(sPath+"\"+sFileName, True)
trace.WriteLine("Result SaveAs:" + sFileName + " " + teller.ToString())
bStepFile = True
End If
'If oVendor = "L", file needs only be lasered and engraved => create unfold and save this as DXF file
If bStepFile = False Then
sFileName = oDescription.ToString()+".dxf"
'oPartDoc = ThisApplication.ActiveDocument
Trace.WriteLine(sFileName)
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
'oCompDef = oDoc.ComponentDefinition
Trace.WriteLine("Tracer05")
If oCompDef.HasFlatPattern = False Then
Trace.WriteLine("Creëer ontvouwing..")
oCompDef.Unfold
Else
Trace.WriteLine("Ontvouwing bestaat al...")
oCompDef.FlatPattern.Edit
Trace.Writeline("Tracer07")
End If
Trace.Writeline("Tracer10")
Dim sOut As String
'RGB Geel= 255;255;0
'RGB Rood= 255;0;0
sOut = "FLAT PATTERN DXF?AcadVersion=2013&OuterProfileLayerColor=255;0;0&InteriorProfilesLayerColor=255;0;0&BendUpLayerColor=255;255;0&BendDownLayerColor=255;255;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN"
oCompDef.DataIO.WriteDataToFile( sOut, sFilename)
trace.Writeline("DXF opgeslagen als: " & sFilename ,"DXF Saved")
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit
trace.WriteLine("Result SaveAs:" + sFileName + " " + teller.ToString())
End If
End If
Catch
trace.WriteLine("Error bij Try: " + model.ToString() )
End Try
End If
Next
MsgBox("Export geëindigd.")
End Sub Can anyone help me with the code ?
Thanks in advance !
Greetings
Cedric
Solved! Go to Solution.