Parts Material Density

Parts Material Density

Cosmin_V
Advocate Advocate
884 Views
14 Replies
Message 1 of 15

Parts Material Density

Cosmin_V
Advocate
Advocate

Hi,

 

I found this code on the forum, but it needs some adjustments. I would like to put all the old Bosch profiles in one assembly, and change their density, but this code only works in part.
Can someone help me ....
I want the code to work in assembly and change the density to "1" on all parts that have:

- Description "Bosch Profile" 
- Material  "-" and  Material "AlMg3"

 

	oPartDoc = ThisDoc.Document
    Dim oMaterial As Material
	If iProperties.Value("Project", "Description") = "Bosch Profil" Then
    oMaterial = oPartDoc.Materials.Item("AlMg3")
	'oMaterial = oPartDoc.Materials.Item("-")
    oMaterial.Density = 1
End If

Many Thanks 

0 Likes
885 Views
14 Replies
Replies (14)
Message 2 of 15

A.Acheson
Mentor
Mentor

Here is a link to working with parts in assemblies. There is a sub routine called “Public Sub ChangeAllPartMaterial” at the bottom that changes the material in parts in the assembly. 

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

This article has been super helpful and I simply saved each type of assembly looping as a snippet to easily work with the assembly depending upon what your looking to process.

 

In addition you will need the access the property sets to find the description you are looking for and here is a link for that 

 

https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

Alternatively you can use the ilogic snippet you are using put the document reference into it like below wrapping it inside a try catch statement to deal with the other files that may be read only. 

 

Try
iProperties
.Value(oPartDoc.DisplayName,"Project", "Description")
Catch
EndTry

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 15

WCrihfield
Mentor
Mentor

Hi @Cosmin_V.  It looks like you want to loop through all levels of your assembly and only process the part documents.  Then within each part document, you want to check the value of its 'Description' iProperty, and if it equals "Bosch Profile" (I added the "e" at the end, I hope that's correct), you want to make sure that part's material is set to one named "AlMg3".  Then when that is taken care of, you next want to set the density to 1.  Does all that sound correct so far?

 

If so...

1)  Is this material named "AlMg3" already accessible to each of those part files (either a local copy, or in their 'active' material library), or will we have to find it in some other material library, then make a local copy of it before we can use it in each part?

 

2)  What units are we talking about when we're setting the Density to 1?  I believe if you just type in a raw number for this in iLogic, it will be understood as the database default units, which I believe is 'grams per cubic centimeter' or 'g/cm^3'.  Is that OK with you, or do you need it in different units.

 

3)  If you want to change the actual material's density in all those different files.  I'm thinking there must be a better way, like changing it in one place, then the 'Mass Properties' of all other documents that are referencing that material will be updated to the new values once their document's have been updated/rebuilt (gives them a chance to recalculate).  These days the 'material' is an 'Asset' object, and any local edits to them in a document can be saved back to the material library where they were originally referenced from, as long as that material library isn't 'ReadOnly'.  I believe this can still all be done by code, but it can get complicated.  (By the way, the iProperty for Density is ReadOnly, and is in database units anyways.)

 

Here is one attempt at it you can play with though:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
	Dim oPDef As PartComponentDefinition = oOcc.Definition
	Dim oPDoc As PartDocument = oPDef.Document
	If oPDoc.PropertySets(3).Item("Description").Value = "Bosh Profile" Then
		If oPDoc.ActiveMaterial.DisplayName = "AlMg3" Then Continue For
		'Find/Get the 'MaterialAsset' named "AlMg3"
		Dim oMatl As MaterialAsset
		Try
			oMatl = oPDoc.MaterialAssets.Item("AlMg3")
		Catch
			oMatl = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("AlMg3")
		Catch
			MsgBox("Couldn't find a 'MaterialAsset' named 'AlMg3'.", vbInformation, "iLogic")
			Continue For
		End Try
		If IsNothing(oMatl) Then Continue For
		oPhysAsset = oMatl.PhysicalPropertiesAsset
		Dim oFloatVal As FloatAssetValue = oPhysAsset.Item("structural_Density")
		oFloatVal.Value = 1
	End If
	oPDoc.Update2(True)
	oPDoc.Save2(False)
Next
oADoc.Update2(True)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 15

Cosmin_V
Advocate
Advocate

Thanks @WCrihfield 

 

Yes, that's what I want,

I try your code, it is run without an error, but noticing there is no change!

 

I have search all the "Bosch Profile" parts in the archive and place them together in one assembly. Some of the oldest have the material "AlMg3", and the newest ones have the material "-"

-my density it is in g/cm^3

0 Likes
Message 5 of 15

WCrihfield
Mentor
Mentor

It seems like I might have left an important step out and maybe could have done a couple things differently, so try this version.

Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
	Dim oPDef As PartComponentDefinition = oOcc.Definition
	Dim oPDoc As PartDocument = oPDef.Document
	If oPDoc.PropertySets(3).Item("Description").Value = "Bosh Profile" Then
		
		'Find/Get the 'MaterialAsset' named "AlMg3"
		Dim oMatl As MaterialAsset = GetMaterialAsset(oPDoc, "AlMg3")
		If IsNothing(oMatl) Then
			MsgBox("Couldn't find a 'MaterialAsset' named " & oMaterialName & "." & vbCrLf & _
			"Skipping to next Part in assembly.", vbInformation, "iLogic")
			Continue For
		End If
		
		'set it as the 'active' material
		If Not oPDoc.ActiveMaterial Is oMatl Then
			oPDoc.ActiveMaterial = oMatl
		End If
		
		'run our Sub below to set Material Density
		SetMaterialDensity(oMatl, 1)
	End If
	If oPDoc.Dirty Then
		oPDoc.Update2(True)
		oPDoc.Save2(False)
	End If
Next
oADoc.Update2(True)
End Sub

Function GetMaterialAsset(oPart As PartDocument, oMaterialName As String) As MaterialAsset
	'Find/Get the 'MaterialAsset' named "AlMg3"
	Dim oMat As MaterialAsset
	Try
		oMat = oPart.MaterialAssets.Item("AlMg3")
	Catch
		oMat = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("AlMg3")
	Catch
		For Each oALib As AssetLibrary In ThisApplication.AssetLibraries
			For Each oMA As MaterialAsset In oALib.MaterialAssets
				If oMA.Name = oMaterialName Or _
					oMA.DisplayName = oMaterialName Then
					oMat = oMA
					Exit For
				End If
			Next
			If Not IsNothing(oMat) Then Exit For
		Next
	End Try
	Return oMat
End Function

Sub SetMaterialDensity(oMaterialAsset As MaterialAsset, oNewDensity As Double)
	'get the Physical Properties of this Material Asset
	oPhysAsset = oMaterialAsset.PhysicalPropertiesAsset
	'get the AssetValue within this Asset that is for Density
	Dim oFloatVal As FloatAssetValue = oPhysAsset.Item("structural_Density")
	oFloatVal.Value = oNewDensity
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 15

Cosmin_V
Advocate
Advocate

Hi @WCrihfield 

I have run the rule in one assembly where I place some of the Bosch Profile, I  adjust a little the rule and it works (the problem it was the material "AIMg3")

Now when I run the rule in the project where I want to change the density it has an error...

It look like, one type of profile it f... everything...and it is not different than the others...what can cause the error?

I attached here the assembly may be you can help!?

The part which it cause the problem it is: 00304356

 

And this is the code:

 

NyD = InputBox("Enter new density:  (g/cm³)"& vbLf &"If decimal are needed use (Comma, not Point)!!!", "Density")
If NyD="" Then Exit Sub 'empty string in input field OR CANCEL BUTTON PRESSED


If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
	Dim oPDef As PartComponentDefinition = oOcc.Definition
	Dim oPDoc As PartDocument = oPDef.Document
	
	If Left(oPDoc.PropertySets(3).Item("Description").Value,5) = "Bosch" Then
		If oPDoc.ActiveMaterial.DisplayName = "" Then Continue For
		'Find/Get the 'MaterialAsset' named "AlMg3"
		Dim oMatl As MaterialAsset
		
		Try
		oMatl = oPDoc.MaterialAssets.Item("-")
		Catch
		oMatl = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("-")
		Catch
		MsgBox("Couldn't find a 'MaterialAsset' named '-'.", vbInformation, "iLogic")
		Continue For
		End Try
		If IsNothing(oMatl) Then Continue For
		oPhysAsset = oMatl.PhysicalPropertiesAsset
		Dim oFloatVal1 As FloatAssetValue = oPhysAsset.Item("structural_Density")

		Try
			oMatl = oPDoc.MaterialAssets.Item("AlMg3")
			Catch
			oMatl = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("AlMg3")
			Catch
			MsgBox("Couldn't find a 'MaterialAsset' named 'AlMg3'.", vbInformation, "iLogic")
			Continue For
			End Try
			If IsNothing(oMatl) Then Continue For
			oPhysAsset = oMatl.PhysicalPropertiesAsset
			Dim oFloatVal2 As FloatAssetValue = oPhysAsset.Item("structural_Density")
		
		oFloatVal1.Value = NyD*1000
		oFloatVal2.Value = oFloatVal1.Value
		Dens=oFloatVal1.Value
	End If
	oPDoc.Update2(True)
	oPDoc.Save2(False)
Next
oADoc.Update2(True)


MessageBox.Show("The new density is " & Dens/1000 & " g/cm³", "Density")

 

Many Thanks!!!

 

0 Likes
Message 7 of 15

WCrihfield
Mentor
Mentor

The file you posted will open eventually, after skipping all searches for referenced documents, but it doesn't include any of the parts, so all references are broken.  My initial guess, without seeing any of the data in the error messages, is that there is a data type conversion issue.  At the very beginning of your code, you are using an InputBox to store data to the "NyD" variable.  The return value from the InputBox function is a String.  Then later, near the bottom of your code you are multiplying this "NyD" variable by 1000 to set the value of the FloatAssetValue.  First of all, you can't multiply a String value by a numerical value.  You would have to convert the "NyD" variable to Double data type either at that point or before that point.  Then the FloadAssetValue.Value is a Double type data, so the data you set as its value must be a Double, not a String.  This may be easily fixable though.

Try replacing this line:

oFloatVal1.Value = NyD*1000

with this:

oFloatVal1.Value = CDbl(NyD)*1000

That line incorporates a direct data Type conversion function to convert the 'NyD' String type variable to a Double data Type, then continues with the math, to set the value of the AssetValue.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 15

Cosmin_V
Advocate
Advocate

HI

Thanks @WCrihfield for your answer, It give me the same error 😞

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.AssetsEnumerator.get_Item(Object Index)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 9 of 15

WCrihfield
Mentor
Mentor

That error message seems to indicate that it is encoutering an error when attempting to get the named Asset from either the document's MaterialAssets (an AssetsEnumerator), or from the ActiveMaterialLibrary (also an AssetsEnumerator). I'm not sure why these are still stopping the rule with an error though, when these calls are within Try...Catch blocks. I'm starting to think that, for the process of getting those two named materials, we should avoid using those Try...Catch blocks, in favor of using a series of traditional loops with If...Then checks instead.  I'm going to change things up a bit this time.  If this still fails, I'm likely going to give up on this project because it doesn't seem like the proper way to do this task anyways.  It seems to me like you could simply edit the source material definition in the material library one time, then just update the local document materials in those other documents so they match the version found in the material library, then update & re-save them.

Here is my latest attempt at  an iLogic rule for the earlier task:

NyD = InputBox("Enter new density:  (g/cm³)"& vbLf &"If decimal are needed use (Comma, not Point)!!!", "Density")
If NyD = "" Then Exit Sub 'empty string in input field OR CANCEL BUTTON PRESSED
Dim oNewDensity As Double = CDbl(NyD) * 1000
Dim oMat1Name As String = "-"
Dim oMat2Name As String = "AlMg3"

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

'try to find the Library versions of these two materials before the main loop
oLibMats = ThisApplication.ActiveMaterialLibrary.MaterialAssets
Dim oLibMat1, oLibMat2 As MaterialAsset
If oLibMats.Count > 0 Then
	For Each oAsset As Asset In oLibMats
		If oAsset.AssetType = AssetTypeEnum.kAssetTypeMaterial Then
			If oAsset.DisplayName = oMat1Name Then
				oLibMat1 = oAsset
			ElseIf oAsset.DisplayName = oMat2Name Then
				oLibMat2 = oAsset
			End If
		End If
	Next
End If
If IsNothing(oLibMat1) Then
	MsgBox("Could not find MaterialAsset named " & oMat1Name & " in ActiveMaterialLibrary.", vbInformation, "iLogic")
End If
If IsNothing(oLibMat2) Then
	MsgBox("Could not find MaterialAsset named " & oMat2Name & " in ActiveMaterialLibrary.", vbInformation, "iLogic")
End If

oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	If oOcc.DefinitionDocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
	Dim oPDoc As PartDocument = oOcc.Definition.Document
	If Not Left(oPDoc.PropertySets(3).Item("Description").Value, 5) = "Bosch" Then Continue For
	If oPDoc.ActiveMaterial.DisplayName = "" Then Continue For
	
	'Find/Get the 'MaterialAsset' objects were looking for
	Dim oDocMat1, oDocMat2 As MaterialAsset
	'searches within document materials, not library materials
	If oPDoc.MaterialAssets.Count > 0 Then
		For Each oAsset As Asset In oPDoc.MaterialAssets
			If oAsset.AssetType = AssetTypeEnum.kAssetTypeMaterial Then
				If IsNothing(oDocMat1) Then
					If oAsset.DisplayName = oMat1Name Then
						oDocMat1 = oAsset
					End If
				End If
				If IsNothing(oDocMat2) Then
					If oAsset.DisplayName = oMat2Name Then
						oDocMat2 = oAsset
					End If
				End If
			End If
			'if both variables have had their values set, then exit the loop
			If (Not IsNothing(oDocMat1)) And (Not IsNothing(oDocMat2)) Then Exit For
		Next
	End If
	
	'if those materials were not found in the document, but were found in the library,
	'then we need to create a local copy of the material within the document to use,
	'otherwise we may not be able to edit its density
	If (Not IsNothing(oLibMat1)) And (IsNothing(oDocMat1)) Then
		oDocMat1 = oLibMat1.CopyTo(oPDoc)
	End If
	If (Not IsNothing(oLibMat2)) And (IsNothing(oDocMat2)) Then
		oDocMat2 = oLibMat2.CopyTo(oPDoc)
	End If

	'now check again if they have been found or not
	If IsNothing(oDocMat1) And IsNothing(oDocMat2) Then
		MsgBox("Neither material was found.  Skipping to next component.", vbCritical, "iLogic")
		Continue For 'nothing left to do in this document, so skip to next
	ElseIf IsNothing(oDocMat1) Then
		MsgBox("The material named " & oMat1Name & " was not found.  Exiting rule.", vbCritical, "iLogic")
	ElseIf IsNothing(oDocMat2) Then
		MsgBox("The material named " & oMat2Name & " was not found.  Exiting rule.", vbCritical, "iLogic")
	End If
	
	Dim oPhysAsset1, oPhysAsset2 As Asset
	Dim oFloatVal1, oFloatVal2 As FloatAssetValue
	If Not IsNothing(oDocMat1) Then
		oPhysAsset1 = oDocMat1.PhysicalPropertiesAsset
		oFloatVal1 = oPhysAsset1.Item("structural_Density")
		oFloatVal1.Value = oNewDensity
	End If
	If Not IsNothing(oDocMat2) Then
		oPhysAsset2 = oDocMat2.PhysicalPropertiesAsset
		oFloatVal2 = oPhysAsset2.Item("structural_Density")
		oFloatVal2.Value = oNewDensity
	End If

	oPDoc.Update2(True)
	oPDoc.Save2(False)
Next
oADoc.Update2(True)

MessageBox.Show("The new density is " & oNewDensity/1000 & " g/cm³", "Density")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 15

Cosmin_V
Advocate
Advocate

Hi

 

I have find a way to change it ....

I change first for all "Bosch Profile" the material in to "-"

and after for all "Bosch Profile" with material "-" the density to the new one.

But this only works in my "Test assembly". If I run the rule in the Projects where I need to change the density it dont work
I get this error...

 

Error in rule: Rule0, in document: 00284073.iam

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartComponentDefinition'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DA33F1A3-7C3F-11D3-B794-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartComponentDefinition'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DA33F1A3-7C3F-11D3-B794-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

This is the rule I run

Sub Main()

  Dim oAssyDoc As AssemblyDocument
   oAssyDoc = ThisApplication.ActiveDocument

  Dim oAssyCompDef As AssemblyComponentDefinition
   oAssyCompDef = oAssyDoc.ComponentDefinition

  Dim oOcc As ComponentOccurrence
  Dim oPartCompDef As PartComponentDefinition

  For Each oOcc In oAssyCompDef.Occurrences 
    Dim oPartDoc As PartDocument

	Dim oPDef As PartComponentDefinition = oOcc.Definition
	Dim oPDoc As PartDocument = oPDef.Document
	If Left(oPDoc.PropertySets(3).Item("Description").Value, 13) = "Bosch Profile" Then


    If Not oOcc.Definition.Type = kWeldsComponentDefinitionObject Then
         oPartDoc = oOcc.Definition.Document
         oPartCompDef = oPartDoc.ComponentDefinition
        oPartCompDef.Material = oPartDoc.Materials.item("-")
    End If
End If
  Next

  oAssyDoc.Update
End Sub
0 Likes
Message 11 of 15

WCrihfield
Mentor
Mentor

I think I may know what is causing the error messages you posted in your last message.  I believe that right inside your loop of the components, you are assuming (without checking first) that all components are going to be regular parts.  Then you are setting oOcc.Definition as the value of a PartComponentDefinition type variable.  If the object returned by oOcc.Definition was not a PartComponentDefinition object, it will cause this error.  That's why I usually have a line of code to check its type before setting this variable's value.  I see that you are checking the type of the oOcc.Definition later after that line, to see if it is a WeldsComponentDefinition, but that's after this point.  You also seem to be creating two different PartDocument variables and setting a value to both nearly the same way within that loop.  I don't understand your logic there because it seems like they would both be the same document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 15

Cosmin_V
Advocate
Advocate

Thanks @WCrihfield  again for your time!

 

There is no logic ... ‌‌😁 I just find a code on the forum and with yours, I trying to do something. But honestly, I don't quite understand what I'm doing.
Sometimes I succeed sometimes not ... maybe you can help me make it work! 😊

0 Likes
Message 13 of 15

A.Acheson
Mentor
Mentor

Can you open the file and modify manually? If the file is read only you will get the error message. I would first check can you do the change manually and progress from there. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 15

Cosmin_V
Advocate
Advocate

Yes, I can!
In my "test assembly" it works even if it's read only!

But to do it manually on all parts of all projects, I need a few months ... there are almost 10,000 pieces in total

0 Likes
Message 15 of 15

Cosmin_V
Advocate
Advocate

 

I have fix the problem with the material...‌‌ But now if I run the rule to change the density, it work, but just before it is finish the inventor it crush...and som part din not get the new density

This is the code I use...

 

NyD = InputBox("Enter new density:  (g/cm³)"& vbLf &"If decimal are needed use (Comma, not Point)!!!", "Density")
If NyD="" Then Exit Sub 'empty string in input field OR CANCEL BUTTON PRESSED


If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oOccs = oADoc.ComponentDefinition.Occurrences
For Each oOcc As ComponentOccurrence In oOccs.AllLeafOccurrences
	If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
	Dim oPDef As PartComponentDefinition = oOcc.Definition
	Dim oPDoc As PartDocument = oPDef.Document
	
	If Left(oPDoc.PropertySets(3).Item("Description").Value,5) = "Bosch" Then
		If oPDoc.ActiveMaterial.DisplayName = "" Then Continue For
		'Find/Get the 'MaterialAsset' named "-"
		Dim oMatl As MaterialAsset
		
		Try
		oMatl = oPDoc.MaterialAssets.Item("-")
		Catch
		oMatl = ThisApplication.ActiveMaterialLibrary.MaterialAssets.Item("-")
		Catch
		MsgBox("Couldn't find a 'MaterialAsset' named '-'.", vbInformation, "iLogic")
		Continue For
		End Try
		If IsNothing(oMatl) Then Continue For
		oPhysAsset = oMatl.PhysicalPropertiesAsset
		Dim oFloatVal1 As FloatAssetValue = oPhysAsset.Item("structural_Density")
		
		oFloatVal1.Value = NyD*1000
		Dens=oFloatVal1.Value
	End If
	oPDoc.Update2(True)
	oPDoc.Save2(False)
Next
oADoc.Update2(True)

MessageBox.Show("The new density is " & Dens/1000 & " g/cm³", "Density")

 

What can be wrong?

Many Thanks

 

 

 

0 Likes