Load a Configuration Depending Upon the Material



Your Ad Here

Some customers have requested that a particular configuration be used for each type of stock material.  So we provide an example below that shows how to load a particular configuration whenever the stock material is changed.  When the material is changed, the macro looks for a matching configuration file.  These files must be created by the user for each material.  The files are loaded from the FeatureCAM directory structure, typically "C:\Program Files\FeatureCAM\Configurations".

Option Explicit

Private Sub LoadConfigForMaterial( Doc As FeatureCAM.FMDocument, new_material As String)
	Dim configs As FMConfigurations
	Dim new_config As FMConfiguration
	Dim doc_config As FMConfiguration
	Dim file As String
	Dim path As String

	Set configs = Application.Configurations
	Set doc_config = configs.Item( Doc.Name)
	Set new_config = configs.Item( new_material)

	If( Not new_config Is Nothing) Then
		doc_config.CopyConfiguration ( new_config)
	Else
		path = Application.InstallPath
		file = path + "\Configurations\" + new_material + ".cdb"
		configs.Import ( file)
		Set new_config = configs.Item( new_material)
		If( new_config Is Nothing) Then
			MsgBox "Unable to load material configuration from " + file
		Else
			doc_config.CopyConfiguration ( new_config)
			new_config.Delete
		End If
	End If
End Sub
Private Sub Application_DocumentNew(Doc As FeatureCAM.FMDocument)
	Dim material As String
	Dim stock As FMStock

	Set stock = Doc.Stock
	material = stock.Material
	LoadConfigForMaterial Doc, material

End Sub

Private Sub Application_StockMaterialChanged(Doc As FeatureCAM.FMDocument, ByVal old_material As String, ByVal new_material As String)
	LoadConfigForMaterial Doc, new_material
End Sub

 

Return to FeatureCAM Index


Your Ad Here