Creating DWFs of Pressed Parts

Creating DWFs of Pressed Parts

donaldleigh
Advocate Advocate
194 Views
1 Reply
Message 1 of 2

Creating DWFs of Pressed Parts

donaldleigh
Advocate
Advocate

Evening all

 

I have a rule "Create DXF of Pressing" that when run with a sheet metal part open will create a DWF of the part.

 

I also have another rule "Bend Existing in Sheet Metal" that when run from an assembly will find all parts that are sheet metal with bends.

In the "Bend Existing in Sheet Metal" If a sheet metal part with a bend is found it should run the "Create DXF of Pressing" rule. Currently what is happing is its creating a DWF of the assembly the rule "Bend Existing in Sheet Metal" is run in. But is naming the DWF as per a iproperty of the sheet metal part.

 

Any help would be great.

 

Donald

2022

 

What I would like to do is combine them together, Either as 2 separate rules or 1.

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

A.Acheson
Mentor
Mentor

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
0 Likes