Here is an attempt. Room for improvement on formatting and duplications. Note the document reference on ilogic iproperty snippet. You could also replace this with propertyset reference.
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
For Each docFile In oDoc.AllReferencedDocuments
If docFile.IsModifiable = True Then 'Modifiable Part
If docFile.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Sheet Metal part
Dim sm As SheetMetalComponentDefinition
sm = docFile.ComponentDefinition
If sm.Bends.Count > 0 Then 'Bend Exist
Dim docName As String
docName = System.IO.Path.GetFileNameWithoutExtension(docFile.FullFileName)
FileName = System.IO.Path.GetFileName(docFile.FullFileName)
oFolder = ThisDoc.WorkspacePath() & "\_Pressing DWFs"
FolderAndFileName = oFolder & iProperties.Value(FileName,"Custom", "DXF Number") & ".dwf"
docFile.Document.SaveAs(FolderAndFileName, True)
'MessageBox.Show("Find Pressing" & docName, "Title")
CreateDxf(docFile.Document,FileName)
Else If sm.Bends.Count = 0 Then 'No Bend Exist
End If
End If
End If
Next
MessageBox.Show("DWF Of Pressing Created", "Title")
End Sub
Sub CreateDxf(oDocument,FileName)
Dim ThisApp = ThisApplication'.ActiveDocument
Dim TransObj As TransientObjects = ThisApp.TransientObjects
DWFAddIn = ThisApp.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = TransObj.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = TransObj.CreateNameValueMap
oDataMedium = TransObj.CreateDataMedium
If DWFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Launch_Viewer") = launchviewer
oOptions.Value("Publish_All_Component_Props") = 1
oOptions.Value("Publish_All_Physical_Props") = 1
oOptions.Value("Password") = 0
End If
'get DWG target folder path
oFolder = ThisDoc.WorkspacePath() & "\_Pressing DWFs\"
'Check for the _DWG folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
FolderAndFileName = oFolder & iProperties.Value(FileName,"Custom", "DXF Number") & ".dwf"
'MessageBox.Show("Create Pressing" & FolderAndFileName, "Title")
oDataMedium.FileName = FolderAndFileName
'Publish document.
Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
Here is an attempt. Note reference to reference FileName in iproperty. If iproperty has no additional target object it is the iproperty of the document the rule is running in. Use Sub routines to easily combine the code sections. There is room for improvement removing duplicate references but maybe you want to keep rule seperate.
Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
For Each docFile In oDoc.AllReferencedDocuments
If docFile.IsModifiable = True Then 'Modifiable Part
If docFile.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'Sheet Metal part
Dim sm As SheetMetalComponentDefinition
sm = docFile.ComponentDefinition
If sm.Bends.Count > 0 Then 'Bend Exist
Dim docName As String
docName = System.IO.Path.GetFileNameWithoutExtension(docFile.FullFileName)
FileName = System.IO.Path.GetFileName(docFile.FullFileName)
oFolder = ThisDoc.WorkspacePath() & "\_Pressing DWFs"
FolderAndFileName = oFolder & iProperties.Value(FileName,"Custom", "DXF Number") & ".dwf"
docFile.Document.SaveAs(FolderAndFileName, True)
'MessageBox.Show("Find Pressing" & docName, "Title")
CreateDxf(docFile.Document,FileName)
Else If sm.Bends.Count = 0 Then 'No Bend Exist
End If
End If
End If
Next
MessageBox.Show("DWF Of Pressing Created", "Title")
End Sub
Sub CreateDxf(oDocument,FileName)
Dim ThisApp = ThisApplication'.ActiveDocument
Dim TransObj As TransientObjects = ThisApp.TransientObjects
DWFAddIn = ThisApp.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = TransObj.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = TransObj.CreateNameValueMap
oDataMedium = TransObj.CreateDataMedium
If DWFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Launch_Viewer") = launchviewer
oOptions.Value("Publish_All_Component_Props") = 1
oOptions.Value("Publish_All_Physical_Props") = 1
oOptions.Value("Password") = 0
End If
'get DWG target folder path
oFolder = ThisDoc.WorkspacePath() & "\_Pressing DWFs\"
'Check for the _DWG folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
FolderAndFileName = oFolder & iProperties.Value(FileName,"Custom", "DXF Number") & ".dwf"
'MessageBox.Show("Create Pressing" & FolderAndFileName, "Title")
oDataMedium.FileName = FolderAndFileName
'Publish document.
Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan