Material Updating Incorrectly

Material Updating Incorrectly

gbaker7NQNF
Participant Participant
188 Views
1 Reply
Message 1 of 2

Material Updating Incorrectly

gbaker7NQNF
Participant
Participant
j = List.Count
'j = 18

For i = 2 To j+1
	
	sNewName = GoExcel.CellValue("B" & i)
	doc.SaveAs(oooFolder & GoExcel.CellValue("A" & i) & " " & sNewName & ".ipt", True)
	xDoc = ThisApplication.Documents.Open(oooFolder & GoExcel.CellValue("A" & i) & " " & sNewName & ".ipt")
	
	If GoExcel.CellValue("C" & i) = "ABS" Then
			iProperties.Material = "ABS Plastic"
		
	Else If GoExcel.CellValue("C" & i) = "Acrylic" Then
			iProperties.Material = "Polycarbonate, Clear"
		
	End If
	
	InventorVb.DocumentUpdate(True)

	Dim oPars As UserParameters = xDoc.ComponentDefinition.Parameters.UserParameters
	oPars.Item("width").Expression = "isolate(" & GoExcel.CellValue("G" & i) & ";in;in)"
	oPars.Item("height").Expression = "isolate(" & GoExcel.CellValue("F" & i) & ";in;in)"
	oPars.Item("thk").Expression = "isolate(" & GoExcel.CellValue("E" & i) & ";in;in)"
		
	xDoc.Save
	xDoc.Close(True)

	For k = 1 To GoExcel.CellValue("I" & i)
	oAssyDoc.ComponentDefinition.Occurrences.Add(oooFolder & GoExcel.CellValue("A" & i) & " " & sNewName & ".ipt", oPos)
	Next k
	
Next i 

 I have this block of code which is used to generate parts based on a spreadsheet. One of my columns is a list of different materials. The pink section of my code is meant to read this column and update the material accordingly. My issue is: the first instance of a new material is set incorrectly, matching the previous material. The following instances are correct.

 

Here's an example:

The column for material reads as follows:

1. ABS

2. ABS

3. ABS

4. ABS

5. Acrylic

6. Acrylic

7. Acrylic

8. ABS

9. ABS
10. ABS 

 

When the parts are created, part 1 will default to Polycarbonate (which the template file is set to initially), part 5 will be set to ABS, part 8 will be Polycarbonate, and the rest are correct.

 

If anyone knows what's going on please let me know!  Any help would be greatly appreciated!

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

A.Acheson
Mentor
Mentor

Hi @gbaker7NQNF 

Because your using an ilogic snippet and the document is continuing to change you might be getting incorrect document targeting. 

You can change the document material via API using the below code and research the syntax via API help. 

Syntax

AssetName

Asset.Name() As String

PartDocument ActiveMaterial

PartDocument.ActiveMaterial() As Asset

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

    Dim assetLib As AssetLibrary  = ThisApplication.AssetLibraries.Item("Inventor Material Library")
 	
	ThisApplication.ActiveMaterialLibrary = assetLib
   
    Dim MaterialName As String = "Gold"
   
    Try
	Dim localMaterial As MaterialAsset = oDoc.MaterialAssets.Item(MaterialName)
 	Catch
    Dim libMaterial As MaterialAsset = assetLib.MaterialAssets.Item(MaterialName)
	libMaterial.CopyTo(oDoc)
	End Try
	
	oDoc.ActiveMaterial = oDoc.MaterialAssets.Item(MaterialName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan